UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

730 lines (729 loc) 25.1 kB
var Y = Object.defineProperty; var Z = (n, e, t) => e in n ? Y(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var P = (n, e, t) => Z(n, typeof e != "symbol" ? e + "" : e, t); import { defineComponent as N, onBeforeMount as R, onMounted as F, createVNode as q, ref as E, inject as O, computed as I } from "vue"; import { isPlainObject as j, cloneDeep as B } from "lodash-es"; import { getCustomClass as K } from "../common/index.esm.js"; const _ = {}, W = {}; function $(n) { const { properties: e, title: t, ignore: o } = n, a = o && Array.isArray(o), c = Object.keys(e).reduce((r, f) => ((!a || !o.find((m) => m === f)) && (r[f] = e[f].type === "object" && e[f].properties ? $(e[f]) : B(e[f].default)), r), {}); if (t && (!a || !o.find((r) => r === "id"))) { const r = t.toLowerCase().replace(/-/g, "_"); c.id = `${r}_${Math.random().toString().slice(2, 6)}`; } return c; } function H(n) { const { properties: e, title: t, required: o } = n; if (o && Array.isArray(o)) { const a = o.reduce((c, r) => (c[r] = e[r].type === "object" && e[r].properties ? $(e[r]) : B(e[r].default), c), {}); if (t && o.find((c) => c === "id")) { const c = t.toLowerCase().replace(/-/g, "_"); a.id = `${c}_${Math.random().toString().slice(2, 6)}`; } return a; } return { type: t }; } function G(n, e = {}, t) { const o = _[n]; if (o) { let a = H(o); const c = W[n]; return a = c ? c({ getSchemaByType: G }, a, e, t) : a, a; } return null; } function x(n, e) { const t = $(e); return Object.keys(t).reduce((o, a) => (Object.prototype.hasOwnProperty.call(n, a) && (o[a] && j(o[a]) && j(n[a] || !n[a]) ? Object.assign(o[a], n[a] || {}) : o[a] = n[a]), o), t), t; } function z(n, e) { return Object.keys(n).filter((o) => n[o] != null).reduce((o, a) => { if (e.has(a)) { const c = e.get(a); if (typeof c == "string") o[c] = n[a]; else { const r = c(a, n[a], n); Object.assign(o, r); } } else o[a] = n[a]; return o; }, {}); } function ee(n, e, t = /* @__PURE__ */ new Map()) { const o = x(n, e); return z(o, t); } function te(n = {}) { function e(i, s, l, u) { if (typeof l == "number") return u[i].length === l; if (typeof l == "object") { const d = Object.keys(l)[0], w = l[d]; if (d === "not") return Number(u[i].length) !== Number(w); if (d === "moreThan") return Number(u[i].length) >= Number(w); if (d === "lessThan") return Number(u[i].length) <= Number(w); } return !1; } function t(i, s, l, u) { return u[i] && u[i].propertyValue && String(u[i].propertyValue.value) === String(l); } const o = /* @__PURE__ */ new Map([ ["length", e], ["getProperty", t] ]); Object.keys(n).reduce((i, s) => (i.set(s, n[s]), i), o); function a(i, s) { const l = i; return typeof s == "number" ? [{ target: l, operator: "length", param: null, value: Number(s) }] : typeof s == "boolean" ? [{ target: l, operator: "getProperty", param: i, value: !!s }] : typeof s == "object" ? Object.keys(s).map((u) => { if (u === "length") return { target: l, operator: "length", param: null, value: s[u] }; const d = u, w = s[u]; return { target: l, operator: "getProperty", param: d, value: w }; }) : []; } function c(i) { return Object.keys(i).reduce((l, u) => { const d = a(u, i[u]); return l.push(...d), l; }, []); } function r(i, s) { if (o.has(i.operator)) { const l = o.get(i.operator); return l && l(i.target, i.param, i.value, s) || !1; } return !1; } function f(i, s) { return c(i).reduce((d, w) => d && r(w, s), !0); } function m(i, s) { const l = Object.keys(i), u = l.includes("allOf"), d = l.includes("anyOf"), w = u || d, C = (w ? i[w ? u ? "allOf" : "anyOf" : "allOf"] : [i]).map((V) => f(V, s)); return u ? !C.includes(!1) : C.includes(!0); } return { parseValueSchema: m }; } const ne = { 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: "标签页工具栏按钮" }, "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: "抽屉" } }, oe = {}, re = {}; te(); function J(n, e, t = /* @__PURE__ */ new Map(), o = (r, f, m, i) => f, a = {}, c = (r) => r) { return _[e.title] = e, W[e.title] = o, oe[e.title] = a, re[e.title] = c, (r = {}, f = !0) => { if (!f) return z(r, t); const m = ee(r, e, t), i = Object.keys(n).reduce((s, l) => (s[l] = n[l].default, s), {}); return Object.assign(i, m); }; } function ae(n, e) { return { customClass: e.class, customStyle: e.style }; } const Q = /* @__PURE__ */ new Map([ ["appearance", ae] ]), ce = "https://json-schema.org/draft/2020-12/schema", ie = "https://farris-design.gitee.io/component.schema.json", se = "component", le = "A Farris Visual Component", pe = "object", ue = { id: { description: "The unique identifier for a component", type: "string" }, type: { description: "The type string of component", type: "string", default: "component" }, componentType: { description: "The type string of component", type: "string" }, viewModel: { description: "The viewModel string of component", type: "string" }, appearance: { description: "", type: "object", properties: { class: { type: "string" }, style: { type: "string" } }, default: {} }, contents: { description: "", type: "array", default: [] }, visible: { description: "", type: "boolean", default: !0 }, onInit: { description: "初始化事件", type: "string", default: "" }, onAfterViewInit: { description: "视图初始化后事件", type: "string", default: "" } }, fe = [ "id", "type", "contents" ], me = { $schema: ce, $id: ie, title: se, description: le, type: pe, properties: ue, required: fe }; function X(n, e, t) { return e; } const A = { id: { type: String }, customClass: { type: String, default: "" }, customStyle: { type: String, default: "" }, componentType: { type: String, default: "" }, formColumns: { type: Number, default: 4 } }, S = J(A, me, Q, X), Ne = Object.assign({}, A, { componentId: { type: String, default: "" } }), U = /* @__PURE__ */ N({ name: "FComponent", props: A, emits: ["init", "afterViewInit"], setup(n, e) { return R(() => { e.emit("init", n.id); }), F(() => { e.emit("afterViewInit", n.id); }), () => q("div", { class: n.customClass }, [e.slots.default && e.slots.default()]); } }); function de(n, e, t) { var L; const o = t && t.getStyles && t.getStyles() || "", a = t && t.getDesignerClass && t.getDesignerClass() || "", c = E(); function r() { return (e == null ? void 0 : e.schema.componentType) === "frame" ? !1 : t && t.checkCanMoveComponent ? t.checkCanMoveComponent() : !0; } function f() { return !1; } function m() { return (e == null ? void 0 : e.schema.componentType) === "frame" ? !1 : t && t.checkCanDeleteComponent ? t.checkCanDeleteComponent() : !0; } function i() { return (e == null ? void 0 : e.schema.componentType) === "frame" ? !0 : t && t.hideNestedPaddingInDesginerView ? t.hideNestedPaddingInDesginerView() : !1; } function s(p) { if (!p || !p.value) return null; if (p.value.schema && p.value.schema.type === "component") return p.value; const y = E(p == null ? void 0 : p.value.parent), v = s(y); return v || null; } function l(p = e) { var D; if (t != null && t.getDraggableDesignItemElement) return t.getDraggableDesignItemElement(p); const { componentInstance: y, designerItemElementRef: v } = p; if (!y || !y.value) return null; const { getCustomButtons: h } = y.value; return y.value.canMove || h && ((D = h()) != null && D.length) ? v : l(p.parent); } function u(p) { return !!t && t.canAccepts(p); } function d() { return (e == null ? void 0 : e.schema.label) || (e == null ? void 0 : e.schema.title) || (e == null ? void 0 : e.schema.name); } function w() { } function b(p, y) { var v; !p || !y || (t != null && t.onAcceptMovedChildElement && t.onAcceptMovedChildElement(p, y), (v = e == null ? void 0 : e.setupContext) == null || v.emit("dragEnd")); } function g(p, y) { const { componentType: v } = p; let h = G(v, p, y); t && t.onResolveNewComponentSchema && (h = t.onResolveNewComponentSchema(p, h)); const D = v.toLowerCase().replace(/-/g, "_"); return h && !h.id && h.type === v && (h.id = `${D}_${Math.random().toString().slice(2, 6)}`), h; } function C(p) { p && t != null && t.onChildElementMovedOut && t.onChildElementMovedOut(p); } function M(...p) { if (t && t.getPropsConfig) return t.getPropsConfig(...p); } function V() { t && t.onRemoveComponent && t.onRemoveComponent(), e != null && e.schema.contents && e.schema.contents.map((p) => { let y = p.id; p.type === "component-ref" && (y = p.component); const v = n.value.querySelectorAll(`#${y}-design-item`); v != null && v.length && Array.from(v).map((h) => { var D; (D = h == null ? void 0 : h.componentInstance) != null && D.value.onRemoveComponent && h.componentInstance.value.onRemoveComponent(); }); }); } function T() { if (t && t.getCustomButtons) return t.getCustomButtons(); } function k(p) { if (t && t.onPropertyChanged) return t.onPropertyChanged(p); } return c.value = { canMove: r(), canSelectParent: f(), canDelete: m(), canNested: !i(), contents: e == null ? void 0 : e.schema.contents, elementRef: n, parent: (L = e == null ? void 0 : e.parent) == null ? void 0 : L.componentInstance, schema: e == null ? void 0 : e.schema, styles: o, designerClass: a, canAccepts: u, getBelongedComponentInstance: s, getDraggableDesignItemElement: l, getDraggingDisplayText: d, getPropConfig: M, getDragScopeElement: w, onAcceptMovedChildElement: b, onChildElementMovedOut: C, addNewChildComponentSchema: g, triggerBelongedComponentToMoveWhenMoved: !!t && t.triggerBelongedComponentToMoveWhenMoved || E(!1), triggerBelongedComponentToDeleteWhenDeleted: !!t && t.triggerBelongedComponentToDeleteWhenDeleted || E(!1), onRemoveComponent: V, getCustomButtons: T, onPropertyChanged: k }, c; } class he { getTemplateRule(e, t) { const o = t == null ? void 0 : t.formSchemaUtils, a = o == null ? void 0 : o.getFormTemplateRule(), c = { canAccept: !0, canDelete: !0, canMove: !0 }; if (!a) return c; const r = this.getComponentContext(e), { componentClassList: f } = r; return f.forEach((m) => { if (!m || !a[m]) return; const { canMove: i, canDelete: s, canAccept: l } = a[m]; c.canMove = c.canMove && this.resolveRuleValue(i, r), c.canDelete = c.canDelete && this.resolveRuleValue(s, r), c.canAccept = c.canAccept && this.resolveRuleValue(l, r); }), c; } resolveRuleValue(e, t) { return typeof e == "boolean" ? e : this.parseRuleValueSchema(e, t); } parseRuleValueSchema(e, t) { const o = e.invalidContext || []; let a = !0; for (const c of o) { if (c.firstLevelChild) { if (c.firstLevelChild.class) { const { firstLevelChildClassList: r } = t; if (r && !r.includes(c.firstLevelChild.class)) { a = !1; continue; } } if (c.firstLevelChild.type) { const { firstLevelChildSchema: r } = t; if (!r || r.type !== c.firstLevelChild.type) { a = !1; continue; } } } if (c.secondLevelChild) { if (c.secondLevelChild.class) { const { secondLevelChildClassList: r } = t; if (r && !r.includes(c.secondLevelChild.class)) { a = !1; continue; } } if (c.secondLevelChild.type) { const { secondLevelChildSchema: r } = t; if (!r || r.type !== c.secondLevelChild.type) { a = !1; continue; } } } if (c.parent) { if (c.parent.class) { const { parentClassList: r } = t; if (r && !r.includes(c.parent.class)) { a = !1; continue; } } if (c.parent.type) { const { parentSchema: r } = t; if (r && r.type !== c.parent.type) { a = !1; continue; } } } a = !0; break; } return !a; } getComponentContext(e) { var b, g, C, M; const t = e.schema, o = t.appearance && t.appearance.class || "", a = o.split(" ") || [], c = t.contents || [], r = c.length ? c[0] : null, f = r && r.appearance ? r.appearance.class : "", m = f ? f.split(" ") : [], i = (b = r == null ? void 0 : r.contents) != null && b.length ? r == null ? void 0 : r.contents[0] : null, s = i && i.appearance ? i.appearance.class : "", l = s ? s.split(" ") : [], u = t.type === "component" ? (C = (g = e.parent) == null ? void 0 : g.parent) == null ? void 0 : C.schema : (M = e.parent) == null ? void 0 : M.schema, d = u && u.appearance && u.appearance.class || "", w = d ? d.split(" ") : []; return { componentClass: o, componentClassList: a, childContents: c, firstLevelChildSchema: r, firstLevelChildClass: f, firstLevelChildClassList: m, secondLevelChildSchema: i, secondLevelChildClass: s, secondLevelChildClassList: l, parentSchema: u, parentClass: d, parentClassList: w }; } } const ye = E(0); function ve() { ye.value++; } const ge = E(0); class be { constructor(e, t) { P(this, "componentId"); P(this, "viewModelId"); P(this, "eventsEditorUtils"); P(this, "formSchemaUtils"); P(this, "formMetadataConverter"); P(this, "designViewModelUtils"); P(this, "designViewModelField"); P(this, "controlCreatorUtils"); P(this, "designerHostService"); P(this, "schemaService", null); P(this, "metadataService", null); P(this, "propertyConfig", { type: "object", categories: {} }); var o; this.componentId = e, this.designerHostService = t, this.eventsEditorUtils = t.eventsEditorUtils, this.formSchemaUtils = t.formSchemaUtils, this.formMetadataConverter = t.formMetadataConverter, this.viewModelId = ((o = this.formSchemaUtils) == null ? void 0 : o.getViewModelIdByComponentId(e)) || "", this.designViewModelUtils = t.designViewModelUtils, this.controlCreatorUtils = t.controlCreatorUtils, this.metadataService = t.metadataService, this.schemaService = t.schemaService; } getTableInfo() { var e; return (e = this.schemaService) == null ? void 0 : e.getTableInfoByViewModelId(this.viewModelId); } setDesignViewModelField(e) { var o; const t = e.binding && e.binding.type === "Form" && e.binding.field; if (t) { if (!this.designViewModelField) { const a = this.designViewModelUtils.getDgViewModel(this.viewModelId); this.designViewModelField = a.fields.find((c) => c.id === t); } e.updateOn = (o = this.designViewModelField) == null ? void 0 : o.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", editable: !1, data: [{ value: e.type, name: ne[e.type].name }] } } } }; } getAppearanceConfig(e = null) { return { title: "外观", description: "Appearance", properties: { class: { title: "class样式", type: "string", description: "组件的CSS样式", $converter: "/converter/appearance.converter" }, style: { title: "style样式", type: "string", description: "组件的样式", $converter: "/converter/appearance.converter" } }, setPropertyRelates(t, o) { if (t) switch (t && t.propertyID) { case "class": case "style": { ge.value++; break; } } } }; } /** * * @param propertyId * @param componentInstance * @returns */ updateElementByParentContainer(e, t) { const o = t && t.parent && t.parent.schema; if (!o) return; const a = o.contents.findIndex((r) => r.id === e), c = B(o.contents[a]); o.contents.splice(a, 1), o.contents.splice(a, 0, c), ve(); } } class Me extends be { constructor(e, t) { super(e, t); } getPropertyConfig(e) { return this.propertyConfig.categories.basic = this.getBasicPropConfig(e), this.propertyConfig.categories.appearance = this.getAppearanceConfig(e), this.getEventPropConfig(e), this.propertyConfig; } getEventPropConfig(e) { const t = [ { label: "onInit", name: "初始化事件" }, { label: "onAfterViewInit", name: "视图初始化后事件" } ], o = this, a = o.eventsEditorUtils.formProperties(e, o.viewModelId, t), c = {}; c[o.viewModelId] = { type: "events-editor", editor: { initialData: a } }, this.propertyConfig.categories.eventsEditor = { title: "事件", hideTitle: !0, properties: c, // 这个属性,标记当属性变更得时候触发重新更新属性 refreshPanelAfterChanged: !0, tabId: "commands", tabName: "交互", setPropertyRelates(r, f) { const m = r.propertyValue; delete e[o.viewModelId], m && (m.setPropertyRelates = this.setPropertyRelates, o.eventsEditorUtils.saveRelatedParameters(e, o.viewModelId, m.events, m)); } }; } } function we(n, e) { const t = new he(), { canMove: o, canDelete: a } = t.getTemplateRule(n, e); function c() { return !1; } function r() { return a; } function f() { return o; } function m() { return !1; } function i() { return " display: inherit;flex-direction: inherit;margin-bottom:10px"; } function s(b) { const g = new Me(b, e), { schema: C } = n; return g.getPropertyConfig(C); } function l() { var V, T, k, L; const b = n == null ? void 0 : n.schema, C = (e == null ? void 0 : e.formSchemaUtils).getViewModelIdByComponentId(b.id); if (b.componentType !== "data-grid" && b.componentType !== "form" || !((V = n.componentInstance) != null && V.value.parent)) return; const M = (T = n.componentInstance) == null ? void 0 : T.value.parent.schema; if ((k = M == null ? void 0 : M.toolbar) != null && k.buttons && M.toolbar.buttons.length) { M.toolbar.buttons.forEach((y) => { const v = y.onClick, h = v && v.split("."); if (!h || h.length < 3) return; h[h.length - 2] === C && (y.needRemove = !0); }), M.toolbar.buttons = M.toolbar.buttons.filter((y) => !y.needRemove); const p = (L = n.componentInstance) == null ? void 0 : L.value.parent; p.parent && p.parent.updateToolbarItems && p.parent.updateToolbarItems(); } } function u() { const b = e == null ? void 0 : e.designViewModelUtils, g = e == null ? void 0 : e.formSchemaUtils, C = n == null ? void 0 : n.schema; if (b && g) { const M = g.getViewModelIdByComponentId(C.id); b.deleteViewModelById(M), g.deleteComponent(C.id); } } function d() { const b = e == null ? void 0 : e.designViewModelUtils, g = e == null ? void 0 : e.formSchemaUtils, C = n == null ? void 0 : n.schema, M = g.getViewModelIdByComponentId(C.id); b.getDgViewModel(M).fields.forEach((V) => { if (g.getExpressions() && g.getExpressions().length) { const T = g.getExpressions().findIndex((k) => k.fieldId === V.id); T > -1 && g.getExpressions().splice(T, 1); } }); } function w() { l(), d(), u(); } return { canAccepts: c, checkCanDeleteComponent: r, checkCanMoveComponent: f, hideNestedPaddingInDesginerView: m, getStyles: i, getPropsConfig: s, onRemoveComponent: w }; } const Ce = /* @__PURE__ */ N({ name: "FComponetDesign", props: A, emits: ["init", "afterViewInit"], setup(n, e) { const t = E(), o = O("designer-host-service"), a = O("design-item-context"), c = we(a, o), r = de(t, a, c), f = I(() => K({ "drag-container": !0 }, n == null ? void 0 : n.customClass)); return F(() => { var m, i, s, l; t.value.componentInstance = r, ((i = (m = a.parent) == null ? void 0 : m.schema) == null ? void 0 : i.type) === "component-ref" && (r.value.parent = (l = (s = a.parent) == null ? void 0 : s.parent) == null ? void 0 : l.componentInstance); }), e.expose(r.value), () => q("div", { ref: t, class: f.value, style: n.customStyle, "data-dragref": `${a.schema.id}-container` }, [e.slots.default && e.slots.default()]); } }), Pe = "https://json-schema.org/draft/2020-12/schema", Ve = "https://farris-design.gitee.io/component.schema.json", De = "component-ref", Te = "A Farris Visual Component", Ee = "object", ke = { id: { description: "The unique identifier for a Section", type: "string" }, type: { description: "The type string of Section component", type: "string", default: "component-ref" }, component: { description: "", type: "string", default: "" } }, Le = [ "id", "type", "component" ], Ae = { $schema: Pe, $id: Ve, title: De, description: Te, type: Ee, properties: ke, required: Le }, Ue = { id: { type: String }, component: { type: String, default: "" } }, Be = J(Ue, Ae, Q, X), Fe = { install(n) { n.component(U.name, U); }, register(n, e, t, o) { n.component = U, e.component = S; }, registerDesigner(n, e) { n.component = Ce, e.component = S, e["component-ref"] = Be; } }; export { U as Component, Ce as ComponentDesign, Ne as componentDesignProps, A as componentProps, Fe as default, S as propsResolver };