UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

1,091 lines (1,090 loc) 35.6 kB
import { ref as k, computed as M, inject as de, reactive as J, defineComponent as R, createVNode as C, createTextVNode as _, watch as L } from "vue"; import { cloneDeep as I, isPlainObject as G } from "lodash-es"; import fe, { FButtonEdit as me } from "../button-edit/index.esm.js"; import { F_NOTIFY_SERVICE_TOKEN as pe } from "../notify/index.esm.js"; import ve, { EditorType as ge } from "../event-parameter/index.esm.js"; import { useGuid as be, withInstall as ye } from "../common/index.esm.js"; function U(e, t) { let n; function l(i) { const { properties: a, title: d, ignore: r } = i, o = r && Array.isArray(r), s = Object.keys(a).reduce((v, T) => ((!o || !r.find((j) => j === T)) && (v[T] = a[T].type === "object" && a[T].properties ? l(a[T]) : I(a[T].default)), v), {}); if (d && (!o || !r.find((v) => v === "id"))) { const v = d.toLowerCase().replace(/-/g, "_"); s.id = `${v}_${Math.random().toString().slice(2, 6)}`; } return s; } function b(i) { const { properties: a, title: d, required: r } = i; if (r && Array.isArray(r)) { const o = r.reduce((s, v) => (s[v] = a[v].type === "object" && a[v].properties ? l(a[v]) : I(a[v].default), s), {}); if (d && r.find((s) => s === "id")) { const s = d.toLowerCase().replace(/-/g, "_"); o.id = `${s}_${Math.random().toString().slice(2, 6)}`; } return o; } return { type: d }; } function F(i, a = {}, d) { const r = e[i]; if (r) { let o = b(r); const s = t[i]; return o = s ? s({ getSchemaByType: F }, o, a, d) : o, n != null && n.appendIdentifyForNewControl && n.appendIdentifyForNewControl(o), o; } return null; } function y(i, a) { const d = l(a); return Object.keys(d).reduce((r, o) => (Object.prototype.hasOwnProperty.call(i, o) && (r[o] && G(r[o]) && G(i[o] || !i[o]) ? Object.assign(r[o], i[o] || {}) : r[o] = i[o]), r), d), d; } function P(i, a) { return Object.keys(i).filter((r) => i[r] != null).reduce((r, o) => { if (a.has(o)) { const s = a.get(o); if (typeof s == "string") r[s] = i[o]; else { const v = s(o, i[o], i); Object.assign(r, v); } } else r[o] = i[o]; return r; }, {}); } function h(i, a, d = /* @__PURE__ */ new Map()) { const r = y(i, a); return P(r, d); } function f(i) { var d; const a = i.type; if (a) { const r = e[a]; if (!r) return i; const o = y(i, r), s = ((d = i.editor) == null ? void 0 : d.type) || ""; if (s) { const v = e[s], T = y(i.editor, v); o.editor = T; } return o; } return i; } function p(i) { n = i; } return { getSchemaByType: F, resolveSchemaWithDefaultValue: f, resolveSchemaToProps: h, mappingSchemaToProps: P, setDesignerContext: p }; } const W = {}, Y = {}, { getSchemaByType: Ct, resolveSchemaWithDefaultValue: Ce, resolveSchemaToProps: Te, mappingSchemaToProps: Fe, setDesignerContext: Tt } = U(W, Y); function Se(e = {}) { function t(f, p, i, a) { if (typeof i == "number") return a[f].length === i; if (typeof i == "object") { const d = Object.keys(i)[0], r = i[d]; if (d === "not") return Number(a[f].length) !== Number(r); if (d === "moreThan") return Number(a[f].length) >= Number(r); if (d === "lessThan") return Number(a[f].length) <= Number(r); } return !1; } function n(f, p, i, a) { return a[f] && a[f].propertyValue && String(a[f].propertyValue.value) === String(i); } const l = /* @__PURE__ */ new Map([ ["length", t], ["getProperty", n] ]); Object.keys(e).reduce((f, p) => (f.set(p, e[p]), f), l); function b(f, p) { const i = f; return typeof p == "number" ? [{ target: i, operator: "length", param: null, value: Number(p) }] : typeof p == "boolean" ? [{ target: i, operator: "getProperty", param: f, value: !!p }] : typeof p == "object" ? Object.keys(p).map((a) => { if (a === "length") return { target: i, operator: "length", param: null, value: p[a] }; const d = a, r = p[a]; return { target: i, operator: "getProperty", param: d, value: r }; }) : []; } function F(f) { return Object.keys(f).reduce((i, a) => { const d = b(a, f[a]); return i.push(...d), i; }, []); } function y(f, p) { if (l.has(f.operator)) { const i = l.get(f.operator); return i && i(f.target, f.param, f.value, p) || !1; } return !1; } function P(f, p) { return F(f).reduce((d, r) => d && y(r, p), !0); } function h(f, p) { const i = Object.keys(f), a = i.includes("allOf"), d = i.includes("anyOf"), r = a || d, v = (r ? f[r ? a ? "allOf" : "anyOf" : "allOf"] : [f]).map((j) => P(j, p)); return a ? !v.includes(!1) : v.includes(!0); } return { parseValueSchema: h }; } const Pe = { convertTo: (e, t, n, l) => { e.appearance || (e.appearance = {}), e.appearance[t] = n; }, convertFrom: (e, t, n) => e.appearance ? e.appearance[t] : e[t] }, he = { convertFrom: (e, t, n) => e.buttons && e.buttons.length ? `共 ${e.buttons.length} 项` : "无" }, je = { convertTo: (e, t, n, l) => { e.editor && (e.editor[t] = n); }, convertFrom: (e, t, n) => e.editor && Object.prototype.hasOwnProperty.call(e.editor, t) ? e.editor[t] : e[t] }, Oe = { 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 b; const l = e.editor && e.editor[t] ? e.editor[t] : e[t]; return ((b = Oe[l]) == null ? void 0 : b.name) || l; } }, De = { convertTo: (e, t, n, l) => { e[t] = e[t]; }, convertFrom: (e, t, n) => e.editor ? n.getRealEditorType(e.editor.type) : "" }, Ee = { convertTo: (e, t, n, l) => { (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"; } }, we = { convertTo: (e, t, n, l) => { 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 : "" }, ke = { convertTo: (e, t, n, l) => { 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 ""; } }, Me = { convertTo: (e, t, n, l) => { 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 : "" }, Ne = { convertTo: (e, t, n, l) => { 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; } } }, Ve = { convertFrom: (e, t) => e.binding ? e.binding.path : "", convertTo: (e, t, n) => { if (n && n.length > 0) { const l = n[0]; e.binding || (e.binding = {}), e.binding.type = "Form", e.binding.path = l.bindingField, e.binding.field = l.id, e.binding.fullPath = l.path, e.path = l.bindingPath; } } }, Be = { convertTo: (e, t, n, l) => { e.pagination || (e.pagination = {}), e.pagination[t] = n; }, convertFrom: (e, t, n) => e.pagination ? e.pagination[t] : e[t] }, $e = { convertTo: (e, t, n, l) => { e.rowNumber || (e.rowNumber = {}), e.rowNumber[t] = n; }, convertFrom: (e, t, n) => e.rowNumber ? e.rowNumber[t] : e[t] }, Re = { convertTo: (e, t, n, l) => { e.selection || (e.selection = {}), e.selection[t] = n; }, convertFrom: (e, t, n) => e.selection ? e.selection[t] : e[t] }, Ae = { 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; } }, Je = { convertTo: (e, t, n, l) => { e.size || (e.size = {}), e.size[t] = n; }, convertFrom: (e, t, n) => e.size ? e.size[t] : e[t] }, ze = { convertFrom: (e, t, n) => { var l, b; return (l = e.formatter) != null && l.data && t === "formatterEnumData" && !e.formatterEnumData ? (b = e.formatter) == null ? void 0 : b.data : e.formatterEnumData; } }, qe = { convertTo: (e, t, n, l) => { e.sort || (e.sort = {}), e.sort[t] = n; }, convertFrom: (e, t, n) => { var l, b; if (t === "mode") return ((l = e.sort) == null ? void 0 : l.mode) || "client"; if (t === "multiSort") return !!((b = e.sort) != null && b.multiSort); } }, _e = { convertTo: (e, t, n, l) => { e.filter || (e.filter = {}), e.filter[t] = n; }, convertFrom: (e, t, n) => { var l; if (t === "mode") return ((l = e.filter) == null ? void 0 : l.mode) || "client"; } }, Le = { convertTo: (e, t, n, l) => { 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 Q(e, t, n) { const l = /* @__PURE__ */ new Map([ ["/converter/appearance.converter", Pe], ["/converter/buttons.converter", he], ["/converter/property-editor.converter", je], ["/converter/items-count.converter", Ae], ["/converter/type.converter", xe], ["/converter/change-editor.converter", De], ["/converter/change-formatter.converter", Ee], ["/converter/column-command.converter", we], ["/converter/column-option.converter", ke], ["/converter/summary.converter", Me], ["/converter/group.converter", Ne], ["/converter/form-group-label.converter", He], ["/converter/field-selector.converter", Ve], ["/converter/pagination.converter", Be], ["/converter/row-number.converter", $e], ["/converter/grid-selection.converter", Re], ["/converter/size.converter", Je], ["/converter/change-formatter-enum.converter", ze], ["/converter/grid-sort.converter", qe], ["/converter/grid-filter.converter", _e], ["/converter/row-option.converter", Le] ]), b = /* @__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 }] ]), F = Se(); function y(r, o) { return () => F.parseValueSchema(r, o); } function P(r, o, s) { return r.includes("visible") && o.visible !== void 0 ? typeof o.visible == "boolean" ? () => !!o.visible : o.visible === void 0 ? !0 : y(o.visible, s) : () => !0; } function h(r, o, s) { return r.includes("readonly") && o.readonly !== void 0 ? typeof o.readonly == "boolean" ? () => !!o.readonly : y(o.readonly, s) : () => !1; } function f(r, o) { const s = r.$converter || o; return typeof s == "string" && s && l.has(s) ? l.get(s) || null : s || null; } function p(r, o, s, v, T, j = "", x = "") { return Object.keys(r).map((c) => { const g = k(1), S = c, m = r[c], O = Object.keys(m), B = m.title, N = m.type, V = b.get(N) || { type: "input-group", enableClear: !1 }, w = m.editor ? Object.assign({}, V, m.editor) : Object.assign({}, V), A = P(O, m, o), $ = h(O, m, o); w.readonly = w.readonly === void 0 ? $() : w.readonly; const H = m.type === "cascade" ? p(m.properties, o, s, v, T, j, x) : [], oe = !0; let D = f(m, x); const ie = M({ get() { if (g.value) { if (["class", "style"].find((ce) => ce === S) && !D && (D = l.get("/converter/appearance.converter") || null), D && D.convertFrom) return D.convertFrom(s, c, T, j); const E = s[c]; return Object.prototype.hasOwnProperty.call(m, "defaultValue") && (E === void 0 || typeof E == "string" && E === "") ? m.type === "boolean" ? m.defaultValue : m.defaultValue || "" : E; } return null; }, set(E) { g.value += 1, D && D.convertTo ? (D.convertTo(v, c, E, T, j), D.convertTo(s, c, E, T, j)) : (v[c] = E, s[c] = E); } }), { refreshPanelAfterChanged: ae, description: le, isExpand: se, parentPropertyID: ue } = m, q = { propertyID: S, propertyName: B, propertyType: N, propertyValue: ie, editor: w, visible: A, readonly: $, cascadeConfig: H, hideCascadeTitle: oe, refreshPanelAfterChanged: ae, description: le, isExpand: se, parentPropertyID: ue }; return o[S] = q, q; }); } function i(r, o, s = {}) { const v = {}, T = e[r]; return T && T.categories ? Object.keys(T.categories).map((x) => { const u = T.categories[x], c = u == null ? void 0 : u.title, g = p(u.properties || {}, v, {}, s, o); return { categoryId: x, categoryName: c, properties: g }; }) : []; } function a(r, o, s, v, T = "") { const j = o.$ref.schema, x = o.$ref.converter, u = s[j], c = u.type, g = n(u), S = {}, m = e[c]; if (m && m.categories) { const O = m.categories[r], B = O == null ? void 0 : O.title; x && Object.keys(O.properties).forEach((w) => { O.properties[w].$converter = x; }); const N = (O == null ? void 0 : O.properties) || {}, V = p(N, S, g, u, v, T); return { categoryId: r, categoryName: B, properties: V }; } return { categoryId: r, categoryName: "", properties: [] }; } function d(r, o, s, v, T) { const j = r.type, x = n(r), u = {}; let c = T || e[j]; if (c && Object.keys(c).length === 0 && s && s.getPropConfig && (c = s.getPropConfig(v)), c && c.categories) { const g = []; return Object.keys(c.categories).map((S) => { const m = c.categories[S]; if (m.$ref) { g.push(a(S, m, r, o, v)); return; } const O = m == null ? void 0 : m.title, B = m == null ? void 0 : m.tabId, N = m == null ? void 0 : m.tabName, V = m == null ? void 0 : m.hide, w = m == null ? void 0 : m.hideTitle, A = p(m.properties || {}, u, x, r, o, v, m.$converter), { setPropertyRelates: $ } = m, H = m == null ? void 0 : m.parentPropertyID; g.push({ categoryId: S, categoryName: O, tabId: B, tabName: N, hide: V, properties: A, hideTitle: w, setPropertyRelates: $, parentPropertyID: H }); }), g; } return []; } return { getPropertyConfigBySchema: d, getPropertyConfigByType: i, propertyConverterMap: l }; } const X = {}, Z = {}; Q(X, Z, Ce); const K = {}, ee = {}, { getSchemaByType: Ft, resolveSchemaWithDefaultValue: Ie, resolveSchemaToProps: St, mappingSchemaToProps: Pt, setDesignerContext: ht } = U(K, ee), te = {}, ne = {}; Q(te, ne, Ie); function Ge(e, t, n = /* @__PURE__ */ new Map(), l = (y, P, h, f) => P, b = {}, F = (y) => y) { return W[t.title] = t, Y[t.title] = l, X[t.title] = b, Z[t.title] = F, K[t.title] = t, ee[t.title] = l, te[t.title] = b, ne[t.title] = F, (y = {}, P = !0) => { if (!P) return Fe(y, n); const h = Te(y, t, n), f = Object.keys(e).reduce((p, i) => (p[i] = e[i].default, p), {}); return Object.assign(f, h); }; } const Ue = "https://json-schema.org/draft/2020-12/schema", We = "https://farris-design.gitee.io/json-editor.schema.json", Ye = "json-editor", Qe = "A Farris Component", Xe = "object", Ze = { type: { description: "The type string of json-editor", type: "string", default: "json-editor" }, parameterDescriptors: { description: "Description of parameters to be configured", type: "array", default: [] }, formContextData: { description: "Form context data", type: "object", default: {} }, beforeOpen: { description: "Before opening the configuration dialog, the callback function is executed", type: "function", default: null }, dialogTitle: { description: "Title of the dialog modal", type: "string", default: "JSON编辑器" }, keyColumnTitle: { description: "Title for the key column in the table", type: "string", default: "键" }, valueColumnTitle: { description: "Title for the value column in the table", type: "string", default: "值" }, operationColumnTitle: { description: "Title for the operation column", type: "string", default: "操作" }, keyColumnPlaceholder: { description: "Placeholder text for key input fields", type: "string", default: "" }, valueColumnPlaceholder: { description: "Placeholder text for value input fields", type: "string", default: "" }, addButtonText: { description: "Text displayed on the add new row button", type: "string", default: "添加" } }, Ke = [ "id", "type" ], et = [], tt = { $schema: Ue, $id: We, title: Ye, description: Qe, type: Xe, properties: Ze, required: Ke, ignore: et }, nt = /* @__PURE__ */ new Map([]); function rt(e, t, n) { return t; } const re = { /** 组件值 */ modelValue: { type: String, default: "" }, /** 待配置参数的描述信息 */ parameterDescriptors: { type: Array, default: [] }, /** 表单上下文数据,用于传递给通用参数编辑器组件 */ formContextData: { type: Object, default: {} }, /** 打开编辑框前回调 */ beforeOpen: { type: Function, default: null }, dialogTitle: { type: String, default: "JSON编辑器" }, keyColumnTitle: { type: String, default: "键" }, valueColumnTitle: { type: String, default: "值" }, operationColumnTitle: { type: String, default: "操作" }, keyColumnPlaceholder: { type: String, default: "" }, valueColumnPlaceholder: { type: String, default: "" }, addButtonText: { type: String, default: "添加" } }, ot = Ge(re, tt, nt, rt); function it(e, t, n) { const l = de(pe, null), { formContextData: b, parameterDescriptors: F, initialize: y, hasDuplicateParameter: P, getNewValue: h } = n; function f(r) { t.emit("change", r), t.emit("update:modelValue", r); } function p() { if (P()) return l == null || l.warning({ message: `配置中存在重复的${e.keyColumnTitle},请修改。`, position: "top-center" }), !1; const r = h(); return f(r), !0; } const i = J({ title: e.dialogTitle, width: 675, height: 500, fitContent: !1, showHeader: !0, showCloseButton: !0, showMaxButton: !1, resizeable: !1, draggable: !0, closedCallback: () => { }, buttons: [ { class: "btn btn-secondary", text: "取消", handle: () => !0 }, { class: "btn btn-primary", text: "确定", handle: () => p() } ] }); function a() { f(""); } function d() { if (y(), typeof e.beforeOpen == "function") { const r = e.beforeOpen(); if (!r) return; r.then((o) => { const s = o == null ? void 0 : o.formContextData; b.value = s || b.value || {}; const v = o == null ? void 0 : o.parameterDescriptors; F.value = v || F.value || []; }); } } return { modalConfigs: i, beforeOpenModalDialog: d, onClear: a, changeValue: f }; } const at = { /** 下拉选项的数据源 */ options: { type: Array, default: [] }, /** 下拉选项的ID字段 */ idField: { type: String, default: "id" }, /** 下拉选项的值字段 */ valueField: { type: String, default: "id" }, /** 下拉选项的名称字段 */ textField: { type: String, default: "name" }, /** 下拉选项的标题字段 */ titleField: { type: String, default: "name" } }, lt = /* @__PURE__ */ R({ name: "FEditableComboPopupContainer", props: at, emits: ["select", "close"], setup(e, t) { const n = M(() => e.options.length === 0); function l(a) { t.emit("select", a); } function b() { t.emit("close"); } function F(a) { return a[e.idField]; } function y(a) { return a[e.textField]; } function P(a) { return a[e.titleField] || ""; } function h() { return C("div", { class: "fv-editable-combo-list-close", onClick: b }, [C("span", null, [_("关闭")])]); } function f(a) { return C("div", { class: "fv-editable-combo-list-item", key: F(a), title: P(a), onClick: () => l(a) }, [C("span", null, [y(a)])]); } function p() { return e.options.map((a) => f(a)); } function i() { return C("div", { class: "fv-editable-combo-list-placeholder" }, [C("span", null, [_("无选项")])]); } return () => C("div", { class: "fv-editable-combo-list" }, [n.value && i(), p(), h()]); } }), st = { /** 绑定值 */ modelValue: { type: String, default: "" }, /** 下拉选项的数据源 */ options: { type: Array, default: [] }, /** 下拉选项的ID字段 */ idField: { type: String, default: "id" }, /** 下拉选项的值字段 */ valueField: { type: String, default: "id" }, /** 下拉选项的名称字段 */ textField: { type: String, default: "name" }, /** 下拉选项的标题字段 */ titleField: { type: String, default: "name" }, /** 占位符 */ placeholder: { type: String, default: "请选择" }, /** 下拉图标 */ dropDownIcon: { type: String, default: '<span class="f-icon f-icon-arrow-60-down"></span>' }, /** 是否在选中下拉选项后自动应用选项的值到输入框 */ autoApply: { type: Boolean, default: !0 }, /** 是否在输入时自动根据当前值过滤选项 */ filterOnType: { type: Boolean, default: !0 } }, ut = /* @__PURE__ */ R({ name: "FEditableCombo", props: st, emits: ["update:modelValue", "select"], setup(e, t) { const n = k(), l = k(""), b = M(() => Array.isArray(e.options) ? e.options.filter((d) => { if (!d || typeof d != "object") return !1; const r = d[e.valueField] || ""; return typeof r != "string" ? !1 : r.includes(l.value); }) : []), F = M(() => b.value.length > 0); function y(d) { var r, o; d ? (r = n.value) == null || r.showPopup() : (o = n.value) == null || o.hidePopup(); } function P(d) { if (d.code === "Escape") { y(!1); return; } e.filterOnType && (l.value = e.modelValue, F.value ? y(!0) : y(!1)); } function h() { l.value = ""; } function f() { h(), F.value && y(!0); } function p() { h(); } function i(d) { t.emit("update:modelValue", d); } function a(d) { if (t.emit("select", d), e.autoApply) { const r = d[e.valueField]; i(r); } y(!1); } return () => C(fe, { ref: n, modelValue: e.modelValue, "onUpdate:modelValue": i, editable: !0, enableClear: !0, placeholder: e.placeholder, buttonContent: e.dropDownIcon, placement: "auto", popupClass: "fv-editable-combo-popup", onClick: f, onClickButton: p, onKeyup: P }, { default: () => [C(lt, { options: b.value, idField: e.idField, valueField: e.valueField, textField: e.textField, titleField: e.titleField, onSelect: a, onClose: () => y(!1) }, null)] }); } }), ct = { useParametersComposition: { type: Object, require: !0 }, jsonEditorProps: { type: Object, default: {} }, formContextData: { type: Object, default: {} } }, dt = /* @__PURE__ */ R({ name: "FJsonEditorModalContainer", props: ct, emits: [], setup(e) { const { parameterItems: t, parameterCodeOptions: n, appendNewParameter: l, deleteParameterById: b, onParameterCodeChanged: F } = e.useParametersComposition, y = M(() => t.value.length === 0), P = M(() => !y.value); function h() { return C("div", { class: "fv-json-editor-header" }, [C("div", { class: "fv-json-editor-key-col" }, [e.jsonEditorProps.keyColumnTitle]), C("div", { class: "fv-json-editor-value-col" }, [e.jsonEditorProps.valueColumnTitle]), C("div", { class: "fv-json-editor-operation-col" }, [e.jsonEditorProps.operationColumnTitle])]); } function f() { return C("div", { class: "fv-json-editor-placeholder" }, [C("div", { class: "fv-json-editor-default-add-button", onClick: l }, [C("span", { class: "fv-json-editor-default-add-icon f-icon f-icon-add" }, null), C("span", { class: "fv-json-editor-default-add-text" }, [e.jsonEditorProps.addButtonText])])]); } function p(s) { return C(ut, { modelValue: s.code, "onUpdate:modelValue": [(v) => s.code = v, () => F(s.id)], options: n.value, placeholder: e.jsonEditorProps.keyColumnPlaceholder }, null); } function i(s) { var v, T, j; return C(ve, { modelValue: s.value, "onUpdate:modelValue": (x) => s.value = x, editorType: s.editorType, fieldData: (v = e.formContextData) == null ? void 0 : v.fieldData, varData: (T = e.formContextData) == null ? void 0 : T.varData, formData: (j = e.formContextData) == null ? void 0 : j.formData }, null); } function a(s) { return C("div", { class: "fv-json-editor-row" }, [C("div", { class: "fv-json-editor-key-col" }, [p(s)]), C("div", { class: "fv-json-editor-value-col" }, [i(s)]), C("div", { class: "fv-json-editor-operation-col" }, [C("div", { class: "fv-json-editor-delete-button" }, [C("span", { class: "fv-json-editor-delete-icon f-icon f-icon-yxs_delete", onClick: () => b(s.id) }, null)])])]); } function d() { return t.value.map((s) => a(s)); } function r() { return C("div", { class: "fv-json-editor-add-button", onClick: l }, [C("span", { class: "fv-json-editor-add-icon f-icon f-icon-add" }, null), C("span", { class: "fv-json-editor-add-text" }, [e.jsonEditorProps.addButtonText])]); } function o() { return C("div", { class: "fv-json-editor-body" }, [y.value && f(), d(), P.value && r()]); } return () => C("div", { class: "fv-json-editor" }, [h(), o()]); } }); function ft(e) { const t = k([]), n = k([]), l = k(e.parameterDescriptors || []); L( () => e.parameterDescriptors, (u) => { l.value = u; } ); const { guid: b } = be(); function F(u) { if (t.value = [], n.value = [], !h(u)) return; const c = JSON.parse(u); Object.keys(c).forEach((g) => { const S = b(), m = a(g); t.value.push(J({ id: S, code: g, value: f(c[g], S), editorType: m })); }); } L( () => e.modelValue, (u) => F(u) ); function y() { F(e.modelValue); } function P() { const u = {}; return t.value.forEach((g) => { const S = g == null ? void 0 : g.code; S && S.trim().length > 0 && (u[S] = p(g.value, g.id)); }), Object.keys(u).length === 0 ? "" : JSON.stringify(u); } function h(u) { try { const c = JSON.parse(u); if (!c || typeof c != "object" || Array.isArray(c)) return !1; } catch { return !1; } return !0; } function f(u, c) { return typeof u == "object" ? (n.value.push(c), JSON.stringify(u)) : u; } function p(u, c) { if (u && typeof u == "string" && n.value.includes(c)) try { u = JSON.parse(u); } catch { return u; } return u === void 0 ? "" : u; } function i(u) { const c = l.value; return !u || !c ? void 0 : c.find((S) => S.id === u); } function a(u) { const c = i(u); return c == null ? void 0 : c.editorType; } function d(u) { if (!u) return ""; switch (u) { case ge.Switch: return !1; default: return ""; } } function r(u) { const c = i(u); if (!c) return; const { editorType: g, defaultValue: S } = c; return S !== void 0 ? S : d(g); } function o() { const u = /* @__PURE__ */ new Set(); for (const c of t.value) { const g = c == null ? void 0 : c.code; if (!(!g || g.trim().length === 0)) { if (u.has(g)) return !0; u.add(g); } } return !1; } function s(u) { const c = t.value.find((O) => O.id === u); if (!c) return; const g = c.code; if (!g) return; const S = a(g); c.editorType = S || void 0; let m = r(g); m = f(m, u), c.value = m; } function v(u) { const c = t.value.findIndex((g) => g.id === u); c >= 0 && t.value.splice(c, 1); } function T() { t.value.push(J({ id: b(), code: "", value: "", editorType: void 0 })); } const j = M(() => l.value.map((u) => { let c = u.label; return u.description && (c += `(${u.description})`), { id: u.id, name: c }; })), x = k(e.formContextData); return { parameterItems: t, parameterCodeOptions: j, formContextData: x, parameterDescriptors: l, initialize: y, onParameterCodeChanged: s, hasDuplicateParameter: o, deleteParameterById: v, appendNewParameter: T, getNewValue: P }; } const z = /* @__PURE__ */ R({ name: "FJsonEditor", props: re, emits: ["change", "update:modelValue"], setup(e, t) { const n = ft(e), { modalConfigs: l, onClear: b, beforeOpenModalDialog: F, changeValue: y } = it(e, t, n), { formContextData: P } = n; return () => C(me, { modelValue: e.modelValue, enableClear: !0, buttonBehavior: "Modal", modalOptions: l, beforeOpen: F, onClear: b, "onUpdate:modelValue": y }, { default: () => [C(dt, { useParametersComposition: n, jsonEditorProps: e, formContextData: P.value }, null)] }); } }); z.register = (e, t, n, l) => { e["json-editor"] = z, t["json-editor"] = ot; }; const jt = ye(z); export { z as FJsonEditor, jt as default, re as jsonEditorProps, ot as propsResolver };