UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

421 lines (420 loc) 11.7 kB
import { defineComponent as N, createVNode as D, ref as k, inject as G, onMounted as J } from "vue"; import { isPlainObject as E, cloneDeep as q } from "lodash-es"; const F = {}, V = {}; function M(r) { const { properties: e, title: s, ignore: t } = r, o = t && Array.isArray(t), l = Object.keys(e).reduce((u, y) => ((!o || !t.find((b) => b === y)) && (u[y] = e[y].type === "object" && e[y].properties ? M(e[y]) : q(e[y].default)), u), {}); if (s && (!o || !t.find((u) => u === "id"))) { const u = s.toLowerCase().replace(/-/g, "_"); l.id = `${u}_${Math.random().toString().slice(2, 6)}`; } return l; } function Q(r) { const { properties: e, title: s, required: t } = r; if (t && Array.isArray(t)) { const o = t.reduce((l, u) => (l[u] = e[u].type === "object" && e[u].properties ? M(e[u]) : q(e[u].default), l), {}); if (s && t.find((l) => l === "id")) { const l = s.toLowerCase().replace(/-/g, "_"); o.id = `${l}_${Math.random().toString().slice(2, 6)}`; } return o; } return { type: s }; } function _(r, e = {}, s) { const t = F[r]; if (t) { let o = Q(t); const l = V[r]; return o = l ? l({ getSchemaByType: _ }, o, e, s) : o, o; } return null; } function X(r, e) { const s = M(e); return Object.keys(s).reduce((t, o) => (Object.prototype.hasOwnProperty.call(r, o) && (t[o] && E(t[o]) && E(r[o] || !r[o]) ? Object.assign(t[o], r[o] || {}) : t[o] = r[o]), t), s), s; } function L(r, e) { return Object.keys(r).filter((t) => r[t] != null).reduce((t, o) => { if (e.has(o)) { const l = e.get(o); if (typeof l == "string") t[l] = r[o]; else { const u = l(o, r[o], r); Object.assign(t, u); } } else t[o] = r[o]; return t; }, {}); } function Y(r, e, s = /* @__PURE__ */ new Map()) { const t = X(r, e); return L(t, s); } function Z(r = {}) { function e(n, a, c, p) { if (typeof c == "number") return p[n].length === c; if (typeof c == "object") { const h = Object.keys(c)[0], g = c[h]; if (h === "not") return Number(p[n].length) !== Number(g); if (h === "moreThan") return Number(p[n].length) >= Number(g); if (h === "lessThan") return Number(p[n].length) <= Number(g); } return !1; } function s(n, a, c, p) { return p[n] && p[n].propertyValue && String(p[n].propertyValue.value) === String(c); } const t = /* @__PURE__ */ new Map([ ["length", e], ["getProperty", s] ]); Object.keys(r).reduce((n, a) => (n.set(a, r[a]), n), t); function o(n, a) { const c = n; return typeof a == "number" ? [{ target: c, operator: "length", param: null, value: Number(a) }] : typeof a == "boolean" ? [{ target: c, operator: "getProperty", param: n, value: !!a }] : typeof a == "object" ? Object.keys(a).map((p) => { if (p === "length") return { target: c, operator: "length", param: null, value: a[p] }; const h = p, g = a[p]; return { target: c, operator: "getProperty", param: h, value: g }; }) : []; } function l(n) { return Object.keys(n).reduce((c, p) => { const h = o(p, n[p]); return c.push(...h), c; }, []); } function u(n, a) { if (t.has(n.operator)) { const c = t.get(n.operator); return c && c(n.target, n.param, n.value, a) || !1; } return !1; } function y(n, a) { return l(n).reduce((h, g) => h && u(g, a), !0); } function b(n, a) { const c = Object.keys(n), p = c.includes("allOf"), h = c.includes("anyOf"), g = p || h, P = (g ? n[g ? p ? "allOf" : "anyOf" : "allOf"] : [n]).map((T) => y(T, a)); return p ? !P.includes(!1) : P.includes(!0); } return { parseValueSchema: b }; } const H = {}, K = {}; Z(); function C(r, e, s = /* @__PURE__ */ new Map(), t = (u, y, b, n) => y, o = {}, l = (u) => u) { return F[e.title] = e, V[e.title] = t, H[e.title] = o, K[e.title] = l, (u = {}, y = !0) => { if (!y) return L(u, s); const b = Y(u, e, s), n = Object.keys(r).reduce((a, c) => (a[c] = r[c].default, a), {}); return Object.assign(n, b); }; } function x(r, e) { return { customClass: e.class, customStyle: e.style }; } const I = /* @__PURE__ */ new Map([ ["appearance", x] ]); function ee(r, e, s) { return e; } const re = "https://json-schema.org/draft/2020-12/schema", te = "https://farris-design.gitee.io/smoke-detector.schema.json", oe = "smoke-detector", ne = "A Farris Component", se = "object", ce = { id: { description: "The unique identifier for smoke-detector", type: "string" }, type: { description: "The type string of smoke-detector", type: "string", default: "smoke-detector" }, voltageA: { description: "A相电压", type: "number", default: -1 }, voltageB: { description: "B相电压", type: "number", default: -1 }, voltageC: { description: "C相电压", type: "number", default: -1 }, forwardActiveTotalPower: { description: "正向有功总电量", type: "number", default: -1 }, totalPositiveReactivePower: { description: "正向无功总电量", type: "number", default: -1 }, reverseTotalActivePower: { description: "反向有功总电量", type: "number", default: -1 }, reverseTotalReactivePower: { description: "反向无功总电量", type: "number", default: -1 }, toDeliverData: { description: "下发数据", type: "string" } }, ie = [ "id", "type" ], ae = { $schema: re, $id: te, title: oe, description: ne, type: se, properties: ce, required: ie }, ue = "smoke-detector", le = "A Farris Component", pe = "object", fe = { basic: { description: "Basic Infomation", title: "基本信息", properties: { id: { description: "组件标识", title: "标识", type: "string", readonly: !0 }, type: { description: "组件类型", title: "控件类型", type: "select", editor: { type: "waiting for modification", enum: [] } } } }, bussinessProperties: { description: "", title: "业务属性", properties: { voltageA: { description: "A相电压", type: "number", title: "A相电压", default: -1 }, voltageB: { description: "B相电压", type: "number", title: "B相电压", default: -1 }, voltageC: { description: "C相电压", type: "number", title: "C相电压", default: -1 }, forwardActiveTotalPower: { description: "正向有功总电量", type: "number", title: "正向有功总电量", default: -1 }, totalPositiveReactivePower: { description: "正向无功总电量", type: "number", title: "正向无功总电量", default: -1 }, reverseTotalActivePower: { description: "反向有功总电量", type: "number", title: "反向有功总电量", default: -1 }, reverseTotalReactivePower: { description: "反向无功总电量", type: "number", title: "反向无功总电量", default: -1 }, toDeliverData: { description: "下发数据", type: "string", title: "下发数据" } } } }, me = { title: ue, description: le, type: pe, categories: fe }, R = {}, $ = C(R, ae, I, ee, me), A = /* @__PURE__ */ N({ name: "FSmokeDetector", props: R, emits: [""], setup(r) { return () => D("div", { class: "f-smoke-detector" }, [D("img", { title: "smoke-detector", src: "./image/smoke-detector-2.png" }, null)]); } }); function de(r, e, s) { var B; const t = "", o = "", l = k(); function u() { return (e == null ? void 0 : e.schema.componentType) !== "frame"; } function y() { return !1; } function b() { return (e == null ? void 0 : e.schema.componentType) !== "frame"; } function n() { return (e == null ? void 0 : e.schema.componentType) === "frame"; } function a(i) { if (!i || !i.value) return null; if (i.value.schema && i.value.schema.type === "component") return i.value; const m = k(i == null ? void 0 : i.value.parent), f = a(m); return f || null; } function c(i = e) { var v; const { componentInstance: m, designerItemElementRef: f } = i; if (!m || !m.value) return null; const { getCustomButtons: d } = m.value; return m.value.canMove || d && ((v = d()) != null && v.length) ? f : c(i.parent); } function p(i) { return !!s; } function h() { return (e == null ? void 0 : e.schema.label) || (e == null ? void 0 : e.schema.title) || (e == null ? void 0 : e.schema.name); } function g() { } function w(i, m) { var f; !i || !m || (f = e == null ? void 0 : e.setupContext) == null || f.emit("dragEnd"); } function S(i, m) { const { componentType: f } = i; let d = _(f, i, m); const v = f.toLowerCase().replace(/-/g, "_"); return d && !d.id && d.type === f && (d.id = `${v}_${Math.random().toString().slice(2, 6)}`), d; } function P(i) { } function O(...i) { } function T(i) { if (!i) return; const m = e == null ? void 0 : e.schema, { formSchemaUtils: f } = i; if (m && f.getExpressions().length) { const d = f.getExpressions().findIndex((v) => v.target === m.id); d > -1 && f.getExpressions().splice(d, 1); } } function W(i) { T(i), e != null && e.schema.contents && e.schema.contents.map((m) => { let f = m.id; m.type === "component-ref" && (f = m.component); const d = r.value.querySelectorAll(`#${f}-design-item`); d != null && d.length && Array.from(d).map((v) => { var j; (j = v == null ? void 0 : v.componentInstance) != null && j.value.onRemoveComponent && v.componentInstance.value.onRemoveComponent(i); }); }); } function U() { } function z(i) { } return l.value = { canMove: u(), canSelectParent: y(), canDelete: b(), canNested: !n(), contents: e == null ? void 0 : e.schema.contents, elementRef: r, parent: (B = e == null ? void 0 : e.parent) == null ? void 0 : B.componentInstance, schema: e == null ? void 0 : e.schema, styles: t, designerClass: o, canAccepts: p, getBelongedComponentInstance: a, getDraggableDesignItemElement: c, getDraggingDisplayText: h, getPropConfig: O, getDragScopeElement: g, onAcceptMovedChildElement: w, onChildElementMovedOut: P, addNewChildComponentSchema: S, triggerBelongedComponentToMoveWhenMoved: k(!1), triggerBelongedComponentToDeleteWhenDeleted: k(!1), onRemoveComponent: W, getCustomButtons: U, onPropertyChanged: z }, l; } const ye = /* @__PURE__ */ N({ name: "FSmokeDetectorDesign", props: R, emits: [""], setup(r, e) { const s = k(), t = G("design-item-context"), o = de(s, t); return J(() => { s.value.componentInstance = o; }), e.expose(o.value), () => D("div", { ref: s, class: "f-smoke-detector" }, [D("img", { title: "smoke-detector", src: "../image/smoke-detector-2.png" }, null)]); } }), ve = { install(r) { r.component(A.name, A); }, register(r, e, s, t) { r["smoke-detector"] = A, e["smoke-detector"] = $; }, registerDesigner(r, e, s) { r["smoke-detector"] = ye, e["smoke-detector"] = $; } }; export { A as SmokeDetector, ve as default, $ as propsResolver, R as smokeDetectorProps };