@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
563 lines (562 loc) • 17.8 kB
JavaScript
import { defineComponent as rr, ref as B, watch as U, reactive as H, createVNode as Q } from "vue";
import { merge as L, mergeWith as er, cloneDeep as tr } from "lodash-es";
import or from "../accordion/index.esm.js";
import nr from "../avatar/index.esm.js";
import sr from "../button-edit/index.esm.js";
import ir from "../button-group/index.esm.js";
import pr from "../calendar/index.esm.js";
import cr from "../capsule/index.esm.js";
import ur from "../checkbox/index.esm.js";
import lr from "../combo-list/index.esm.js";
import fr from "../combo-tree/index.esm.js";
import ar from "../component/index.esm.js";
import mr from "../color-picker/index.esm.js";
import gr from "../content-container/index.esm.js";
import dr from "../date-picker/index.esm.js";
import yr from "../data-grid/index.esm.js";
import Fr from "../dropdown/index.esm.js";
import br from "../dynamic-form/index.esm.js";
import Er from "../events-editor/index.esm.js";
import Pr from "../filter-bar/index.esm.js";
import Cr from "../field-selector/index.esm.js";
import vr from "../binding-selector/index.esm.js";
import Rr from "../image-cropper/index.esm.js";
import Vr from "../input-group/index.esm.js";
import Tr from "../layout/index.esm.js";
import Or from "../list-nav/index.esm.js";
import kr from "../list-view/index.esm.js";
import Ar from "../lookup/index.esm.js";
import Mr from "../mapping-editor/index.esm.js";
import jr from "../nav/index.esm.js";
import Dr from "../number-range/index.esm.js";
import Kr from "../number-spinner/index.esm.js";
import Ir from "../order/index.esm.js";
import Br from "../page-header/index.esm.js";
import Lr from "../page-footer/index.esm.js";
import Nr from "../pagination/index.esm.js";
import xr from "../progress/index.esm.js";
import hr from "../query-solution/index.esm.js";
import $r from "../radio-group/index.esm.js";
import Gr from "../rate/index.esm.js";
import Ur from "../response-toolbar/index.esm.js";
import Hr from "../response-layout/index.esm.js";
import Qr from "../response-layout-editor/index.esm.js";
import Wr from "../search-box/index.esm.js";
import qr from "../section/index.esm.js";
import zr from "../smoke-detector/index.esm.js";
import Jr from "../splitter/index.esm.js";
import Xr from "../step/index.esm.js";
import Yr from "../switch/index.esm.js";
import Zr from "../tabs/index.esm.js";
import _r from "../tags/index.esm.js";
import wr from "../text/index.esm.js";
import Sr from "../time-picker/index.esm.js";
import re from "../transfer/index.esm.js";
import ee from "../tree-view/index.esm.js";
import te from "../uploader/index.esm.js";
import oe from "../verify-detail/index.esm.js";
import ne from "../video/index.esm.js";
import se from "../textarea/index.esm.js";
import ie from "../schema-selector/index.esm.js";
import pe from "../tree-grid/index.esm.js";
import ce from "../event-parameter/index.esm.js";
import ue from "../filter-condition-editor/index.esm.js";
import le from "../fieldset/index.esm.js";
import fe from "../sort-condition-editor/index.esm.js";
import ae from "../menu-lookup/index.esm.js";
import me from "../drawer/index.esm.js";
const ge = {
/**
* schema
*/
schema: { type: Object, default: null },
/**
* 组件值
*/
modelValue: { type: Object, default: null },
/**
* 回调
*/
callback: { type: Function, default: () => {
} }
}, e = {}, o = {}, n = {}, t = {};
let W = !1;
function de() {
W || (W = !0, nr.register(e, o, n, t), or.register(e, o, n, t), sr.register(e, o, n, t), ir.register(e, o, n, t), pr.register(e, o, n, t), cr.register(e, o, n, t), ur.register(e, o, n, t), lr.register(e, o, n, t), fr.register(e, o, n, t), ar.register(e, o, n, t), gr.register(e, o, n, t), mr.register(e, o, n, t), dr.register(e, o, n, t), yr.register(e, o, n, t), Fr.register(e, o, n, t), br.register(e, o, n, t), Er.register(e, o, n, t), Pr.register(e, o, n, t), Cr.register(e, o, n, t), ue.register(e, o, n, t), Rr.register(e, o, n, t), Vr.register(e, o, n, t), Tr.register(e, o, n, t), kr.register(e, o, n, t), Or.register(e, o, n, t), Ar.register(e, o, n, t), Mr.register(e, o, n, t), jr.register(e, o, n, t), Dr.register(e, o, n, t), Kr.register(e, o, n, t), Ir.register(e, o, n, t), Br.register(e, o, n, t), Lr.register(e, o, n, t), Nr.register(e, o, n, t), xr.register(e, o, n, t), hr.register(e, o, n, t), $r.register(e, o, n, t), Gr.register(e, o, n, t), Hr.register(e, o, n, t), Qr.register(e, o, n, t), Ur.register(e, o, n, t), ie.register(e, o, n), Wr.register(e, o, n, t), qr.register(e, o, n, t), zr.register(e, o, n, t), Jr.register(e, o, n, t), Xr.register(e, o, n, t), Yr.register(e, o, n, t), fe.register(e, o, n, t), Zr.register(e, o, n, t), _r.register(e, o, n, t), wr.register(e, o, n, t), Sr.register(e, o, n, t), re.register(e, o, n, t), ee.register(e, o, n, t), oe.register(e, o, n, t), te.register(e, o, n, t), ne.register(e, o, n, t), se.register(e, o, n, t), pe.register(e, o, n, t), vr.register(e, o, n, t), ce.register(e, o, n, t), le.register(e, o, n, t), ae.register(e, o, n, t), me.register(e, o, n, t));
}
function ye(l = {}) {
function F(p, a, g, d) {
if (typeof g == "number")
return d[p].length === g;
if (typeof g == "object") {
const T = Object.keys(g)[0], O = g[T];
if (T === "not")
return Number(d[p].length) !== Number(O);
if (T === "moreThan")
return Number(d[p].length) >= Number(O);
if (T === "lessThan")
return Number(d[p].length) <= Number(O);
}
return !1;
}
function y(p, a, g, d) {
return d[p] && d[p].propertyValue && String(d[p].propertyValue.value) === String(g);
}
const b = /* @__PURE__ */ new Map([
["length", F],
["getProperty", y]
]);
Object.keys(l).reduce((p, a) => (p.set(a, l[a]), p), b);
function v(p, a) {
const g = p;
return typeof a == "number" ? [{ target: g, operator: "length", param: null, value: Number(a) }] : typeof a == "boolean" ? [{ target: g, operator: "getProperty", param: p, value: !!a }] : typeof a == "object" ? Object.keys(a).map((d) => {
if (d === "length")
return { target: g, operator: "length", param: null, value: a[d] };
const T = d, O = a[d];
return { target: g, operator: "getProperty", param: T, value: O };
}) : [];
}
function f(p) {
return Object.keys(p).reduce((g, d) => {
const T = v(d, p[d]);
return g.push(...T), g;
}, []);
}
function m(p, a) {
if (b.has(p.operator)) {
const g = b.get(p.operator);
return g && g(p.target, p.param, p.value, a) || !1;
}
return !1;
}
function C(p, a) {
return f(p).reduce((T, O) => T && m(O, a), !0);
}
function E(p, a) {
const g = Object.keys(p), d = g.includes("allOf"), T = g.includes("anyOf"), O = d || T, A = (O ? p[O ? d ? "allOf" : "anyOf" : "allOf"] : [p]).map((x) => C(x, a));
return d ? !A.includes(!1) : A.includes(!0);
}
return { parseValueSchema: E };
}
ye();
function Fe() {
function l(F, y) {
const { id: b } = F || {}, { field: v } = F.binding || {};
return {
modelValue: y.getValue(b),
"onUpdate:modelValue": (f) => {
y.setValue(b, v, f);
}
};
}
return {
resolve: l
};
}
function be() {
return (l, F, y) => {
const b = F.id, { type: v } = F, f = l.emits;
return f ? f.filter((m) => m !== "update:modelValue").reduce((m, C) => {
const E = `on${C.charAt(0).toUpperCase()}${C.slice(1)}`;
return m[E] = (...p) => {
y.dispatch(b, C, v, p);
}, m;
}, {}) : {};
};
}
function Ee(l, F) {
function y(b, v, f, m) {
l.emit("event", { token: b, name: v, type: f, payloads: m, schema: F });
}
return {
dispatch: y
};
}
function Pe() {
const l = /* @__PURE__ */ new Map();
function F(E, p) {
l.set(E, p);
}
function y(E) {
const p = l.get(E);
return p || (console.warn(`Instance with id ${E} not found`), null);
}
function b(E) {
l.delete(E);
}
function v(E, p) {
if (!l.has(E)) {
console.warn(`Instance with id ${E} not found`);
return;
}
l.set(E, p);
}
function f(E) {
return l.has(E);
}
function m() {
return new Map(l);
}
function C() {
l.clear();
}
return {
register: F,
get: y,
remove: b,
update: v,
has: f,
getAll: m,
clear: C
};
}
function Ce(l, F) {
function y(v) {
return l.value && l.value[v];
}
function b(v, f, m) {
l.value && (l.value[v] = m), F.emit("update:modelValue", { elementId: v, field: f, value: m, modelValue: l.value });
}
return {
getValue: y,
setValue: b
};
}
function z(l) {
function F() {
var y, b;
return ((b = (y = l == null ? void 0 : l.module) == null ? void 0 : y.entity[0]) == null ? void 0 : b.entities[0]) || {};
}
return {
getSchemaEntity: F
};
}
function ve(l) {
const { getSchemaEntity: F } = z(l);
function y(f) {
const m = F();
return v(m, f);
}
function b(f) {
var a, g;
const m = [];
function C(d, T) {
var D;
const O = [...T, d.label];
(((D = f == null ? void 0 : f.type) == null ? void 0 : D.primary) || null) && m.push({
bindingPaths: O,
primaryKey: d.type.primary,
label: d.label
}), d.type.entities.forEach((A) => {
C(A, O);
});
}
return (((a = f == null ? void 0 : f.type) == null ? void 0 : a.primary) || null) && (m.push({
bindingPaths: [],
primaryKey: f.type.primary,
label: f.label
}), (((g = f == null ? void 0 : f.type) == null ? void 0 : g.entities) || []).forEach((d) => {
C(d, []);
})), m;
}
function v(f, m, C = !0) {
const E = C ? [] : [f.label];
if (f.label === m)
return {
bindingPaths: E,
primaryKey: f.type.primary,
label: f.label
};
for (const p of f.type.entities) {
const a = v(p, m, !1);
if (a)
return {
bindingPaths: [...E, ...a.bindingPaths],
primaryKey: a.primaryKey,
label: a.label
};
}
return null;
}
return {
resolveEntityByDataSource: y,
resolveEntity: v,
resolveEntities: b
};
}
function Re(l) {
const F = {}, { getSchemaEntity: y } = z(l), { resolveEntities: b } = ve(l);
function v() {
const m = y();
b(m).forEach((E) => {
const p = "/" + E.bindingPaths.join("/"), { primaryKey: a } = E, g = { primaryKey: a, bindingPath: p, label: E.label, currentId: null };
F[p] = g;
});
}
function f(m) {
return Array.isArray(m) ? m = "/" + m.join("/") : m = "/" + m.split("/").filter((C) => C).join("/"), F[m];
}
return {
setup: v,
get: f
};
}
function Ve(l) {
function F(y, b) {
return l(y, b);
}
return {
call: F
};
}
const q = /* @__PURE__ */ rr({
name: "FDynamicView",
props: ge,
emits: ["update:modelValue", "event", "componentReady"],
setup(l, F) {
const y = B(l.schema), b = B(l.modelValue), v = B(l.callback), f = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
de();
const C = Pe(), E = Ce(b, F), p = Re(y.value);
p.setup();
const a = /* @__PURE__ */ new Map();
function g(r) {
const s = r.type, {
dataSource: i,
binding: u
} = r;
if (!i && !u)
return {};
i && m.set(i, r);
const c = t[s];
return (c && c.bindingResolver ? c.bindingResolver : Fe()).resolve(r, E);
}
function d(r) {
const s = {};
return r && Object.entries(r).forEach(([i, u]) => {
s[i] = () => Array.isArray(u) ? u.map((c) => A(c)) : A(u);
}), s;
}
function T(r) {
const s = r.type, i = t[s];
if (!i || Object.keys(i).length < 1)
return {};
const {
callbackResolver: u
} = i;
if (!u)
return {};
const c = Ve(v.value);
return u.resolve(r, c);
}
function O(r) {
const s = r.type, i = Ee(F, r), u = e[s], c = be(), R = t[s], P = R ? R.editorResolver : null;
if (P) {
const V = P.resolve(r).type, j = e[V];
return c ? c(j, r, i) : {};
}
return c ? c(u, r, i) : {};
}
function K(r) {
return {};
}
function D(r) {
const s = r.type, i = o[s], u = i ? i(r) : {}, c = {
...O(r)
};
return {
props: {
...{
...u,
...g(r),
...K(),
...T(r)
},
key: r.id,
ref: (k) => {
k && r.id && !C.has(r.id) && (C.register(r.id, k), F.emit("componentReady", {
ref: B(k),
id: r.id,
type: r.type
}));
}
},
eventProps: c
};
}
function A(r) {
var P, k, M;
const s = r.type;
if (s === "component-ref") {
const V = (k = (P = y.value) == null ? void 0 : P.module) == null ? void 0 : k.components.find((j) => j.id === r.component);
if (V)
return A(V);
}
r.id && f.set(r.id, r);
const i = e[s];
if (!i)
return null;
const u = () => r.contents ? typeof r.contents == "string" ? r.contents : r.contents.map((V) => A(V)) : null, c = (V, j, I) => I && I.length > 0 ? Q(V, {
...j
}, I) : Q(V, {
...j
}, null), R = ((M = a.get(r.id)) == null ? void 0 : M.props) || {};
return r.contents && r.contents.length > 0 ? c(i, R, [u()]) : r.slots ? c(i, R, [...Object.values(d(r.slots))]) : c(i, R);
}
function N(r) {
r.$forceUpdate && r.$forceUpdate();
}
function x(r) {
return f.get(r);
}
function J(r, s) {
const i = f.get(r);
if (!i)
return;
const u = C.get(r);
if (!u)
return;
L(i, s);
const c = i.type, R = t[c], P = R ? R.updateColumnsResolver : null;
P && P.updateColumns(u, i), N(u);
}
function X(r) {
var s;
return (s = a.get(r)) == null ? void 0 : s.props;
}
function Y(r, s) {
const i = a.get(r);
er(i == null ? void 0 : i.props, s, S);
}
function Z(r, s, ...i) {
const u = C.get(r);
if (u) {
if (!u || typeof u[s] != "function")
throw new Error(`Method ${s} not found on instance ${r}`);
return u[s](...i);
}
}
function _(r, s) {
const i = p.get(r);
if (!i)
return;
const u = i.label, c = m.get(u);
if (!c)
return;
const R = c.type, P = t[R], k = P ? P.selectionItemResolver : null;
if (k) {
const M = C.get(c.id);
k.selectItemById(M, s);
}
}
function h(r) {
var k, M;
const s = r.type;
if (s === "component-ref") {
const V = (M = (k = y.value) == null ? void 0 : k.module) == null ? void 0 : M.components.find((j) => j.id === r.component);
if (V)
return h(V);
}
if (!e[s])
return;
const {
props: u,
eventProps: c
} = D(r), R = t[s], P = R ? R.editorResolver : null;
if (P) {
const V = P.resolve(r);
Object.assign(V, c);
} else
Object.assign(u, c);
if (u && Object.keys(u).length > 0) {
const V = a.get(r.id);
V ? L(V == null ? void 0 : V.props, u) : a.set(r.id, H({
props: u
}));
}
!r.contents || !Array.isArray(r.contents) || r.contents.forEach((V) => h(V));
}
function w(r, s) {
const i = o[r];
return i ? i(s, !1) : {};
}
function $(r) {
var c, R;
const s = r.type;
if (s === "component-ref") {
const P = (R = (c = y.value) == null ? void 0 : c.module) == null ? void 0 : R.components.find((k) => k.id === r.component);
if (P)
return $(P);
}
if (!e[s])
return;
const u = g(r);
if (u && Object.keys(u).length > 0) {
const P = a.get(r.id);
P ? L(P == null ? void 0 : P.props, u) : a.set(r.id, H({
props: u
}));
}
!r.contents || !Array.isArray(r.contents) || r.contents.forEach((P) => $(P));
}
function G() {
var i, u;
const r = (u = (i = y.value) == null ? void 0 : i.module) == null ? void 0 : u.components;
if (!r || r.length < 1)
return null;
const s = r.find((c) => c.componentType && c.componentType.toLowerCase() === "frame");
return s || null;
}
function S(r, s) {
if (Array.isArray(r) && Array.isArray(s)) {
const i = /* @__PURE__ */ new Map();
return r.forEach((c) => {
c.id != null && i.set(c.id, c);
}), s.forEach((c) => {
if (c.id != null) {
const R = i.get(c.id);
R ? i.set(c.id, L(R, c)) : i.set(c.id, tr(c));
}
}), Array.from(i.values());
}
}
return U(() => l.modelValue, (r) => {
b.value = r;
const s = G();
s && $(s);
}), U(() => l.schema, (r) => {
y.value = r;
const s = G();
s && h(s);
}), F.expose({
componentManager: C,
rerender: N,
getProps: X,
invoke: Z,
setProps: Y,
selectItemById: _,
getSchema: x,
setSchema: J,
convertPartialSchemaToProps: w
}), () => {
var i, u;
const r = (u = (i = y.value) == null ? void 0 : i.module) == null ? void 0 : u.components;
if (!r || r.length < 1)
return null;
const s = r.find((c) => c.componentType && c.componentType.toLowerCase() === "frame");
return s ? A(s) : null;
};
}
}), ht = {
install(l) {
l.component(q.name, q);
}
};
export {
q as FDynamicView,
e as componentMap,
o as componentPropsConverter,
ht as default,
ge as dynamicViewProps,
de as loadRegister,
t as resolverMap
};