@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
412 lines (411 loc) • 11.4 kB
JavaScript
import { defineComponent as N, createVNode as D, ref as k, inject as H, onMounted as z } from "vue";
import { isPlainObject as j, cloneDeep as E } from "lodash-es";
const q = {}, F = {};
function T(r) {
const { properties: e, title: c, ignore: t } = r, o = t && Array.isArray(t), l = Object.keys(e).reduce((u, m) => ((!o || !t.find((v) => v === m)) && (u[m] = e[m].type === "object" && e[m].properties ? T(e[m]) : E(e[m].default)), u), {});
if (c && (!o || !t.find((u) => u === "id"))) {
const u = c.toLowerCase().replace(/-/g, "_");
l.id = `${u}_${Math.random().toString().slice(2, 6)}`;
}
return l;
}
function G(r) {
const { properties: e, title: c, required: t } = r;
if (t && Array.isArray(t)) {
const o = t.reduce((l, u) => (l[u] = e[u].type === "object" && e[u].properties ? T(e[u]) : E(e[u].default), l), {});
if (c && t.find((l) => l === "id")) {
const l = c.toLowerCase().replace(/-/g, "_");
o.id = `${l}_${Math.random().toString().slice(2, 6)}`;
}
return o;
}
return {
type: c
};
}
function V(r, e = {}, c) {
const t = q[r];
if (t) {
let o = G(t);
const l = F[r];
return o = l ? l({ getSchemaByType: V }, o, e, c) : o, o;
}
return null;
}
function J(r, e) {
const c = T(e);
return Object.keys(c).reduce((t, o) => (Object.prototype.hasOwnProperty.call(r, o) && (t[o] && j(t[o]) && j(r[o] || !r[o]) ? Object.assign(t[o], r[o] || {}) : t[o] = r[o]), t), c), c;
}
function _(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 Q(r, e, c = /* @__PURE__ */ new Map()) {
const t = J(r, e);
return _(t, c);
}
function U(r = {}) {
function e(n, i, s, p) {
if (typeof s == "number")
return p[n].length === s;
if (typeof s == "object") {
const d = Object.keys(s)[0], h = s[d];
if (d === "not")
return Number(p[n].length) !== Number(h);
if (d === "moreThan")
return Number(p[n].length) >= Number(h);
if (d === "lessThan")
return Number(p[n].length) <= Number(h);
}
return !1;
}
function c(n, i, s, p) {
return p[n] && p[n].propertyValue && String(p[n].propertyValue.value) === String(s);
}
const t = /* @__PURE__ */ new Map([
["length", e],
["getProperty", c]
]);
Object.keys(r).reduce((n, i) => (n.set(i, r[i]), n), t);
function o(n, i) {
const s = n;
return typeof i == "number" ? [{ target: s, operator: "length", param: null, value: Number(i) }] : typeof i == "boolean" ? [{ target: s, operator: "getProperty", param: n, value: !!i }] : typeof i == "object" ? Object.keys(i).map((p) => {
if (p === "length")
return { target: s, operator: "length", param: null, value: i[p] };
const d = p, h = i[p];
return { target: s, operator: "getProperty", param: d, value: h };
}) : [];
}
function l(n) {
return Object.keys(n).reduce((s, p) => {
const d = o(p, n[p]);
return s.push(...d), s;
}, []);
}
function u(n, i) {
if (t.has(n.operator)) {
const s = t.get(n.operator);
return s && s(n.target, n.param, n.value, i) || !1;
}
return !1;
}
function m(n, i) {
return l(n).reduce((d, h) => d && u(h, i), !0);
}
function v(n, i) {
const s = Object.keys(n), p = s.includes("allOf"), d = s.includes("anyOf"), h = p || d, P = (h ? n[h ? p ? "allOf" : "anyOf" : "allOf"] : [n]).map((A) => m(A, i));
return p ? !P.includes(!1) : P.includes(!0);
}
return { parseValueSchema: v };
}
const X = {}, Y = {};
U();
function Z(r, e, c = /* @__PURE__ */ new Map(), t = (u, m, v, n) => m, o = {}, l = (u) => u) {
return q[e.title] = e, F[e.title] = t, X[e.title] = o, Y[e.title] = l, (u = {}, m = !0) => {
if (!m)
return _(u, c);
const v = Q(u, e, c), n = Object.keys(r).reduce((i, s) => (i[s] = r[s].default, i), {});
return Object.assign(n, v);
};
}
function K(r, e) {
return { customClass: e.class, customStyle: e.style };
}
const C = /* @__PURE__ */ new Map([
["appearance", K]
]);
function x(r, e, c) {
return e;
}
const I = "https://json-schema.org/draft/2020-12/schema", ee = "https://farris-design.gitee.io/smoke-detector.schema.json", re = "smoke-detector", te = "A Farris Component", oe = "object", ne = {
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"
}
}, ce = [
"id",
"type"
], se = {
$schema: I,
$id: ee,
title: re,
description: te,
type: oe,
properties: ne,
required: ce
}, ie = "smoke-detector", ae = "A Farris Component", ue = "object", le = {
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: "下发数据"
}
}
}
}, pe = {
title: ie,
description: ae,
type: ue,
categories: le
}, R = {}, $ = Z(R, se, C, x, pe), M = /* @__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 fe(r, e, c) {
var B;
const t = "", o = "", l = k();
function u() {
return (e == null ? void 0 : e.schema.componentType) !== "frame";
}
function m() {
return !1;
}
function v() {
return (e == null ? void 0 : e.schema.componentType) !== "frame";
}
function n() {
return (e == null ? void 0 : e.schema.componentType) === "frame";
}
function i(a) {
if (!a || !a.value)
return null;
if (a.value.schema && a.value.schema.type === "component")
return a.value;
const y = k(a == null ? void 0 : a.value.parent), f = i(y);
return f || null;
}
function s(a = e) {
var b;
const { componentInstance: y, designerItemElementRef: f } = a;
if (!y || !y.value)
return null;
const { getCustomButtons: g } = y.value;
return y.value.canMove || g && ((b = g()) != null && b.length) ? f : s(a.parent);
}
function p(a) {
return !!c;
}
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 h() {
}
function w(a, y) {
var f;
!a || !y || (f = e == null ? void 0 : e.setupContext) == null || f.emit("dragEnd");
}
function S(a, y) {
const { componentType: f } = a;
let g = V(f, a, y);
const b = f.toLowerCase().replace(/-/g, "_");
return g && !g.id && g.type === f && (g.id = `${b}_${Math.random().toString().slice(2, 6)}`), g;
}
function P(a) {
}
function O(...a) {
}
function A() {
e != null && e.schema.contents && e.schema.contents.map((a) => {
let y = a.id;
a.type === "component-ref" && (y = a.component);
const f = r.value.querySelectorAll(`#${y}-design-item`);
f != null && f.length && Array.from(f).map((g) => {
var b;
(b = g == null ? void 0 : g.componentInstance) != null && b.value.onRemoveComponent && g.componentInstance.value.onRemoveComponent();
});
});
}
function L() {
}
function W(a) {
}
return l.value = {
canMove: u(),
canSelectParent: m(),
canDelete: v(),
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: i,
getDraggableDesignItemElement: s,
getDraggingDisplayText: d,
getPropConfig: O,
getDragScopeElement: h,
onAcceptMovedChildElement: w,
onChildElementMovedOut: P,
addNewChildComponentSchema: S,
triggerBelongedComponentToMoveWhenMoved: k(!1),
triggerBelongedComponentToDeleteWhenDeleted: k(!1),
onRemoveComponent: A,
getCustomButtons: L,
onPropertyChanged: W
}, l;
}
const me = /* @__PURE__ */ N({
name: "FSmokeDetectorDesign",
props: R,
emits: [""],
setup(r, e) {
const c = k(), t = H("design-item-context"), o = fe(c, t);
return z(() => {
c.value.componentInstance = o;
}), e.expose(o.value), () => D("div", {
ref: c,
class: "f-smoke-detector"
}, [D("img", {
title: "smoke-detector",
src: "../image/smoke-detector-2.png"
}, null)]);
}
}), ge = {
install(r) {
r.component(M.name, M);
},
register(r, e, c, t) {
r["smoke-detector"] = M, e["smoke-detector"] = $;
},
registerDesigner(r, e, c) {
r["smoke-detector"] = me, e["smoke-detector"] = $;
}
};
export {
M as SmokeDetector,
ge as default,
$ as propsResolver,
R as smokeDetectorProps
};