@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
1,129 lines (1,128 loc) • 36.6 kB
JavaScript
import { ref as C, computed as N, defineComponent as W, watch as H, inject as ce, onMounted as se, createVNode as E } from "vue";
import de from "../button-edit/index.esm.js";
import { cloneDeep as $, isPlainObject as z, debounce as fe } from "lodash-es";
import me from "../tree-view/index.esm.js";
import { FInputGroup as pe } from "../input-group/index.esm.js";
import { withInstall as ve } from "../common/index.esm.js";
function _(e, t) {
let n;
function c(r) {
const { properties: o, title: u, ignore: a } = r, i = a && Array.isArray(a), l = Object.keys(o).reduce((d, v) => ((!i || !a.find((x) => x === v)) && (d[v] = o[v].type === "object" && o[v].properties ? c(o[v]) : $(o[v].default)), d), {});
if (u && (!i || !a.find((d) => d === "id"))) {
const d = u.toLowerCase().replace(/-/g, "_");
l.id = `${d}_${Math.random().toString().slice(2, 6)}`;
}
return l;
}
function p(r) {
const { properties: o, title: u, required: a } = r;
if (a && Array.isArray(a)) {
const i = a.reduce((l, d) => (l[d] = o[d].type === "object" && o[d].properties ? c(o[d]) : $(o[d].default), l), {});
if (u && a.find((l) => l === "id")) {
const l = u.toLowerCase().replace(/-/g, "_");
i.id = `${l}_${Math.random().toString().slice(2, 6)}`;
}
return i;
}
return {
type: u
};
}
function T(r, o = {}, u) {
const a = e[r];
if (a) {
let i = p(a);
const l = t[r];
return i = l ? l({ getSchemaByType: T }, i, o, u) : i, n != null && n.appendIdentifyForNewControl && n.appendIdentifyForNewControl(i), i;
}
return null;
}
function g(r, o) {
const u = c(o);
return Object.keys(u).reduce((a, i) => (Object.prototype.hasOwnProperty.call(r, i) && (a[i] && z(a[i]) && z(r[i] || !r[i]) ? Object.assign(a[i], r[i] || {}) : a[i] = r[i]), a), u), u;
}
function S(r, o) {
return Object.keys(r).filter((a) => r[a] != null).reduce((a, i) => {
if (o.has(i)) {
const l = o.get(i);
if (typeof l == "string")
a[l] = r[i];
else {
const d = l(i, r[i], r);
Object.assign(a, d);
}
} else
a[i] = r[i];
return a;
}, {});
}
function b(r, o, u = /* @__PURE__ */ new Map()) {
const a = g(r, o);
return S(a, u);
}
function s(r) {
var u;
const o = r.type;
if (o) {
const a = e[o];
if (!a)
return r;
const i = g(r, a), l = ((u = r.editor) == null ? void 0 : u.type) || "";
if (l) {
const d = e[l], v = g(r.editor, d);
i.editor = v;
}
return i;
}
return r;
}
function m(r) {
n = r;
}
return { getSchemaByType: T, resolveSchemaWithDefaultValue: s, resolveSchemaToProps: b, mappingSchemaToProps: S, setDesignerContext: m };
}
const G = {}, U = {}, { getSchemaByType: pt, resolveSchemaWithDefaultValue: ge, resolveSchemaToProps: ye, mappingSchemaToProps: be, setDesignerContext: vt } = _(G, U);
function Se(e = {}) {
function t(s, m, r, o) {
if (typeof r == "number")
return o[s].length === r;
if (typeof r == "object") {
const u = Object.keys(r)[0], a = r[u];
if (u === "not")
return Number(o[s].length) !== Number(a);
if (u === "moreThan")
return Number(o[s].length) >= Number(a);
if (u === "lessThan")
return Number(o[s].length) <= Number(a);
}
return !1;
}
function n(s, m, r, o) {
return o[s] && o[s].propertyValue && String(o[s].propertyValue.value) === String(r);
}
const c = /* @__PURE__ */ new Map([
["length", t],
["getProperty", n]
]);
Object.keys(e).reduce((s, m) => (s.set(m, e[m]), s), c);
function p(s, m) {
const r = s;
return typeof m == "number" ? [{ target: r, operator: "length", param: null, value: Number(m) }] : typeof m == "boolean" ? [{ target: r, operator: "getProperty", param: s, value: !!m }] : typeof m == "object" ? Object.keys(m).map((o) => {
if (o === "length")
return { target: r, operator: "length", param: null, value: m[o] };
const u = o, a = m[o];
return { target: r, operator: "getProperty", param: u, value: a };
}) : [];
}
function T(s) {
return Object.keys(s).reduce((r, o) => {
const u = p(o, s[o]);
return r.push(...u), r;
}, []);
}
function g(s, m) {
if (c.has(s.operator)) {
const r = c.get(s.operator);
return r && r(s.target, s.param, s.value, m) || !1;
}
return !1;
}
function S(s, m) {
return T(s).reduce((u, a) => u && g(a, m), !0);
}
function b(s, m) {
const r = Object.keys(s), o = r.includes("allOf"), u = r.includes("anyOf"), a = o || u, d = (a ? s[a ? o ? "allOf" : "anyOf" : "allOf"] : [s]).map((x) => S(x, m));
return o ? !d.includes(!1) : d.includes(!0);
}
return { parseValueSchema: b };
}
const he = {
convertTo: (e, t, n, c) => {
e.appearance || (e.appearance = {}), e.appearance[t] = n;
},
convertFrom: (e, t, n) => e.appearance ? e.appearance[t] : e[t]
}, Fe = {
convertFrom: (e, t, n) => e.buttons && e.buttons.length ? `共 ${e.buttons.length} 项` : "无"
}, Ce = {
convertTo: (e, t, n, c) => {
e.editor && (e.editor[t] = n);
},
convertFrom: (e, t, n) => e.editor && Object.prototype.hasOwnProperty.call(e.editor, t) ? e.editor[t] : e[t]
}, Te = {
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: "多语输入框" }
}, xe = {
convertFrom: (e, t, n) => {
var p;
const c = e.editor && e.editor[t] ? e.editor[t] : e[t];
return ((p = Te[c]) == null ? void 0 : p.name) || c;
}
}, we = {
convertTo: (e, t, n, c) => {
e[t] = e[t];
},
convertFrom: (e, t, n) => e.editor ? n.getRealEditorType(e.editor.type) : ""
}, Oe = {
convertTo: (e, t, n, c) => {
(e.type === "data-grid-column" || e.type === "tree-grid-column") && (e.formatter ? e.formatter[t] = n : e.formatter = {
[t]: n
});
},
convertFrom: (e, t, n) => {
if (e.formatter) {
if (t === "trueText")
return e.formatter.trueText;
if (t === "falseText")
return e.formatter.falseText;
if (t === "prefix")
return e.formatter.prefix;
if (t === "suffix")
return e.formatter.suffix;
if (t === "precision")
return e.formatter.precision;
if (t === "decimal")
return e.formatter.decimal;
if (t === "thousand")
return e.formatter.thousand;
if (t === "tempDateFormat")
return e.formatter.dateFormat === "yyyy年MM月dd日" ? "yearMonthDay" : e.formatter.dateFormat === "yyyy-MM-dd HH:mm:ss" ? "yyyy-MM-ddTHH:mm:ss" : e.formatter.dateFormat === "yyyy/MM/dd HH:mm:ss" ? "yyyy/MM/ddTHH:mm:ss" : e.formatter.dateFormat === "yyyy年MM月dd日 HH时mm分ss秒" ? "yearMonthDayHourMinuteSecond" : e.formatter.tempDateFormat || e.formatter.dateFormat || "yyyy-MM-dd";
if (t === "customFormat")
return e.formatter.customFormat;
if (t === "type")
return e.formatter.type || "none";
}
return "none";
}
}, Pe = {
convertTo: (e, t, n, c) => {
e.command ? e.command[t] = n : e.command = {
[t]: n
}, t === "enable" && n && (e.command.commands || (e.command.commands = [
{
text: "编辑",
type: "primary",
command: "edit"
},
{
text: "删除",
type: "danger",
command: "remove"
}
]));
},
convertFrom: (e, t, n) => e.command && t === "enable" ? e.command.enable : ""
}, Me = {
convertTo: (e, t, n, c) => {
e.column ? e.column[t] = n : e.column = {
[t]: n
}, t === "fitColumns" && n && (e.column.fitMode || (e.column.fitMode = "average"));
},
convertFrom: (e, t, n) => {
if (e.column) {
if (t === "fitColumns")
return e.column.fitColumns;
if (t === "fitMode")
return e.column.fitMode;
}
return "";
}
}, De = {
convertTo: (e, t, n, c) => {
e.summary ? e.summary[t] = n : e.summary = {
[t]: n
}, t === "enable" && n && (e.summary ? e.summary.groupFields || (e.summary.groupFields = []) : e.summary = {
enable: n,
groupFields: []
});
},
convertFrom: (e, t, n) => e.summary && t === "enable" ? e.summary.enable : e.type === "data-grid-column" ? e.enableSummary === void 0 ? !1 : e.enableSummary : ""
}, Be = {
convertTo: (e, t, n, c) => {
e.group ? e.group[t] = n : e.group = {
[t]: n
}, t === "enable" && n && (e.group ? e.group.groupFields || (e.group.groupFields = []) : e.group = {
enable: n,
groupFields: [],
showSummary: !1
});
},
convertFrom: (e, t, n) => {
if (e.group) {
if (t === "enable")
return e.group.enable;
if (t === "showSummary")
return e.group.showSummary;
}
}
}, je = {
convertFrom: (e, t) => e.binding ? e.binding.path : "",
convertTo: (e, t, n) => {
if (n && n.length > 0) {
const c = n[0];
e.binding || (e.binding = {}), e.binding.type = "Form", e.binding.path = c.bindingField, e.binding.field = c.id, e.binding.fullPath = c.path, e.path = c.bindingPath;
}
}
}, Re = {
convertTo: (e, t, n, c) => {
e.pagination || (e.pagination = {}), e.pagination[t] = n;
},
convertFrom: (e, t, n) => e.pagination ? e.pagination[t] : e[t]
}, ke = {
convertTo: (e, t, n, c) => {
e.rowNumber || (e.rowNumber = {}), e.rowNumber[t] = n;
},
convertFrom: (e, t, n) => e.rowNumber ? e.rowNumber[t] : e[t]
}, Ee = {
convertTo: (e, t, n, c) => {
e.selection || (e.selection = {}), e.selection[t] = n;
},
convertFrom: (e, t, n) => e.selection ? e.selection[t] : e[t]
}, Ne = {
convertFrom: (e, t, n) => e[t] && e[t].length ? `共 ${e[t].length} 项` : ""
}, He = {
convertFrom: (e, t) => e[t] || "",
convertTo: (e, t, n) => {
e[t] = n;
}
}, $e = {
convertTo: (e, t, n, c) => {
e.size || (e.size = {}), e.size[t] = n;
},
convertFrom: (e, t, n) => e.size ? e.size[t] : e[t]
}, Ie = {
convertFrom: (e, t, n) => {
var c, p;
return (c = e.formatter) != null && c.data && t === "formatterEnumData" && !e.formatterEnumData ? (p = e.formatter) == null ? void 0 : p.data : e.formatterEnumData;
}
}, Ve = {
convertTo: (e, t, n, c) => {
e.sort || (e.sort = {}), e.sort[t] = n;
},
convertFrom: (e, t, n) => {
var c, p;
if (t === "mode")
return ((c = e.sort) == null ? void 0 : c.mode) || "client";
if (t === "multiSort")
return !!((p = e.sort) != null && p.multiSort);
}
}, Ae = {
convertTo: (e, t, n, c) => {
e.filter || (e.filter = {}), e.filter[t] = n;
},
convertFrom: (e, t, n) => {
var c;
if (t === "mode")
return ((c = e.filter) == null ? void 0 : c.mode) || "client";
}
}, Le = {
convertTo: (e, t, n, c) => {
e.rowOption ? e.rowOption[t] = n : e.rowOption = {
[t]: n
};
},
convertFrom: (e, t, n) => {
if (e.rowOption) {
if (t === "customRowStyle")
return e.rowOption.customRowStyle;
if (t === "customCellStyle")
return e.rowOption.customCellStyle;
}
return "";
}
};
function J(e, t, n) {
const c = /* @__PURE__ */ new Map([
["/converter/appearance.converter", he],
["/converter/buttons.converter", Fe],
["/converter/property-editor.converter", Ce],
["/converter/items-count.converter", Ne],
["/converter/type.converter", xe],
["/converter/change-editor.converter", we],
["/converter/change-formatter.converter", Oe],
["/converter/column-command.converter", Pe],
["/converter/column-option.converter", Me],
["/converter/summary.converter", De],
["/converter/group.converter", Be],
["/converter/form-group-label.converter", He],
["/converter/field-selector.converter", je],
["/converter/pagination.converter", Re],
["/converter/row-number.converter", ke],
["/converter/grid-selection.converter", Ee],
["/converter/size.converter", $e],
["/converter/change-formatter-enum.converter", Ie],
["/converter/grid-sort.converter", Ve],
["/converter/grid-filter.converter", Ae],
["/converter/row-option.converter", Le]
]), p = /* @__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 }]
]), T = Se();
function g(a, i) {
return () => T.parseValueSchema(a, i);
}
function S(a, i, l) {
return a.includes("visible") && i.visible !== void 0 ? typeof i.visible == "boolean" ? () => !!i.visible : i.visible === void 0 ? !0 : g(i.visible, l) : () => !0;
}
function b(a, i, l) {
return a.includes("readonly") && i.readonly !== void 0 ? typeof i.readonly == "boolean" ? () => !!i.readonly : g(i.readonly, l) : () => !1;
}
function s(a, i) {
const l = a.$converter || i;
return typeof l == "string" && l && c.has(l) ? c.get(l) || null : l || null;
}
function m(a, i, l, d, v, x = "", P = "") {
return Object.keys(a).map((h) => {
const y = C(1), F = h, f = a[h], w = Object.keys(f), j = f.title, R = f.type, k = p.get(R) || { type: "input-group", enableClear: !1 }, B = f.editor ? Object.assign({}, k, f.editor) : Object.assign({}, k), V = S(w, f, i), I = b(w, f, i);
B.readonly = B.readonly === void 0 ? I() : B.readonly;
const A = f.type === "cascade" ? m(f.properties, i, l, d, v, x, P) : [], ne = !0;
let M = s(f, P);
const re = N({
get() {
if (y.value) {
if (["class", "style"].find((ue) => ue === F) && !M && (M = c.get("/converter/appearance.converter") || null), M && M.convertFrom)
return M.convertFrom(l, h, v, x);
const D = l[h];
return Object.prototype.hasOwnProperty.call(f, "defaultValue") && (D === void 0 || typeof D == "string" && D === "") ? f.type === "boolean" ? f.defaultValue : f.defaultValue || "" : D;
}
return null;
},
set(D) {
y.value += 1, M && M.convertTo ? (M.convertTo(d, h, D, v, x), M.convertTo(l, h, D, v, x)) : (d[h] = D, l[h] = D);
}
}), { refreshPanelAfterChanged: oe, description: ae, isExpand: ie, parentPropertyID: le } = f, q = { propertyID: F, propertyName: j, propertyType: R, propertyValue: re, editor: B, visible: V, readonly: I, cascadeConfig: A, hideCascadeTitle: ne, refreshPanelAfterChanged: oe, description: ae, isExpand: ie, parentPropertyID: le };
return i[F] = q, q;
});
}
function r(a, i, l = {}) {
const d = {}, v = e[a];
return v && v.categories ? Object.keys(v.categories).map((P) => {
const O = v.categories[P], h = O == null ? void 0 : O.title, y = m(O.properties || {}, d, {}, l, i);
return { categoryId: P, categoryName: h, properties: y };
}) : [];
}
function o(a, i, l, d, v = "") {
const x = i.$ref.schema, P = i.$ref.converter, O = l[x], h = O.type, y = n(O), F = {}, f = e[h];
if (f && f.categories) {
const w = f.categories[a], j = w == null ? void 0 : w.title;
P && Object.keys(w.properties).forEach((B) => {
w.properties[B].$converter = P;
});
const R = (w == null ? void 0 : w.properties) || {}, k = m(R, F, y, O, d, v);
return { categoryId: a, categoryName: j, properties: k };
}
return { categoryId: a, categoryName: "", properties: [] };
}
function u(a, i, l, d, v) {
const x = a.type, P = n(a), O = {};
let h = v || e[x];
if (h && Object.keys(h).length === 0 && l && l.getPropConfig && (h = l.getPropConfig(d)), h && h.categories) {
const y = [];
return Object.keys(h.categories).map((F) => {
const f = h.categories[F];
if (f.$ref) {
y.push(o(F, f, a, i, d));
return;
}
const w = f == null ? void 0 : f.title, j = f == null ? void 0 : f.tabId, R = f == null ? void 0 : f.tabName, k = f == null ? void 0 : f.hide, B = f == null ? void 0 : f.hideTitle, V = m(f.properties || {}, O, P, a, i, d, f.$converter), { setPropertyRelates: I } = f, A = f == null ? void 0 : f.parentPropertyID;
y.push({ categoryId: F, categoryName: w, tabId: j, tabName: R, hide: k, properties: V, hideTitle: B, setPropertyRelates: I, parentPropertyID: A });
}), y;
}
return [];
}
return {
getPropertyConfigBySchema: u,
getPropertyConfigByType: r,
propertyConverterMap: c
};
}
const Q = {}, X = {};
J(Q, X, ge);
const Y = {}, Z = {}, { getSchemaByType: gt, resolveSchemaWithDefaultValue: qe, resolveSchemaToProps: yt, mappingSchemaToProps: bt, setDesignerContext: St } = _(Y, Z), K = {}, ee = {};
J(K, ee, qe);
function ze(e, t, n = /* @__PURE__ */ new Map(), c = (g, S, b, s) => S, p = {}, T = (g) => g) {
return G[t.title] = t, U[t.title] = c, Q[t.title] = p, X[t.title] = T, Y[t.title] = t, Z[t.title] = c, K[t.title] = p, ee[t.title] = T, (g = {}, S = !0) => {
if (!S)
return be(g, n);
const b = ye(g, t, n), s = Object.keys(e).reduce((m, r) => (m[r] = e[r].default, m), {});
return Object.assign(s, b);
};
}
function We(e, t) {
return { customClass: t.class, customStyle: t.style };
}
const _e = /* @__PURE__ */ new Map([
["appearance", We]
]), Ge = "https://json-schema.org/draft/2020-12/schema", Ue = "https://farris-design.gitee.io/combo-list.schema.json", Je = "combo-tree", Qe = "A Farris Input Component", Xe = "object", Ye = {
id: {
description: "The unique identifier for a combo list",
type: "string"
},
type: {
description: "The type string of number combo list component",
type: "string",
default: "combo-tree"
},
appearance: {
description: "",
type: "object",
properties: {
class: {
type: "string"
},
style: {
type: "string"
}
},
default: {}
},
binding: {
description: "",
type: "object",
default: {}
},
editable: {
description: "",
type: "boolean",
default: !0
},
enableLinkLabel: {
description: "",
type: "boolean",
default: !1
},
label: {
description: "",
type: "string",
default: ""
},
lableWidth: {
description: "",
type: "number"
},
placeholder: {
description: "",
type: "string",
default: ""
},
valueField: {
description: "",
type: "string",
default: "id"
},
titleField: {
description: "",
type: "string",
default: "name"
},
textField: {
description: "",
type: "string",
default: "name"
},
data: {
description: "",
type: "array"
},
readonly: {
description: "",
type: "boolean",
default: !1
},
required: {
description: "",
type: "boolean",
default: !1
},
tabindex: {
description: "",
type: "number",
default: -1
},
textAlign: {
description: "",
type: "string",
enum: [
"left",
"middle",
"right"
],
default: "left"
},
visible: {
description: "",
type: "boolean",
default: !0
},
onBlur: {
description: "",
type: "string",
default: ""
},
onClickLinkLabel: {
description: "",
type: "sting",
default: ""
},
formatter: {
type: "object",
default: null
},
customRowStatus: {
type: "object",
default: null
},
minPanelWidth: {
description: "",
type: "number",
default: 160
},
idField: {
description: "",
type: "string",
default: "id"
},
multiSelect: {
description: "",
type: "boolean",
default: !1
},
viewType: {
description: "",
type: "string",
default: "text"
},
searchFields: {
description: "",
type: "array",
default: []
},
enableSearch: {
description: "",
type: "boolean",
default: !1
},
displayFormatter: {
type: "object",
default: null
}
}, Ze = [
"id",
"type"
], Ke = {
$schema: Ge,
$id: Ue,
title: Je,
description: Qe,
type: Xe,
properties: Ye,
required: Ze
};
function et(e, t, n) {
return t;
}
var tt = /* @__PURE__ */ ((e) => (e.Text = "text", e.Tag = "tag", e))(tt || {}), nt = /* @__PURE__ */ ((e) => (e.top = "top", e.bottom = "bottom", e.auto = "auto", e))(nt || {});
const te = {
/**
* 组件标识
*/
id: { type: String },
/**
* 下拉数据源
*/
data: { type: Array, default: [] },
/**
* 可选,展示文本
* 默认为空字符串
*/
displayText: { type: String, default: "" },
/**
* 可选,是否禁用
* 默认为`false`
*/
disabled: { type: Boolean, default: !1 },
/**
* 可选,下拉图标
* 默认为'<span class="f-icon f-icon-arrow-60-down"></span>'
*/
dropDownIcon: { type: String, default: '<span class="f-icon f-icon-arrow-chevron-down"></span>' },
/**
* 可选,是否可编辑
* 默认`false`
*/
editable: { type: Boolean, default: !1 },
/**
* 可选,是否启用清空
* 默认启用
*/
enableClear: { type: Boolean, default: !0 },
/**
* 可选,启用搜索
* 默认为`false`
*/
enableSearch: { type: Boolean, default: !1 },
/**
* 可选,鼠标悬停时是否显示控件值
* 默认显示
*/
enableTitle: { type: Boolean, default: !0 },
fitEditor: { type: Boolean, default: !1 },
/**
* 可选,强制显示占位符
* 默认`false`
*/
forcePlaceholder: { type: Boolean, default: !1 },
/**
* 可选,清空值时隐藏面板
* 默认`true`
*/
hidePanelOnClear: { type: Boolean, default: !0 },
/**
* 可选,数据源id字段
* 默认为`id`
*/
idField: { type: String, default: "id" },
/**
* 可选,字段映射
*/
mapFields: { type: Object },
/**
* 可选,最大高度
* 默认`350`
*/
maxHeight: { type: Number, default: 350 },
/**
* 最大输入长度
*/
maxLength: { type: Number },
/**
* 可选,是否支持多选
* 默认`false`
*/
multiSelect: { type: Boolean, default: !1 },
/**
* 绑定值
*/
modelValue: { type: String, default: "" },
/**
* 占位符
*/
placeholder: { type: String },
/**
* 可选,下拉面板展示位置
* 默认为`auto`
*/
placement: {
type: String,
default: "auto"
/* auto */
},
/**
* 可选,是否只读
* 默认为`false`
*/
readonly: { type: Boolean, default: !1 },
/**
* 可选,是否支持远端过滤
* 默认`false`
*/
remoteSearch: { type: Boolean, default: !1 },
/**
* 可选,分隔符
* 默认`,`
*/
separator: { type: String, default: "," },
/**
* tabIndex
*/
tabIndex: { type: Number, default: -1 },
/**
* 可选,数据源显示字段
* 默认为`name`
*/
textField: { type: String, default: "name" },
/**
* 可选,数据源的title
* 默认为`name`
*/
titleField: { type: String, default: "name" },
/**
* 可选,数据源值字段
* 默认为`id`
*/
valueField: { type: String, default: "id" },
/**
* 可选,下拉列表值展示方式
* 支持text | tag,即文本或标签,默认为`ViewType.Text`,即文本方式`text`
*/
viewType: {
type: String,
default: "text"
/* Text */
},
/**
* 作为内嵌编辑器被创建后默认获得焦点
*/
focusOnCreated: { type: Boolean, default: !1 },
/**
* 作为内嵌编辑器被创建后默认选中文本
*/
selectOnCreated: { type: Boolean, default: !1 },
/**
* 树表展示格式化函数
*/
formatter: { type: Function, default: null },
/**
* 显示文本格式化函数
*/
displayFormatter: { type: Function, default: null },
editorParams: { type: Object },
repositoryToken: { type: Symbol, default: null },
/** 自定义行状态 */
customRowStatus: { type: Object, default: null },
minPanelWidth: { type: Number, default: 160 },
/** 查询字段集合 */
searchFields: { type: Array, default: ["name"] }
}, rt = ze(te, Ke, _e, et), ot = {
data: { type: Array, default: [] },
enableSearch: { type: Boolean, default: !1 },
idField: { type: String, default: "id" },
multiSelect: { default: !1, type: Boolean },
selectedValues: { type: String, default: "" },
separator: { type: String, default: "," },
textField: { type: String, default: "name" },
titleField: { type: String, default: "name" },
width: { type: Number },
height: { type: Number },
valueField: { type: String, default: "id" },
formatter: { type: Function },
maxHeight: { type: Number, default: 350 },
repositoryToken: { type: Symbol, default: null },
editorParams: { type: Object },
customRowStatus: { type: Object, default: null },
searchHandler: { type: Function, default: () => {
} }
}, at = /* @__PURE__ */ W({
name: "FComboTreeContainer",
props: ot,
emits: ["selectionChange"],
setup(e, t) {
const n = C(e.data), c = C([]), p = C(e.separator), T = C(e.width), g = C(e.height), S = C(e.maxHeight), b = C(String(e.selectedValues).split(p.value)), s = C(), m = {
customRowStatus: e.customRowStatus
};
H(() => e.data, (l) => {
var d;
n.value = l, (d = s.value) == null || d.updateDataSource(l);
});
const r = {
enableSelectRow: !0,
multiSelect: e.multiSelect,
showCheckbox: e.multiSelect,
multiSelectMode: "OnCheckAndClick"
};
let o = null;
e.repositoryToken && (o = ce(e.repositoryToken));
const u = N(() => [{
field: e.textField,
title: "",
dataType: "string",
formatter: e.formatter
}]), a = N(() => {
const l = {};
return T.value !== void 0 && (l.width = `${T.value}px`), g.value !== void 0 && (l.height = `${g.value}px`), S.value !== void 0 && S.value > 0 && (l.maxHeight = `${S.value}px`, l.overflow = "auto"), n.value.length === 0 && (l.height = "200px"), l.position = "relative", l;
});
function i(l = []) {
l && l.length > 0 ? (c.value = [...l], b.value = c.value.map((d) => d[e.idField])) : (c.value = [], b.value = []), t.emit("selectionChange", c.value);
}
return se(() => {
o && o.getData(e.editorParams).then((l) => {
n.value = l;
}), b.value && s.value.activeRowById(b.value[0]);
}), t.expose({
treeInstance: s
}), () => E("div", {
class: "f-combo-tree-container",
style: a.value
}, [e.multiSelect && e.enableSearch && E("div", {
class: "p-2",
style: "position: sticky;top:0;z-index: 2; background:white",
onMousedown: (l) => l.stopPropagation()
}, [E(pe, {
buttonContent: '<i class="f-icon f-icon-search"></i>',
enableClear: !0,
placeholder: "请输入搜索内容",
onClear: () => t.emit("clearSearch"),
onInput: (l, d) => e.searchHandler(d)
}, null)]), E(me, {
ref: s,
fit: !0,
data: n.value,
idField: e.idField,
columns: u.value,
"selection-values": b.value,
onSelectionChange: i,
columnOption: {
fitColumns: !0,
fitMode: "expand"
},
rowOption: m,
selection: r,
rowNumber: {
enable: !1
}
}, null)]);
}
});
function it(e) {
const t = C(""), n = C(e.modelValue), c = C(e.data || []), p = C(e.editable);
function T(r, o = []) {
return r = r || [], r.reduce((u, a) => (u.push(a), a.children && a.children.length && T(a.children, u), u), o);
}
function g(r) {
const o = String(r).split(e.separator).map((l, d) => [l, d]), u = new Map(o), a = [];
return T(c.value, a), a.filter((l) => {
const d = l.data ? String(l.data[e.valueField]) : String(l[e.valueField]);
return u.has(d);
}).map((l) => l.data ? l.data : l).sort((l, d) => {
const v = u.get(String(l[e.valueField])) || 0, x = u.get(String(d[e.valueField])) || 0;
return v - x;
});
}
function S(r) {
const o = g(r), u = e.displayFormatter ? e.displayFormatter(o) : o.map((a) => a[e.textField]).join(e.separator);
t.value = p.value ? u || r : u;
}
function b(r) {
const o = r.split(e.separator).map((i) => [i, !0]), u = new Map(o);
let a = [];
return c.value[0].data ? T(c.value, a) : a = c.value, a = a.map((i) => i.data ? i.data : i), a.filter((i) => u.has(i[e.textField]) || u.has(i[e.valueField]));
}
function s(r) {
const o = {};
return o[e.idField] = r, o[e.textField] = r, [o];
}
function m(r) {
let o = b(r);
const u = o && o.length > 0;
return p.value && !u && (o = s(r)), o;
}
return H(() => e.data, () => {
c.value = e.data;
}), H([c], ([r]) => {
if (e.modelValue) {
const o = r.find((u) => u[e.valueField] === e.modelValue);
o && (t.value = o[e.textField]);
}
}), H(() => e.modelValue, (r, o) => {
r !== o && (n.value = r, S(r));
}), S(e.modelValue), { dataSource: c, displayText: t, editable: p, modelValue: n, getItemsByDisplayText: b, getItemsByValue: g, getSelectedItemsByDisplayText: m };
}
function lt(e) {
const { comboEditorRef: t, dataSource: n, searchFields: c, originalValue: p, showPopover: T } = e;
function g(r, o) {
const u = (r.children || []).map((i) => g(i, o)).filter((i) => i !== null);
return c.value.some((i) => {
var l;
return (l = r.data[i]) == null ? void 0 : l.toString().toLowerCase().includes(o.toLowerCase());
}) ? {
data: { ...r.data },
children: r.children
// 注意这里保留原始子节点
} : u.length > 0 ? {
data: { ...r.data },
children: u
} : null;
}
function S() {
p.value = $(n.value);
}
function b(r) {
var u;
if (T.value || (u = t.value) == null || u.showPopup(), !r) {
S();
return;
}
const o = n.value.map((a) => g(a, r)).filter((a) => a !== null);
p.value = $(o);
}
const s = fe((r) => {
var u;
const o = (u = r.target) == null ? void 0 : u.value;
b(o);
}, 200);
function m(r) {
var u;
let o = (u = r.target) == null ? void 0 : u.value;
o !== "" && (o = o.trim()), r.target._value !== o && s(r);
}
return {
onValueChange: m,
resetDataSource: S
};
}
const L = /* @__PURE__ */ W({
name: "FComboTree",
props: te,
emits: ["clear", "update:modelValue", "change", "search"],
setup(e, t) {
const n = C(), c = C(e.disabled), p = C(e.enableClear), T = C(e.enableSearch), g = C(e.readonly), S = C(e.searchFields || [e.textField]), b = C(), s = C(), {
dataSource: m,
displayText: r,
editable: o,
modelValue: u,
getSelectedItemsByDisplayText: a
} = it(e), i = N(() => e.multiSelect);
N(() => n.value ? n.value.elementRef.getBoundingClientRect().width : 0);
const l = N(() => {
var F;
const y = (F = n.value) == null ? void 0 : F.popoverRef;
return y ? y.shown : !1;
}), {
onValueChange: d,
resetDataSource: v
} = lt({
comboEditorRef: n,
dataSource: m,
searchFields: S,
originalValue: b,
showPopover: l
});
function x() {
!i.value && n.value && n.value.hidePopup();
}
function P(y) {
r.value = e.displayFormatter ? e.displayFormatter(y) : y.map((F) => F[e.textField]).join(e.separator), u.value = y.map((F) => F[e.valueField]).join(e.separator), t.emit("update:modelValue", u.value), t.emit("change", y, u.value), x();
}
function O(y) {
var F;
u.value = "", l.value && ((F = n.value) == null || F.hidePopup()), t.emit("update:modelValue", ""), t.emit("change", null, u.value), t.emit("clear");
}
H([() => e.disabled, () => e.editable, () => e.enableClear, () => e.enableSearch, () => e.readonly], ([y, F, f, w, j]) => {
c.value = y, o.value = F, p.value = f, T.value = w, g.value = j;
});
const h = () => {
b.value = $(m.value);
};
return () => E(de, {
ref: n,
id: e.id,
disable: c.value,
readonly: g.value,
forcePlaceholder: e.forcePlaceholder,
editable: o.value && !e.multiSelect,
buttonContent: e.dropDownIcon,
placeholder: e.placeholder,
enableClear: p.value,
maxLength: e.maxLength,
tabIndex: e.tabIndex,
enableTitle: e.enableTitle,
inputType: e.viewType,
popupOnClick: !0,
modelValue: r.value,
"onUpdate:modelValue": (y) => r.value = y,
onClear: O,
onInput: d,
focusOnCreated: e.focusOnCreated,
selectOnCreated: e.selectOnCreated,
beforeOpen: h,
placement: e.placement,
popupMinWidth: e.minPanelWidth
}, {
default: () => [l.value && E(at, {
ref: s,
maxHeight: e.maxHeight,
multiSelect: e.multiSelect,
enableSearch: e.enableSearch,
idField: e.idField,
valueField: e.valueField,
textField: e.textField,
titleField: e.titleField,
data: b.value,
selectedValues: u.value,
onSelectionChange: P,
formatter: e.formatter,
editorParams: e.editorParams,
repositoryToken: e.repositoryToken,
customRowStatus: e.customRowStatus,
searchHandler: d,
onClearSearch: v
}, null)]
});
}
});
L.register = (e, t, n, c) => {
e["combo-tree"] = L, t["combo-tree"] = rt;
};
const ht = ve(L);
export {
L as FComboTree,
nt as Placement,
tt as ViewType,
te as comboTreeProps,
ht as default,
rt as propsResolver
};