@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
275 lines (274 loc) • 7.4 kB
JavaScript
import { defineComponent as j, ref as T, watch as $, createVNode as b, Fragment as C } from "vue";
import { isPlainObject as O, cloneDeep as D } from "lodash-es";
import { withInstall as M } from "../common/index.esm.js";
const P = {}, B = {};
function x(t) {
const { properties: e, title: l, ignore: r } = t, o = r && Array.isArray(r), a = Object.keys(e).reduce((c, p) => ((!o || !r.find((g) => g === p)) && (c[p] = e[p].type === "object" && e[p].properties ? x(e[p]) : D(e[p].default)), c), {});
if (l && (!o || !r.find((c) => c === "id"))) {
const c = l.toLowerCase().replace(/-/g, "_");
a.id = `${c}_${Math.random().toString().slice(2, 6)}`;
}
return a;
}
function N(t, e) {
const l = x(e);
return Object.keys(l).reduce((r, o) => (Object.prototype.hasOwnProperty.call(t, o) && (r[o] && O(r[o]) && O(t[o] || !t[o]) ? Object.assign(r[o], t[o] || {}) : r[o] = t[o]), r), l), l;
}
function v(t, e) {
return Object.keys(t).filter((r) => t[r] != null).reduce((r, o) => {
if (e.has(o)) {
const a = e.get(o);
if (typeof a == "string")
r[a] = t[o];
else {
const c = a(o, t[o], t);
Object.assign(r, c);
}
} else
r[o] = t[o];
return r;
}, {});
}
function V(t, e, l = /* @__PURE__ */ new Map()) {
const r = N(t, e);
return v(r, l);
}
function A(t = {}) {
function e(n, s, i, u) {
if (typeof i == "number")
return u[n].length === i;
if (typeof i == "object") {
const f = Object.keys(i)[0], d = i[f];
if (f === "not")
return Number(u[n].length) !== Number(d);
if (f === "moreThan")
return Number(u[n].length) >= Number(d);
if (f === "lessThan")
return Number(u[n].length) <= Number(d);
}
return !1;
}
function l(n, s, i, u) {
return u[n] && u[n].propertyValue && String(u[n].propertyValue.value) === String(i);
}
const r = /* @__PURE__ */ new Map([
["length", e],
["getProperty", l]
]);
Object.keys(t).reduce((n, s) => (n.set(s, t[s]), n), r);
function o(n, s) {
const i = n;
return typeof s == "number" ? [{ target: i, operator: "length", param: null, value: Number(s) }] : typeof s == "boolean" ? [{ target: i, operator: "getProperty", param: n, value: !!s }] : typeof s == "object" ? Object.keys(s).map((u) => {
if (u === "length")
return { target: i, operator: "length", param: null, value: s[u] };
const f = u, d = s[u];
return { target: i, operator: "getProperty", param: f, value: d };
}) : [];
}
function a(n) {
return Object.keys(n).reduce((i, u) => {
const f = o(u, n[u]);
return i.push(...f), i;
}, []);
}
function c(n, s) {
if (r.has(n.operator)) {
const i = r.get(n.operator);
return i && i(n.target, n.param, n.value, s) || !1;
}
return !1;
}
function p(n, s) {
return a(n).reduce((f, d) => f && c(d, s), !0);
}
function g(n, s) {
const i = Object.keys(n), u = i.includes("allOf"), f = i.includes("anyOf"), d = u || f, h = (d ? n[d ? u ? "allOf" : "anyOf" : "allOf"] : [n]).map((w) => p(w, s));
return u ? !h.includes(!1) : h.includes(!0);
}
return { parseValueSchema: g };
}
const F = {}, k = {};
A();
function L(t, e, l = /* @__PURE__ */ new Map(), r = (c, p, g, n) => p, o = {}, a = (c) => c) {
return P[e.title] = e, B[e.title] = r, F[e.title] = o, k[e.title] = a, (c = {}, p = !0) => {
if (!p)
return v(c, l);
const g = V(c, e, l), n = Object.keys(t).reduce((s, i) => (s[i] = t[i].default, s), {});
return Object.assign(n, g);
};
}
function q(t, e) {
return { customClass: e.class, customStyle: e.style };
}
const I = /* @__PURE__ */ new Map([
["appearance", q]
]);
function S(t, e, l) {
return e;
}
const _ = "https://json-schema.org/draft/2020-12/schema", H = "https://farris-design.gitee.io/radio-button.schema.json", z = "radio-button", G = "A Farris Component", J = "object", Q = {
id: {
description: "The unique identifier for radio-button",
type: "string"
},
type: {
description: "The type string of radio-button",
type: "string",
default: "radio-button"
},
appearance: {
description: "",
type: "object",
properties: {
class: {
type: "string"
},
style: {
type: "string"
}
},
default: {}
},
binding: {
description: "",
type: "object",
default: {}
},
disable: {
type: "string",
default: !1
},
editable: {
description: "",
type: "boolean",
default: !0
},
placeholder: {
description: "",
type: "string",
default: ""
},
readonly: {
description: "",
type: "boolean",
default: !1
},
require: {
description: "",
type: "boolean",
default: !1
},
tabindex: {
description: "",
type: "number",
default: -1
},
visible: {
description: "",
type: "boolean",
default: !0
}
}, U = [
"id",
"type"
], W = {
$schema: _,
$id: H,
title: z,
description: G,
type: J,
properties: Q,
required: U
}, X = "radio-button", Y = "A Farris Component", Z = "object", K = {
basic: {
description: "Basic Infomation",
title: "基本信息",
properties: {
id: {
description: "组件标识",
title: "标识",
type: "string",
readonly: !0
},
type: {
description: "组件类型",
title: "控件类型",
type: "select",
editor: {
type: "waiting for modification",
enum: []
}
}
}
}
}, tt = {
title: X,
description: Y,
type: Z,
categories: K
}, m = {
/**
* 单选组枚举数组
*/
enumData: { type: Array, default: [{ text: "1", active: !0 }] },
/**
* 后缀
*/
suffixValue: { type: String, default: "" },
/**
* 返回值
*/
onSelectedValueChanged: { type: Function, default: () => {
} }
}, E = L(m, W, I, S, tt), y = /* @__PURE__ */ j({
name: "FRadioButton",
props: m,
emits: ["selectedValueChanged"],
setup(t, e) {
const l = T(t.enumData);
function r(a, c) {
if (a.currentTarget.classList.value = "btn btn-secondary active", a.currentTarget.tagName.toLowerCase() === "label") {
const {
currentTarget: p
} = a, g = p.parentElement;
Array.from(g.querySelectorAll("label")).filter((s) => s !== p).forEach((s) => s.classList.remove("active"));
}
e.emit("selectedValueChanged", c);
}
function o(a) {
return `${a.text}${t.suffixValue}`;
}
return $(() => t.enumData, (a, c) => {
a !== c && (l.value = t.enumData);
}), () => b("div", {
class: "f-radio-button"
}, [b("div", {
class: ["farris-input-wrap"]
}, [l.value.map((a, c) => b(C, null, [b("label", {
class: a.active ? "btn btn-secondary active" : "btn btn-secondary",
onClick: (p) => r(p, a)
}, [b("span", {
class: "f-radio-button-text"
}, [o(a)])])]))])]);
}
}), et = /* @__PURE__ */ j({
name: "FRadioButtonDesign",
props: m,
emits: [""],
setup(t, e) {
return () => b(C, null, null);
}
});
y.register = (t, e, l, r) => {
t["radio-button"] = y, e["radio-button"] = E;
};
y.registerDesigner = (t, e, l) => {
t["radio-button"] = et, e["radio-button"] = E;
};
const at = M(y);
export {
y as RadioButton,
at as default,
E as propsResolver,
m as radioButtonProps
};