@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
1,404 lines (1,403 loc) • 47.9 kB
JavaScript
var ge = Object.defineProperty;
var ve = (t, e, n) => e in t ? ge(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
var S = (t, e, n) => ve(t, typeof e != "symbol" ? e + "" : e, n);
import { ref as B, computed as U, defineComponent as Z, createVNode as T, inject as W, onMounted as be } from "vue";
import { cloneDeep as G, isPlainObject as J } from "lodash-es";
import { UseTemplateDragAndDropRules as ye, useDragulaCommonRule as he, DgControl as j, useDesignerComponent as Ce } from "../designer-canvas/index.esm.js";
import { FormBindingType as Q } from "../property-panel/index.esm.js";
import { useDesignerRules as X } from "../dynamic-form/index.esm.js";
function H(t, e) {
let n;
function r(s) {
const { properties: m, title: h, ignore: l } = s, d = l && Array.isArray(l), v = Object.keys(m).reduce((f, y) => ((!d || !l.find((M) => M === y)) && (f[y] = m[y].type === "object" && m[y].properties ? r(m[y]) : G(m[y].default)), f), {});
if (h && (!d || !l.find((f) => f === "id"))) {
const f = h.toLowerCase().replace(/-/g, "_");
v.id = `${f}_${Math.random().toString().slice(2, 6)}`;
}
return v;
}
function o(s) {
const { properties: m, title: h, required: l } = s;
if (l && Array.isArray(l)) {
const d = l.reduce((v, f) => (v[f] = m[f].type === "object" && m[f].properties ? r(m[f]) : G(m[f].default), v), {});
if (h && l.find((v) => v === "id")) {
const v = h.toLowerCase().replace(/-/g, "_");
d.id = `${v}_${Math.random().toString().slice(2, 6)}`;
}
return d;
}
return {
type: h
};
}
function a(s, m = {}, h) {
const l = t[s];
if (l) {
let d = o(l);
const v = e[s];
return d = v ? v({ getSchemaByType: a }, d, m, h) : d, n != null && n.appendIdentifyForNewControl && n.appendIdentifyForNewControl(d), d;
}
return null;
}
function i(s, m) {
const h = r(m);
return Object.keys(h).reduce((l, d) => (Object.prototype.hasOwnProperty.call(s, d) && (l[d] && J(l[d]) && J(s[d] || !s[d]) ? Object.assign(l[d], s[d] || {}) : l[d] = s[d]), l), h), h;
}
function g(s, m) {
return Object.keys(s).filter((l) => s[l] != null).reduce((l, d) => {
if (m.has(d)) {
const v = m.get(d);
if (typeof v == "string")
l[v] = s[d];
else {
const f = v(d, s[d], s);
Object.assign(l, f);
}
} else
l[d] = s[d];
return l;
}, {});
}
function c(s, m, h = /* @__PURE__ */ new Map()) {
const l = i(s, m);
return g(l, h);
}
function u(s) {
var h;
const m = s.type;
if (m) {
const l = t[m];
if (!l)
return s;
const d = i(s, l), v = ((h = s.editor) == null ? void 0 : h.type) || "";
if (v) {
const f = t[v], y = i(s.editor, f);
d.editor = y;
}
return d;
}
return s;
}
function p(s) {
n = s;
}
return { getSchemaByType: a, resolveSchemaWithDefaultValue: u, resolveSchemaToProps: c, mappingSchemaToProps: g, setDesignerContext: p };
}
const K = {}, ee = {}, { getSchemaByType: wt, resolveSchemaWithDefaultValue: we, resolveSchemaToProps: Me, mappingSchemaToProps: xe, setDesignerContext: Mt } = H(K, ee);
function Ee(t = {}) {
function e(u, p, s, m) {
if (typeof s == "number")
return m[u].length === s;
if (typeof s == "object") {
const h = Object.keys(s)[0], l = s[h];
if (h === "not")
return Number(m[u].length) !== Number(l);
if (h === "moreThan")
return Number(m[u].length) >= Number(l);
if (h === "lessThan")
return Number(m[u].length) <= Number(l);
}
return !1;
}
function n(u, p, s, m) {
return m[u] && m[u].propertyValue && String(m[u].propertyValue.value) === String(s);
}
const r = /* @__PURE__ */ new Map([
["length", e],
["getProperty", n]
]);
Object.keys(t).reduce((u, p) => (u.set(p, t[p]), u), r);
function o(u, p) {
const s = u;
return typeof p == "number" ? [{ target: s, operator: "length", param: null, value: Number(p) }] : typeof p == "boolean" ? [{ target: s, operator: "getProperty", param: u, value: !!p }] : typeof p == "object" ? Object.keys(p).map((m) => {
if (m === "length")
return { target: s, operator: "length", param: null, value: p[m] };
const h = m, l = p[m];
return { target: s, operator: "getProperty", param: h, value: l };
}) : [];
}
function a(u) {
return Object.keys(u).reduce((s, m) => {
const h = o(m, u[m]);
return s.push(...h), s;
}, []);
}
function i(u, p) {
if (r.has(u.operator)) {
const s = r.get(u.operator);
return s && s(u.target, u.param, u.value, p) || !1;
}
return !1;
}
function g(u, p) {
return a(u).reduce((h, l) => h && i(l, p), !0);
}
function c(u, p) {
const s = Object.keys(u), m = s.includes("allOf"), h = s.includes("anyOf"), l = m || h, f = (l ? u[l ? m ? "allOf" : "anyOf" : "allOf"] : [u]).map((M) => g(M, p));
return m ? !f.includes(!1) : f.includes(!0);
}
return { parseValueSchema: c };
}
const Fe = {
convertTo: (t, e, n, r) => {
t.appearance || (t.appearance = {}), t.appearance[e] = n;
},
convertFrom: (t, e, n) => t.appearance ? t.appearance[e] : t[e]
}, Se = {
convertFrom: (t, e, n) => t.buttons && t.buttons.length ? `共 ${t.buttons.length} 项` : "无"
}, Ie = {
convertTo: (t, e, n, r) => {
t.editor && (t.editor[e] = n);
},
convertFrom: (t, e, n) => t.editor && Object.prototype.hasOwnProperty.call(t.editor, e) ? t.editor[e] : t[e]
}, z = {
button: { type: "button", name: "按钮" },
"response-toolbar": { type: "response-toolbar", name: "工具栏" },
"response-toolbar-item": { type: "response-toolbar-item", name: "按钮" },
"content-container": { type: "content-container", name: "容器" },
"input-group": { type: "input-group", name: "文本" },
textarea: { type: "textarea", name: "多行文本" },
lookup: { type: "lookup", name: "帮助" },
"number-spinner": { type: "number-spinner", name: "数值" },
"date-picker": { type: "date-picker", name: "日期" },
switch: { type: "switch", name: "开关" },
"radio-group": { type: "radio-group", name: "单选组" },
"check-box": { type: "check-box", name: "复选框" },
"check-group": { type: "check-group", name: "复选框组" },
"combo-list": { type: "combo-list", name: "下拉列表" },
"response-form": { type: "response-form", name: "卡片面板" },
"response-layout": { type: "response-layout", name: "布局容器", icon: "response-layout-3" },
"response-layout-item": { type: "response-layout-item", name: "布局", icon: "response-layout-1" },
"tree-grid": { type: "tree-grid", name: "树表格" },
"tree-grid-column": { type: "tree-grid-column", name: "树表格列" },
"data-grid": { type: "data-grid", name: "表格" },
"data-grid-column": { type: "data-grid-column", name: "表格列" },
module: { type: "Module", name: "模块" },
component: { type: "component", name: "组件" },
tabs: { type: "tabs", name: "标签页" },
"tab-page": { type: "tab-page", name: "标签页项", dependentParentControl: "Tab" },
"tab-toolbar-item": { type: "tab-toolbar-item", name: "标签页工具栏按钮" },
"html-template": { type: "html-template", name: "模板容器" },
"time-picker": { type: "time-picker", name: "时间选择" },
section: { type: "section", name: "分组面板" },
"section-toolbar": { type: "section-toolbar", name: "分组面板工具栏" },
"section-toolbar-item": { type: "section-toolbar-item", name: "分组面板按钮" },
splitter: { type: "splitter", name: "分栏面板" },
"splitter-pane": { type: "splitter-pane", name: "分栏面板项", dependentParentControl: "Splitter" },
"component-ref": { type: "component-ref", name: "组件引用节点" },
uploader: { type: "uploader", name: "附件上传" },
"page-header": { type: "page-header", name: "页头" },
"page-footer": { type: "page-footer", name: "页脚" },
"tab-toolbar": { type: "tab-toolbar", name: "标签页工具栏" },
fieldset: { type: "fieldset", name: "分组" },
"query-solution": { type: "query-solution", name: "筛选方案" },
drawer: { type: "drawer", name: "抽屉" },
"external-container": { type: "external-container", name: "外部容器", icon: "content-container" },
"list-nav": { type: "list-nav", name: "列表导航" },
"list-view": { type: "list-view", name: "列表" },
"filter-bar": { type: "filter-bar", name: "筛选条" },
"language-textbox": { type: "language-textbox", name: "多语输入框" }
}, Te = {
convertFrom: (t, e, n) => {
var o;
const r = t.editor && t.editor[e] ? t.editor[e] : t[e];
return ((o = z[r]) == null ? void 0 : o.name) || r;
}
}, Pe = {
convertTo: (t, e, n, r) => {
t[e] = t[e];
},
convertFrom: (t, e, n) => t.editor ? n.getRealEditorType(t.editor.type) : ""
}, Ve = {
convertTo: (t, e, n, r) => {
(t.type === "data-grid-column" || t.type === "tree-grid-column") && (t.formatter ? t.formatter[e] = n : t.formatter = {
[e]: n
});
},
convertFrom: (t, e, n) => {
if (t.formatter) {
if (e === "trueText")
return t.formatter.trueText;
if (e === "falseText")
return t.formatter.falseText;
if (e === "prefix")
return t.formatter.prefix;
if (e === "suffix")
return t.formatter.suffix;
if (e === "precision")
return t.formatter.precision;
if (e === "decimal")
return t.formatter.decimal;
if (e === "thousand")
return t.formatter.thousand;
if (e === "tempDateFormat")
return t.formatter.dateFormat === "yyyy年MM月dd日" ? "yearMonthDay" : t.formatter.dateFormat === "yyyy-MM-dd HH:mm:ss" ? "yyyy-MM-ddTHH:mm:ss" : t.formatter.dateFormat === "yyyy/MM/dd HH:mm:ss" ? "yyyy/MM/ddTHH:mm:ss" : t.formatter.dateFormat === "yyyy年MM月dd日 HH时mm分ss秒" ? "yearMonthDayHourMinuteSecond" : t.formatter.tempDateFormat || t.formatter.dateFormat || "yyyy-MM-dd";
if (e === "customFormat")
return t.formatter.customFormat;
if (e === "type")
return t.formatter.type || "none";
}
return "none";
}
}, ke = {
convertTo: (t, e, n, r) => {
t.command ? t.command[e] = n : t.command = {
[e]: n
}, e === "enable" && n && (t.command.commands || (t.command.commands = [
{
text: "编辑",
type: "primary",
command: "edit"
},
{
text: "删除",
type: "danger",
command: "remove"
}
]));
},
convertFrom: (t, e, n) => t.command && e === "enable" ? t.command.enable : ""
}, Ne = {
convertTo: (t, e, n, r) => {
t.column ? t.column[e] = n : t.column = {
[e]: n
}, e === "fitColumns" && n && (t.column.fitMode || (t.column.fitMode = "average"));
},
convertFrom: (t, e, n) => {
if (t.column) {
if (e === "fitColumns")
return t.column.fitColumns;
if (e === "fitMode")
return t.column.fitMode;
}
return "";
}
}, Oe = {
convertTo: (t, e, n, r) => {
t.summary ? t.summary[e] = n : t.summary = {
[e]: n
}, e === "enable" && n && (t.summary ? t.summary.groupFields || (t.summary.groupFields = []) : t.summary = {
enable: n,
groupFields: []
});
},
convertFrom: (t, e, n) => t.summary && e === "enable" ? t.summary.enable : t.type === "data-grid-column" ? t.enableSummary === void 0 ? !1 : t.enableSummary : ""
}, Re = {
convertTo: (t, e, n, r) => {
t.group ? t.group[e] = n : t.group = {
[e]: n
}, e === "enable" && n && (t.group ? t.group.groupFields || (t.group.groupFields = []) : t.group = {
enable: n,
groupFields: [],
showSummary: !1
});
},
convertFrom: (t, e, n) => {
if (t.group) {
if (e === "enable")
return t.group.enable;
if (e === "showSummary")
return t.group.showSummary;
}
}
}, Be = {
convertFrom: (t, e) => t.binding ? t.binding.path : "",
convertTo: (t, e, n) => {
if (n && n.length > 0) {
const r = n[0];
t.binding || (t.binding = {}), t.binding.type = "Form", t.binding.path = r.bindingField, t.binding.field = r.id, t.binding.fullPath = r.path, t.path = r.bindingPath;
}
}
}, De = {
convertTo: (t, e, n, r) => {
t.pagination || (t.pagination = {}), t.pagination[e] = n;
},
convertFrom: (t, e, n) => t.pagination ? t.pagination[e] : t[e]
}, Ue = {
convertTo: (t, e, n, r) => {
t.rowNumber || (t.rowNumber = {}), t.rowNumber[e] = n;
},
convertFrom: (t, e, n) => t.rowNumber ? t.rowNumber[e] : t[e]
}, $e = {
convertTo: (t, e, n, r) => {
t.selection || (t.selection = {}), t.selection[e] = n;
},
convertFrom: (t, e, n) => t.selection ? t.selection[e] : t[e]
}, Ae = {
convertFrom: (t, e, n) => t[e] && t[e].length ? `共 ${t[e].length} 项` : ""
}, je = {
convertFrom: (t, e) => t[e] || "",
convertTo: (t, e, n) => {
t[e] = n;
}
}, qe = {
convertTo: (t, e, n, r) => {
t.size || (t.size = {}), t.size[e] = n;
},
convertFrom: (t, e, n) => t.size ? t.size[e] : t[e]
}, Ge = {
convertFrom: (t, e, n) => {
var r, o;
return (r = t.formatter) != null && r.data && e === "formatterEnumData" && !t.formatterEnumData ? (o = t.formatter) == null ? void 0 : o.data : t.formatterEnumData;
}
}, ze = {
convertTo: (t, e, n, r) => {
t.sort || (t.sort = {}), t.sort[e] = n;
},
convertFrom: (t, e, n) => {
var r, o;
if (e === "mode")
return ((r = t.sort) == null ? void 0 : r.mode) || "client";
if (e === "multiSort")
return !!((o = t.sort) != null && o.multiSort);
}
}, Le = {
convertTo: (t, e, n, r) => {
t.filter || (t.filter = {}), t.filter[e] = n;
},
convertFrom: (t, e, n) => {
var r;
if (e === "mode")
return ((r = t.filter) == null ? void 0 : r.mode) || "client";
}
}, _e = {
convertTo: (t, e, n, r) => {
t.rowOption ? t.rowOption[e] = n : t.rowOption = {
[e]: n
};
},
convertFrom: (t, e, n) => {
if (t.rowOption) {
if (e === "customRowStyle")
return t.rowOption.customRowStyle;
if (e === "customCellStyle")
return t.rowOption.customCellStyle;
}
return "";
}
};
function te(t, e, n) {
const r = /* @__PURE__ */ new Map([
["/converter/appearance.converter", Fe],
["/converter/buttons.converter", Se],
["/converter/property-editor.converter", Ie],
["/converter/items-count.converter", Ae],
["/converter/type.converter", Te],
["/converter/change-editor.converter", Pe],
["/converter/change-formatter.converter", Ve],
["/converter/column-command.converter", ke],
["/converter/column-option.converter", Ne],
["/converter/summary.converter", Oe],
["/converter/group.converter", Re],
["/converter/form-group-label.converter", je],
["/converter/field-selector.converter", Be],
["/converter/pagination.converter", De],
["/converter/row-number.converter", Ue],
["/converter/grid-selection.converter", $e],
["/converter/size.converter", qe],
["/converter/change-formatter-enum.converter", Ge],
["/converter/grid-sort.converter", ze],
["/converter/grid-filter.converter", Le],
["/converter/row-option.converter", _e]
]), o = /* @__PURE__ */ new Map([
["string", { type: "input-group", enableClear: !1 }],
["boolean", {
type: "combo-list",
textField: "name",
valueField: "value",
idField: "value",
enableClear: !1,
editable: !1,
data: [
{
value: !0,
name: "是"
},
{
value: !1,
name: "否"
}
]
}],
["enum", { type: "combo-list", maxHeight: 128, enableClear: !1, editable: !1 }],
["array", { type: "button-edit" }],
["number", { type: "number-spinner", placeholder: "" }],
["events-editor", { type: "events-editor", hide: !0 }]
]), a = Ee();
function i(l, d) {
return () => a.parseValueSchema(l, d);
}
function g(l, d, v) {
return l.includes("visible") && d.visible !== void 0 ? typeof d.visible == "boolean" ? () => !!d.visible : d.visible === void 0 ? !0 : i(d.visible, v) : () => !0;
}
function c(l, d, v) {
return l.includes("readonly") && d.readonly !== void 0 ? typeof d.readonly == "boolean" ? () => !!d.readonly : i(d.readonly, v) : () => !1;
}
function u(l, d) {
const v = l.$converter || d;
return typeof v == "string" && v && r.has(v) ? r.get(v) || null : v || null;
}
function p(l, d, v, f, y, M = "", w = "") {
return Object.keys(l).map((C) => {
const E = B(1), F = C, b = l[C], I = Object.keys(b), R = b.title, V = b.type, k = o.get(V) || { type: "input-group", enableClear: !1 }, P = b.editor ? Object.assign({}, k, b.editor) : Object.assign({}, k), D = g(I, b, d), $ = c(I, b, d);
P.readonly = P.readonly === void 0 ? $() : P.readonly;
const A = b.type === "cascade" ? p(b.properties, d, v, f, y, M, w) : [], le = !0;
let N = u(b, w);
const ce = U({
get() {
if (E.value) {
if (["class", "style"].find((me) => me === F) && !N && (N = r.get("/converter/appearance.converter") || null), N && N.convertFrom)
return N.convertFrom(v, C, y, M);
const O = v[C];
return Object.prototype.hasOwnProperty.call(b, "defaultValue") && (O === void 0 || typeof O == "string" && O === "") ? b.type === "boolean" ? b.defaultValue : b.defaultValue || "" : O;
}
return null;
},
set(O) {
E.value += 1, N && N.convertTo ? (N.convertTo(f, C, O, y, M), N.convertTo(v, C, O, y, M)) : (f[C] = O, v[C] = O);
}
}), { refreshPanelAfterChanged: ue, description: de, isExpand: fe, parentPropertyID: pe } = b, _ = { propertyID: F, propertyName: R, propertyType: V, propertyValue: ce, editor: P, visible: D, readonly: $, cascadeConfig: A, hideCascadeTitle: le, refreshPanelAfterChanged: ue, description: de, isExpand: fe, parentPropertyID: pe };
return d[F] = _, _;
});
}
function s(l, d, v = {}) {
const f = {}, y = t[l];
return y && y.categories ? Object.keys(y.categories).map((w) => {
const x = y.categories[w], C = x == null ? void 0 : x.title, E = p(x.properties || {}, f, {}, v, d);
return { categoryId: w, categoryName: C, properties: E };
}) : [];
}
function m(l, d, v, f, y = "") {
const M = d.$ref.schema, w = d.$ref.converter, x = v[M], C = x.type, E = n(x), F = {}, b = t[C];
if (b && b.categories) {
const I = b.categories[l], R = I == null ? void 0 : I.title;
w && Object.keys(I.properties).forEach((P) => {
I.properties[P].$converter = w;
});
const V = (I == null ? void 0 : I.properties) || {}, k = p(V, F, E, x, f, y);
return { categoryId: l, categoryName: R, properties: k };
}
return { categoryId: l, categoryName: "", properties: [] };
}
function h(l, d, v, f, y) {
const M = l.type, w = n(l), x = {};
let C = y || t[M];
if (C && Object.keys(C).length === 0 && v && v.getPropConfig && (C = v.getPropConfig(f)), C && C.categories) {
const E = [];
return Object.keys(C.categories).map((F) => {
const b = C.categories[F];
if (b.$ref) {
E.push(m(F, b, l, d, f));
return;
}
const I = b == null ? void 0 : b.title, R = b == null ? void 0 : b.tabId, V = b == null ? void 0 : b.tabName, k = b == null ? void 0 : b.hide, P = b == null ? void 0 : b.hideTitle, D = p(b.properties || {}, x, w, l, d, f, b.$converter), { setPropertyRelates: $ } = b, A = b == null ? void 0 : b.parentPropertyID;
E.push({ categoryId: F, categoryName: I, tabId: R, tabName: V, hide: k, properties: D, hideTitle: P, setPropertyRelates: $, parentPropertyID: A });
}), E;
}
return [];
}
return {
getPropertyConfigBySchema: h,
getPropertyConfigByType: s,
propertyConverterMap: r
};
}
const ne = {}, re = {};
te(ne, re, we);
const oe = {}, ie = {}, { getSchemaByType: xt, resolveSchemaWithDefaultValue: We, resolveSchemaToProps: Et, mappingSchemaToProps: Ft, setDesignerContext: St } = H(oe, ie), se = {}, ae = {};
te(se, ae, We);
function Je(t, e, n = /* @__PURE__ */ new Map(), r = (i, g, c, u) => g, o = {}, a = (i) => i) {
return K[e.title] = e, ee[e.title] = r, ne[e.title] = o, re[e.title] = a, oe[e.title] = e, ie[e.title] = r, se[e.title] = o, ae[e.title] = a, (i = {}, g = !0) => {
if (!g)
return xe(i, n);
const c = Me(i, e, n), u = Object.keys(t).reduce((p, s) => (p[s] = t[s].default, p), {});
return Object.assign(u, c);
};
}
function Qe(t, e) {
return { customClass: e.class, customStyle: e.style };
}
const Xe = /* @__PURE__ */ new Map([
["appearance", Qe]
]), Ye = "https://json-schema.org/draft/2020-12/schema", Ze = "https://farris-design.gitee.io/fieldset.schema.json", He = "fieldset", Ke = "A Farris Container Component", et = "object", tt = {
id: {
description: "The unique identifier for a fieldset",
type: "string"
},
type: {
description: "The type string of fieldset component",
type: "string",
default: "fieldset"
},
appearance: {
description: "",
type: "object",
properties: {
class: {
type: "string"
},
style: {
type: "string"
}
},
default: {}
},
title: {
description: "The title for a fieldset",
type: "string"
},
contents: {
description: "",
type: "array",
default: []
}
}, nt = [
"id",
"type",
"contents"
], rt = {
$schema: Ye,
$id: Ze,
title: He,
description: Ke,
type: et,
properties: tt,
required: nt
};
function ot(t, e, n) {
return Object.assign(e, {
appearance: {
class: "col-12 px-0"
},
title: "分组标题"
}), e;
}
const L = {
/** 组件自定义样式 */
customClass: { type: String, default: "" },
customStyle: { type: String, default: "" },
/** 标题 */
title: { type: String, default: "" }
}, it = Object.assign({}, L, {
componentId: { type: String, default: "" }
}), Y = Je(L, rt, Xe, ot), q = /* @__PURE__ */ Z({
name: "FFieldset",
props: L,
emits: [],
setup(t, e) {
const n = B(!0);
function r(g, c) {
g && c && c.split(" ").reduce((p, s) => (p[s] = !0, p), g);
}
const o = U(() => {
const g = {
"f-section-formgroup": !0,
"f-state-collapse": !n.value
};
return r(g, t.customClass), g;
}), a = U(() => ({
btn: !0,
"f-btn-mx": !0,
"f-btn-collapse-expand": !0,
"f-state-expand": n.value
}));
function i() {
n.value = !n.value;
}
return () => T("fieldset", {
class: o.value,
style: t.customStyle
}, [T("legend", {
class: "f-section-formgroup-legend"
}, [T("div", {
class: "f-header"
}, [T("div", {
class: "f-title",
onClick: i
}, [t.title]), T("div", {
class: "f-toolbar",
onClick: i
}, [T("button", {
class: a.value
}, null)])])]), T("div", {
class: "f-section-formgroup-inputs"
}, [e.slots.default && e.slots.default()])]);
}
}), st = B(0);
function at() {
st.value++;
}
const lt = B(0);
function ct(t) {
const { formSchemaUtils: e, formStateMachineUtils: n } = t;
function r(c, u = "") {
return {
path: u + c.code,
field: c.id,
fullPath: c.code
};
}
function o(c, u = "") {
return e.getViewModelById(c).states.map((s) => r(s, u));
}
function a(c) {
const u = e.getRootViewModelId(), p = o(c);
if (c === u)
return p;
const s = o(u, "root-component.");
return [...p, ...s];
}
function i(c) {
return c.binding && c.binding.path || c.id || "";
}
function g() {
return n && n.getRenderStates() || [];
}
return { getVariables: a, getControlName: i, getStateMachines: g };
}
class ut {
constructor(e) {
S(this, "sessionVariables", [
{
key: "CurrentSysOrgName",
name: "当前组织Name",
description: "当前组织Name"
},
// {
// key: "CurrentSysOrgCode",
// name: "当前组织Code",
// description: "当前组织Code"
// },
{
key: "CurrentSysOrgId",
name: "当前组织Id",
description: "当前组织Id"
},
{
key: "CurrentUserName",
name: "当前用户Name",
description: "当前用户Name"
},
{
key: "CurrentUserCode",
name: "当前用户Code",
description: "当前用户Code"
},
{
key: "CurrentUserId",
name: "当前用户Id",
description: "当前用户Id"
},
{
key: "CurrentLanguage",
name: "当前语言编号",
description: "当前登录的语言编号,例如简体中文返回'zh-CHS',英文返回'en',繁体中文'zh-CHT'"
}
]);
S(this, "expressionNames", {
compute: "计算表达式",
dependency: "依赖表达式",
validate: "验证表达式",
dataPicking: "帮助前表达式",
visible: "可见表达式",
readonly: "只读表达式",
required: "必填表达式"
});
S(this, "getExpressionConverter", (e, n) => ({
convertFrom: (r, o, a, i) => {
const g = a.getExpressionRuleValue(e, n || o);
return g && g.value || "";
},
convertTo: (r, o, a, i, g) => {
var c;
if (o === "dataPicking" && (a != null && a.target)) {
const u = `${a.target}_dataPicking`;
((c = a.rules) == null ? void 0 : c.some(
(s) => s.id === u && s.value
)) ? r.dictPickingExpressionId = u : delete r.dictPickingExpressionId;
}
i.updateExpression(a);
}
}));
this.formSchemaService = e;
}
getExpressionRule(e, n) {
const r = this.formSchemaService.getExpressions();
if (!r)
return "";
const o = r.find((i) => i.target === e);
if (!o)
return "";
const a = o.rules.find((i) => i.type === n);
return a || "";
}
// 获取上下文表单变量
getContextFormVariables() {
const { module: e } = this.formSchemaService.getFormSchema();
if (!e.viewmodels || e.viewmodels.length === 0)
return [];
const n = this.formSchemaService.getRootViewModelId(), r = this.formSchemaService.getViewModelById(n);
if (!r || !r.states || r.states.length === 0)
return [];
const o = [];
return r.states.forEach((a) => {
o.push({
key: a.code,
name: a.name,
description: a.name,
category: a.category
});
}), o;
}
createTreeNode(e, n, r = "label") {
return {
id: e.id,
name: e.name,
bindingPath: e[r],
parents: n,
type: "field"
};
}
buildEntityFieldsTreeData(e = null, n) {
const r = [];
return e == null || e.forEach((o) => {
var g;
const a = this.createTreeNode(o, n);
let i = [];
(g = o.type) != null && g.fields && (i = this.buildEntityFieldsTreeData(o.type.fields, [...n, o.label])), r.push({
data: a,
children: i,
expanded: !0
});
}), r;
}
buildChildEntityTreeData(e = null, n) {
const r = [];
return e == null || e.forEach((o) => {
var c, u;
const a = this.createTreeNode(o, n);
a.type = "entity";
const i = this.buildEntityFieldsTreeData((c = o.type) == null ? void 0 : c.fields, [...n, o.label]), g = this.buildChildEntityTreeData((u = o.type) == null ? void 0 : u.entities, [...n, o.label]);
g != null && g.length && (i == null || i.push(...g)), r.push({
data: a,
children: i || [],
// 空值回退
expanded: !0
});
}), r;
}
getEntitiesTreeData() {
const e = this.formSchemaService.getSchemaEntities();
if (!(e != null && e.length))
return [];
const n = e[0];
if (!(n != null && n.type))
return [];
const r = this.buildEntityFieldsTreeData(n.type.fields, [n.code]), o = this.buildChildEntityTreeData(n.type.entities, [n.code]);
return o != null && o.length && (r == null || r.push(...o)), {
entityCode: n.code,
fields: [{
data: this.createTreeNode(n, [], "code"),
children: r || []
}]
};
}
getEntitiesAndVariables() {
return {
entities: this.getEntitiesTreeData(),
variables: {
session: {
name: "系统变量",
items: this.sessionVariables,
visible: !1
},
forms: {
name: "表单变量",
items: this.getContextFormVariables(),
visible: !0
}
}
};
}
onBeforeOpenExpression(e, n, r) {
const o = r === "Field" ? e.binding.field : e.id, a = this.getExpressionRule(o, n), i = this.getEntitiesAndVariables(), g = {
message: ["validate", "required", "dataPicking"].includes(n) && a ? a.message : "",
...i
};
return a.messageType != null && (g.messageType = a.messageType), g;
}
buildRule(e, n, r, o) {
const { expression: a, message: i, messageType: g } = n, c = {
id: `${e}_${r}`,
type: r,
value: a
};
return (r === "validate" || r === "dataPicking" || r === "required") && (c.message = i), r === "dataPicking" && (c.messageType = g), r === "validate" && o && (c.elementId = o), c;
}
getExpressionData() {
const { expressions: e } = this.formSchemaService.getFormSchema().module;
return e || [];
}
updateExpression(e, n, r, o) {
const a = n === "Field" ? e.binding.field : e.id, i = this.buildRule(a, r, o, e.type === "form-group" ? e.id : "");
let c = this.getExpressionData().find((p) => p.targetType === n && p.target === a);
const u = (p) => p.value.trim() === "";
if (c) {
const p = c.rules.find((s) => s.id === i.id);
if (p)
u(i) ? c.rules = c.rules.filter((s) => s.id !== i.id) : (Object.assign(p, i), o === "validate" && e.type === "form-group" && (p.elementId = e.id));
else {
if (u(i))
return null;
c.rules = c.rules || [], c.rules.push(i);
}
} else {
if (u(i))
return null;
c = {
target: `${a}`,
rules: [i],
targetType: n
};
}
return c;
}
getExpressionEditorOptions(e, n, r, o) {
return r.reduce((a, i) => {
var c, u;
const g = n === "Field" ? (c = e == null ? void 0 : e.binding) == null ? void 0 : c.field : e.id;
return a[i] = {
hide: n === "Field" ? !!((u = e == null ? void 0 : e.binding) != null && u.field) : !1,
description: "",
title: this.expressionNames[i],
type: "string",
$converter: this.getExpressionConverter(g),
refreshPanelAfterChanged: !0,
editor: {
type: "expression-editor",
singleExpand: !1,
dialogTitle: `${this.expressionNames[i]}编辑器`,
showMessage: i === "validate" || i === "dataPicking" || i === "required",
showMessageType: i === "dataPicking",
beforeOpen: () => this.onBeforeOpenExpression(e, i, n),
onSubmitModal: (p) => {
const s = this.updateExpression(e, n, p, i);
if (o) {
const m = this.buildRule(g, p, i);
o(m);
}
return s;
}
}
}, a;
}, {});
}
getExpressionInfo(e, n, r) {
const o = n === "Field" ? e.binding.field : e.id, a = this.getExpressionRule(o, r), i = {
value: a && a.value,
targetId: o,
targetType: n,
expressionType: r
};
return a && a.message && (i.message = a.message), i;
}
getExpressionConfig(e, n, r = ["compute", "dependency", "validate"], o) {
return {
description: "表达式",
title: "表达式",
hide: !e.binding,
properties: {
...this.getExpressionEditorOptions(e, n, r, o)
}
};
}
getExpressionOptions(e, n, r) {
const o = this.getExpressionInfo(e, n, r);
return {
dialogTitle: `${this.expressionNames[r]}编辑器`,
singleExpand: !1,
showMessage: r === "required",
beforeOpen: () => this.onBeforeOpenExpression(e, r, n),
expressionInfo: o
};
}
}
class dt {
constructor(e, n) {
S(this, "componentId");
S(this, "viewModelId");
S(this, "eventsEditorUtils");
S(this, "formSchemaUtils");
S(this, "formMetadataConverter");
S(this, "designViewModelUtils");
S(this, "designViewModelField");
S(this, "controlCreatorUtils");
S(this, "designerHostService");
S(this, "designerContext");
S(this, "schemaService", null);
S(this, "metadataService", null);
S(this, "propertyConfig", {
type: "object",
categories: {}
});
var r;
this.componentId = e, this.designerHostService = n, this.eventsEditorUtils = n.eventsEditorUtils, this.formSchemaUtils = n.formSchemaUtils, this.formMetadataConverter = n.formMetadataConverter, this.viewModelId = ((r = this.formSchemaUtils) == null ? void 0 : r.getViewModelIdByComponentId(e)) || "", this.designViewModelUtils = n.designViewModelUtils, this.controlCreatorUtils = n.controlCreatorUtils, this.metadataService = n.metadataService, this.schemaService = n.schemaService, this.designerContext = n.designerContext;
}
getFormDesignerInstance() {
var e, n;
return (n = (e = this.designerContext) == null ? void 0 : e.instances) == null ? void 0 : n.formDesigner.value;
}
getTableInfo() {
var e;
return (e = this.schemaService) == null ? void 0 : e.getTableInfoByViewModelId(this.viewModelId);
}
setDesignViewModelField(e) {
var r;
const n = e.binding && e.binding.type === "Form" && e.binding.field;
if (n) {
if (!this.designViewModelField) {
const o = this.designViewModelUtils.getDgViewModel(this.viewModelId);
this.designViewModelField = o.fields.find((a) => a.id === n);
}
e.updateOn = (r = this.designViewModelField) == null ? void 0 : r.updateOn;
}
}
getBasicPropConfig(e) {
return {
description: "Basic Information",
title: "基本信息",
properties: {
id: {
description: "组件标识",
title: "标识",
type: "string",
readonly: !0
},
type: {
description: "组件类型",
title: "控件类型",
type: "select",
editor: {
type: "combo-list",
textField: "name",
valueField: "value",
idField: "value",
editable: !1,
data: [{ value: e.type, name: z[e.type] && z[e.type].name }]
}
}
}
};
}
getAppearanceConfig(e = null, n = {}, r) {
const o = {
title: "外观",
description: "Appearance"
}, a = {
class: {
title: "class样式",
type: "string",
description: "组件的CSS样式",
$converter: "/converter/appearance.converter",
parentPropertyID: "appearance"
},
style: {
title: "style样式",
type: "string",
description: "组件的样式",
$converter: "/converter/appearance.converter",
parentPropertyID: "appearance"
}
};
for (const i in n)
a[i] = Object.assign(a[i] || {}, n[i]);
return {
...o,
properties: { ...a },
setPropertyRelates(i, g) {
if (i) {
switch (i && i.propertyID) {
case "class":
case "style": {
lt.value++;
break;
}
}
r && r(i, e, g);
}
}
};
}
getPropertyEditorParams(e, n = [], r = "visible", o = {}, a = {}) {
const { getVariables: i, getControlName: g, getStateMachines: c } = ct(this.designerHostService), u = this.getRealTargetType(e), p = n && n.length > 0 ? n : ["Const", "Variable", "StateMachine", "Expression"], s = {
type: "property-editor",
propertyTypes: p
};
return p.map((m) => {
switch (m) {
case "Const":
Object.assign(s, {
constType: "enum",
constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }]
}, o);
break;
case "Expression":
s.expressionConfig = this.getExpressionOptions(e, u, r);
break;
case "StateMachine":
s.stateMachines = c();
break;
case "Variable":
Object.assign(s, {
controlName: g(e),
newVariablePrefix: "is",
newVariableType: "Boolean",
variables: i(this.viewModelId),
onBeforeOpenVariables: (h) => {
h.value = i(this.viewModelId);
}
}, a);
break;
}
}), s;
}
getVisibleProperty(e, n = "") {
var a;
let r = ["Const", "Variable", "StateMachine", "Expression"];
return n === "gridFieldEditor" ? r = ["Const", "Expression"] : n === "form-group" && !((a = e.binding) != null && a.field) && (r = ["Const", "Variable", "StateMachine"]), {
visible: {
title: "是否可见",
type: "boolean",
description: "运行时组件是否可见",
editor: this.getPropertyEditorParams(e, r, "visible")
}
};
}
/**
* 获取行为
* @param propertyData
* @param viewModelId
* @returns
*/
getBehaviorConfig(e, n = "", r = {}, o) {
const a = {
title: "行为",
description: ""
}, i = this.getVisibleProperty(e, n);
for (const c in r)
i[c] = Object.assign(i[c] || {}, r[c]);
const g = this;
return {
...a,
properties: { ...i },
setPropertyRelates(c, u) {
if (c) {
switch (c.propertyID) {
case "disabled":
case "readonly":
case "visible":
g.afterMutilEditorChanged(e, c);
break;
}
o && o(c, u);
}
}
};
}
/**
* 当多值编辑器变更时
* @param propertyData
* @param changeObject
*/
afterMutilEditorChanged(e, n) {
this.addNewVariableToViewModel(n, this.viewModelId), this.updateExpressionValue(n), this.clearExpression(n, e);
}
/**
*
* @param propertyId
* @param componentInstance
* @returns
*/
updateElementByParentContainer(e, n) {
const r = n && n.parent && n.parent.schema;
if (!r)
return;
const o = r.contents.findIndex((i) => i.id === e), a = G(r.contents[o]);
r.contents.splice(o, 1), r.contents.splice(o, 0, a), at();
}
/**
* 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到ViewModel中
* @param changeObject
* @param viewModelId
* @returns
*/
addNewVariableToViewModel(e, n) {
const r = e.propertyValue;
if (!(r && typeof r == "object") || !(r.type === "Variable" && r.isNewVariable))
return;
const i = {
id: r.field,
category: "locale",
code: r.fullPath,
name: r.fullPath,
type: r.newVariableType || "String"
};
delete r.newVariableType, delete r.isNewVariable, this.formSchemaUtils.getVariableByCode(i.code) || this.formSchemaUtils.getViewModelById(n).states.push(i);
}
/**
* 更新表达式到expressions节点
* @param changeObject
*/
updateExpressionValue(e) {
const n = e.propertyValue;
if (!((n && n.type) === "Expression" && n.expressionInfo))
return;
const { expressionId: a, expressionInfo: i } = n, { targetId: g, targetType: c, expressionType: u, value: p, message: s } = i, m = this.formSchemaUtils.getModule();
m.expressions = m.expressions || [];
const { expressions: h } = m;
let l = h.find((v) => v.target === g);
l || (l = { target: g, rules: [], targetType: c }, h.push(l));
const d = l.rules.find((v) => v.type === u);
if (d)
d.value = p, d.message = s;
else {
const v = { id: a, type: u, value: p, message: s };
l.rules.push(v);
}
delete n.expressionInfo;
}
/**
* 属性类型切换为非表达式后,清除原表达式
* @param changeObject
* @param propertyData
* @returns
*/
clearExpression(e, n) {
const r = e.propertyValue;
if (r && r.type === "Expression")
return;
const a = e.propertyID, i = this.formSchemaUtils.getExpressions(), g = n.binding ? n.binding.field : n.id, c = i.find((u) => u.target === g);
!c || !c.rules || (c.rules = c.rules.filter((u) => u.type !== a));
}
getExpressionOptions(e, n, r) {
return new ut(this.formSchemaUtils).getExpressionOptions(e, n, r);
}
getRealTargetType(e) {
return ["response-toolbar-item", "tab-toolbar-item", "section-toolbar-item"].indexOf(e.type) > -1 ? "Button" : e.binding && e.binding.field ? "Field" : "Container";
}
createBaseEventProperty(e) {
const n = {};
return n[this.viewModelId] = {
type: "events-editor",
editor: {
initialData: e,
viewSourceHandle: (r) => {
var o;
((o = r.controller) == null ? void 0 : o.label.indexOf(this.formSchemaUtils.getModule().code)) > -1 && this.eventsEditorUtils.jumpToMethod(r);
}
}
}, n;
}
}
class ft extends dt {
constructor(e, n) {
super(e, n);
}
getPropertyConfig(e) {
return this.propertyConfig.categories.basic = this.getBasicPropConfig(e), this.propertyConfig.categories.appearance = this.getAppearanceProperties(e), this.propertyConfig;
}
getAppearanceProperties(e) {
const n = this;
return this.getAppearanceConfig(e, {
title: {
title: "标题",
type: "string",
description: "标题"
}
}, (o, a, i) => {
switch (o && o.propertyID) {
case "title": {
o.needRefreshControlTree = !0, n.changeGroupNameInViewModel(a.id, o.propertyValue);
break;
}
}
});
}
/**
* 修改分组标题后,需要同步viewmodel中字段的分组信息
*/
changeGroupNameInViewModel(e, n) {
var a;
const r = this.designViewModelUtils.getDgViewModel(this.viewModelId);
r && r.changeGroupName(e, n);
const o = this.formSchemaUtils.getViewModelById(this.viewModelId);
(a = o == null ? void 0 : o.fields) != null && a.length && o.fields.forEach((i) => {
i.groupId === e && (i.groupName = n);
});
}
}
function pt(t, e) {
const n = new ye(), { canAccept: r } = n.getTemplateRule(t, e), o = t.schema;
function a() {
return "f-section-formgroup";
}
function i() {
return !0;
}
function g() {
return !0;
}
function c() {
return !1;
}
function u(f) {
const { sourceElement: y } = f, { componentInstance: M } = y, w = e == null ? void 0 : e.formSchemaUtils;
if (!w)
return !0;
const x = w.getComponentById(M.value.belongedComponentId), C = w.getViewModelById(x.viewModel), E = w.getComponentById(t.componentInstance.value.belongedComponentId), F = w.getViewModelById(E.viewModel);
return C != null && C.id && (F != null && F.id) && C.id !== F.id ? C.bindTo === F.bindTo : !0;
}
function p(f) {
const { bindingTargetId: y } = f;
if (!e)
return;
const { formSchemaUtils: M, schemaService: w } = e, x = M.getComponentById(t.componentInstance.value.belongedComponentId), C = w.getFieldByIDAndVMID(y, x.viewModel);
return !!(C != null && C.schemaField);
}
function s(f) {
return f.sourceType === "control" && f.componentCategory === "input" ? !0 : f.sourceType === "move" && f.componentType === "form-group" ? u(f) : f.sourceType === "field" && f.componentCategory === "input" ? p(f) : !1;
}
function m(f) {
return !(!he().basalDragulaRuleForContainer(f, e) || !r || !s(f));
}
function h(f) {
return new ft(f, e).getPropertyConfig(o);
}
function l(f) {
var F, b, I, R, V;
if (!e)
return;
const { formSchemaUtils: y, designViewModelUtils: M } = e, w = f.componentInstance, x = w.value.parent, C = y.getComponentById(w.value.belongedComponentId), E = M.getDgViewModel(C.viewModel);
switch (x && ((F = x.schema) == null ? void 0 : F.type)) {
case j.fieldset.type:
case j["response-form"].type:
case j["response-layout-item"].type: {
const k = { groupId: o.id, groupName: o.title }, P = (I = (b = w.value.schema) == null ? void 0 : b.binding) == null ? void 0 : I.type, D = (V = (R = w.value.schema) == null ? void 0 : R.binding) == null ? void 0 : V.field;
switch (P) {
case Q.Form: {
E.changeField(D, k);
break;
}
case Q.Variable: {
y.modifyViewModelFieldById(C.viewModel, D, k, !0);
break;
}
}
break;
}
}
}
function d(f) {
if (!f || !f.componentInstance || !e)
return;
const y = f.componentInstance, M = y.value.schema;
if (!M.binding || !M.binding.field)
return;
l(f);
const { formSchemaUtils: w } = e, x = w.getViewModelIdByComponentId(y.value.belongedComponentId), C = w.getViewModelIdByComponentId(t.componentInstance.value.belongedComponentId);
x !== C && X(t, e).moveInputBetweenComponent(f);
}
function v(f, y) {
var M, w, x;
if (f.componentCategory === "input") {
const { label: C } = f;
let E;
const F = e == null ? void 0 : e.controlCreatorUtils;
(M = f.bindingSourceContext) != null && M.entityFieldNode ? E = F.setFormFieldProperty((w = f.bindingSourceContext) == null ? void 0 : w.entityFieldNode, y == null ? void 0 : y.type) : (E = F.createFormGroupWithoutField(y == null ? void 0 : y.type), E.label = C);
const b = X(t, e);
return b.resolveFormGroupAppearance(E), b.syncFieldToViewModel(f, (x = E.editor) == null ? void 0 : x.type, o.id, o.title), E;
}
return y;
}
return {
canAccepts: m,
hideNestedPaddingInDesginerView: c,
getPropsConfig: h,
checkCanDeleteComponent: i,
checkCanMoveComponent: g,
onAcceptMovedChildElement: d,
onResolveNewComponentSchema: v,
getDesignerClass: a
};
}
const mt = /* @__PURE__ */ Z({
name: "FFieldsetDesign",
props: it,
emits: [],
setup(t, e) {
const n = B(), r = B(), o = W("design-item-context"), a = W("designer-host-service"), i = pt(o, a), g = Ce(r, o, i);
e.expose(g.value), be(() => {
r.value.componentInstance = g;
});
const c = B(!0);
function u(l, d) {
l && d && d.split(" ").reduce((f, y) => (f[y] = !0, f), l);
}
const p = U(() => {
const l = {
"f-section-formgroup": !0,
"f-state-collapse": !c.value
};
return u(l, t.customClass), l;
}), s = U(() => ({
display: c.value ? "flex" : "none",
"flex-wrap": "wrap"
})), m = U(() => ({
btn: !0,
"f-btn-mx": !0,
"f-btn-collapse-expand": !0,
"f-state-expand": c.value
}));
function h() {
c.value = !c.value;
}
return () => T("fieldset", {
class: p.value,
ref: n
}, [T("legend", {
class: "f-section-formgroup-legend"
}, [T("div", {
class: "f-header"
}, [T("div", {
class: "f-title",
onClick: h
}, [t.title]), T("div", {
class: "f-toolbar",
onClick: h
}, [T("button", {
class: m.value
}, null)])])]), T("div", {
"data-dragref": `${o.schema.id}-container`,
ref: r,
class: "f-section-formgroup-inputs drag-container",
style: s.value
}, [e.slots.default && e.slots.default()])]);
}
}), It = {
install(t) {
t.component(q.name, q);
},
register(t, e, n, r) {
t.fieldset = q, e.fieldset = Y;
},
registerDesigner(t, e, n) {
t.fieldset = mt, e.fieldset = Y;
}
};
export {
q as Fieldset,
It as default,
it as fieldsetDesignerProps,
L as fieldsetProps,
Y as propsResolver
};