UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

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