1482 lines
104 KiB
JavaScript
1482 lines
104 KiB
JavaScript
var tn = Object.defineProperty;
|
|
var ni = (t) => {
|
|
throw TypeError(t);
|
|
};
|
|
var nn = (t, e, i) => e in t ? tn(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
var N = (t, e, i) => nn(t, typeof e != "symbol" ? e + "" : e, i), ri = (t, e, i) => e.has(t) || ni("Cannot " + i);
|
|
var c = (t, e, i) => (ri(t, e, "read from private field"), i ? i.call(t) : e.get(t)), S = (t, e, i) => e.has(t) ? ni("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), W = (t, e, i, n) => (ri(t, e, "write to private field"), n ? n.call(t, i) : e.set(t, i), i);
|
|
var ai = (t, e, i, n) => ({
|
|
set _(r) {
|
|
W(t, e, r, i);
|
|
},
|
|
get _() {
|
|
return c(t, e, n);
|
|
}
|
|
});
|
|
import { jsx as h, jsxs as A } from "react/jsx-runtime";
|
|
import E, { useEffect as V, useState as j, useCallback as X, useRef as _, useContext as le, useMemo as K, useId as jt, isValidElement as rn, useLayoutEffect as an } from "react";
|
|
import ce from "pathe";
|
|
import b from "prop-types";
|
|
import O from "classnames";
|
|
import * as oi from "react-is";
|
|
import { useNotification as on } from "rc-notification";
|
|
import m from "lodash";
|
|
import ie, { Field as Ht, FieldContext as bi } from "rc-field-form";
|
|
import { M as Rt, N as Je, a as Ae, s as It, b as sn, S as ln } from "./vender-BkiRbACr.js";
|
|
import Ci from "immutability-helper";
|
|
import { Space as cn, Form as ft, Input as dn, Button as wt, Pagination as un, Tree as pn, Breadcrumb as gn, Table as hn, Empty as mn, Popover as fn, Popconfirm as yn, Tooltip as wn } from "antd";
|
|
import { useMergedState as bn } from "rc-util";
|
|
import { generatePath as Cn, useInRouterContext as ki, useParams as kn, useLocation as En, createBrowserRouter as $n, Navigate as xn } from "react-router-dom";
|
|
import "rc-util/lib/hooks/useMergedState";
|
|
import Sn from "rc-drawer";
|
|
import vn from "rc-dialog";
|
|
var ze, Ge, We, we, Le, je;
|
|
class Ei {
|
|
constructor(e, i) {
|
|
S(this, ze, /* @__PURE__ */ new Map());
|
|
S(this, Ge, !0);
|
|
S(this, We, []);
|
|
S(this, we);
|
|
S(this, Le, () => c(this, we));
|
|
S(this, je, () => Promise.resolve());
|
|
N(this, "get", (...e) => new Promise((i, n) => {
|
|
const r = JSON.stringify(e);
|
|
if (c(this, ze).has(r)) return i(c(this, je).call(this, c(this, we), ...e));
|
|
if (c(this, we) === void 0) c(this, We).push([e, i, n]), c(this, Ge) && (W(this, Ge, !1), Promise.resolve(typeof c(this, Le) == "function" ? c(this, Le).call(this) : c(this, Le)).then((a) => W(this, we, a || null)).finally(() => {
|
|
c(this, We).forEach(([a, o, s]) => {
|
|
try {
|
|
const l = c(this, je).call(this, c(this, we), ...a);
|
|
c(this, ze).set(JSON.stringify(a), l), o(l);
|
|
} catch (l) {
|
|
s(l);
|
|
}
|
|
}), c(this, We).length = 0;
|
|
}));
|
|
else {
|
|
const a = c(this, je).call(this, c(this, we), ...e);
|
|
c(this, ze).set(r, a), i(a);
|
|
}
|
|
}));
|
|
W(this, je, i), W(this, Le, e);
|
|
}
|
|
}
|
|
ze = new WeakMap(), Ge = new WeakMap(), We = new WeakMap(), we = new WeakMap(), Le = new WeakMap(), je = new WeakMap();
|
|
const Hr = () => h("div", { children: "Empty" }), st = E.createContext({ ele: {}, mount: () => {
|
|
}, unmount: () => {
|
|
} }), G = ({ rootClassName: t, className: e, children: i, actions: n, title: r, subTitle: a, extras: o, style: s = {} }) => {
|
|
const { mount: l, unmount: u } = E.useContext(st);
|
|
return G.Action({ children: n }), G.Title({ children: r }), G.SubTitle({ children: a }), G.Extra({ children: o }), V(() => (l("rootClassName", t), () => u(t)), [t]), h("div", { className: O("ff-container", e), style: s, children: i });
|
|
}, mt = (t) => ({ children: e, className: i }) => {
|
|
const { mount: n, unmount: r } = E.useContext(st);
|
|
return V(() => (e && n(t, E.createElement("div", { key: `ff-${t}`, className: O(`ff-popup-${t}`, i) }, e)), () => r(t)), [i, e]), null;
|
|
};
|
|
G.Action = mt("actions"), G.Title = mt("title"), G.SubTitle = mt("sub-title"), G.Extra = mt("extras"), G.propTypes = { className: b.string, style: b.object, title: b.any, subTitle: b.any, actions: b.any, extras: b.any };
|
|
const Jr = () => h(G, { className: "ff-loading", children: A("div", { className: "loader", children: [A("div", { className: "square", children: [h("span", {}), h("span", {}), h("span", {})] }), A("div", { className: "square", children: [h("span", {}), h("span", {}), h("span", {})] }), A("div", { className: "square", children: [h("span", {}), h("span", {}), h("span", {})] }), A("div", { className: "square", children: [h("span", {}), h("span", {}), h("span", {})] })] }) }), Yr = () => h("div", { children: "NotFound" }), $i = ({ children: t }) => {
|
|
const [e, i] = j({}), n = X((a, o) => i((s) => ({ ...s, [a]: o })), []), r = X((a) => i((o) => ({ ...o, [a]: void 0 })), []);
|
|
return typeof (t == null ? void 0 : t.type) == "string" ? t : h(st.Provider, { value: { ele: e, mount: n, unmount: r }, children: E.cloneElement(t, { className: e.rootClassName, title: e.title, subTitle: e["sub-title"], actions: e.actions, extras: e.extras }) });
|
|
};
|
|
$i.propTypes = { children: b.element.isRequired };
|
|
const si = { close: ["M563.8 512l262.5-312.9c4.4-5.2 0.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9c-4.4 5.2-0.7 13.1 6.1 13.1h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"], check: ["M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474c-6.1-7.7-15.3-12.2-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1 0.4-12.8-6.3-12.8z"], info: ["M512 224m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z", "M544 392h-64c-4.4 0-8 3.6-8 8v464c0 4.4 3.6 8 8 8h64c4.4 0 8-3.6 8-8V400c0-4.4-3.6-8-8-8z"] }, Jt = ({ type: t, props: e }) => h("i", { ...e, children: h("svg", { viewBox: "0 0 1024 1024", width: "1em", height: "1em", fill: "currentColor", children: (si[t] || si.info).map((i, n) => h("path", { d: i }, n)) }) }), xi = ({ className: t, content: e, icon: i, $close: n }) => A(E.Fragment, { children: [i && h("div", { className: O("ff-notification-icon", t), children: h(Jt, { type: i }) }), e] }), Nn = ({}) => h(G, { children: "Confirm" });
|
|
var xe, Be;
|
|
const de = class de {
|
|
constructor() {
|
|
S(this, Be, /* @__PURE__ */ new Map());
|
|
N(this, "init", (e) => W(this, Be, new Map(e)));
|
|
N(this, "check", (e) => !c(this, Be).has(e) || c(this, Be).get(e));
|
|
if (c(de, xe)) return c(de, xe);
|
|
}
|
|
};
|
|
xe = new WeakMap(), Be = new WeakMap(), S(de, xe, null), N(de, "getInstance", () => (c(de, xe) || W(de, xe, new de()), c(de, xe)));
|
|
let Vt = de;
|
|
const Si = Vt.getInstance(), Pn = (t, e, i = "children") => {
|
|
if (m.isEmpty(t)) return {};
|
|
const n = m.find(t, ["value", e]);
|
|
if (!m.isEmpty(n)) return n;
|
|
const r = t.length;
|
|
for (let a = 0; a < r; a++) {
|
|
const { [i]: o } = t[a], s = Pn(o, e, i);
|
|
if (!m.isEmpty(s)) return s;
|
|
}
|
|
return {};
|
|
}, vi = (t = "Input", e = "@pkg/ff/grid-layout-forms") => t != null && t.startsWith("@") || t != null && t.startsWith("blob:") ? t : `${e}/${t}`;
|
|
var Se, Xe;
|
|
const ue = class ue {
|
|
constructor() {
|
|
S(this, Xe, null);
|
|
N(this, "init", (e) => W(this, Xe, e));
|
|
N(this, "get", (e, i) => m.get(c(this, Xe), e, i));
|
|
if (c(ue, Se)) return c(ue, Se);
|
|
}
|
|
};
|
|
Se = new WeakMap(), Xe = new WeakMap(), S(ue, Se, null), N(ue, "getInstance", () => (c(ue, Se) || W(ue, Se, new ue()), c(ue, Se)));
|
|
let Mt = ue;
|
|
const Me = Mt.getInstance(), li = { null2json: (t) => Object.create(), null2array: (t) => [], null2number: (t) => 0, null2bool: (t) => !1, null2string: (t) => "", null2integer: (t) => 0, null2float: (t) => 0, string2json: (t) => t ? JSON.parse(t) : "{}", string2array: (t) => t.substr(0, 1) === "[" && t.substr(-1) === "]" ? JSON.parse(t) : t.split(","), string2number: (t) => t == "" ? 0 : +t, string2integer: (t) => t == "" ? 0 : +t, string2float: (t) => t == "" ? 0 : +t, string2bool: (t) => {
|
|
switch (`${t}`.toLowerCase()) {
|
|
case "0":
|
|
case "false":
|
|
case "[]":
|
|
case "{}":
|
|
return !1;
|
|
}
|
|
return !!t;
|
|
}, string2string: (t) => t, json2json: (t) => t, json2array: (t) => t ? Object.values(t) : [], json2number: (t) => Object.keys(t).length, json2integer: (t) => Object.keys(t).length, json2float: (t) => Object.keys(t).length, json2bool: (t) => Object.keys(t).length > 0, json2string: (t) => t ? JSON.stringify(t) : "", array2json: (t) => ({ ...t }), array2array: (t) => t, array2number: (t) => t.length, array2integer: (t) => t.length, array2float: (t) => t.length, array2bool: (t) => t.length > 0, array2string: (t) => JSON.stringify(t), number2json: (t) => ({}), number2array: (t) => [t], number2number: (t) => t, number2integer: (t) => t, number2float: (t) => t, number2bool: (t) => !!t, number2string: (t) => t.toString(), boolean2json: (t) => ({}), boolean2array: (t) => [], boolean2number: (t) => +t, boolean2integer: (t) => +t, boolean2float: (t) => +t, boolean2bool: (t) => t, boolean2string: (t) => t ? "true" : "false" }, oe = (t, e) => {
|
|
let i = "string";
|
|
i = Array.isArray(t) ? "array" : typeof t, m.isObject(t) && (i = "json");
|
|
const n = `${i}2${e}`;
|
|
return Reflect.has(li, n) ? li[n](t) : t;
|
|
}, Tn = (t) => t === null ? "null" : Array.isArray(t) ? "array" : typeof t == "object" ? "json" : typeof t == "boolean" ? "bool" : typeof t == "string" ? "string" : typeof t == "number" ? Number.isInteger(t) ? "integer" : "float" : typeof t, lt = (t = {}, e = {}, i = {}, n = "") => Ni(t, (r, a) => a === "type" && r === "code") ? Pi(t, e, i, n) : Ti(t, e, n), Ni = (t, e = () => !1) => m.some(t, (i) => !!m.some(i, e) || (m.isEmpty(i) || !m.isPlainObject(i) && !m.isArray(i) ? void 0 : Ni(i, e))), Pi = async (t = {}, e = {}, i = {}, n = "") => {
|
|
let r = /* @__PURE__ */ Object.create(null);
|
|
for (let a in t) {
|
|
let o;
|
|
if (Reflect.has(t[a], "type") && ["code", "field", "router", "query", "string"].includes(t[a].type)) {
|
|
const { type: s, value: l = "", default: u = n } = t[a];
|
|
switch (s) {
|
|
case "code":
|
|
try {
|
|
o = await Fe.exec(l, e, i);
|
|
} catch (d) {
|
|
console.error("getWidgetPropsData", d);
|
|
}
|
|
break;
|
|
case "field":
|
|
o = m.get(e, l) ?? m.get(e, l.substring(l.indexOf(".") + 1));
|
|
break;
|
|
case "router":
|
|
case "query":
|
|
o = Ee.getPageParams(l);
|
|
break;
|
|
case "string":
|
|
o = l;
|
|
}
|
|
o ?? (o = u);
|
|
} else o = await Pi(t[a], e, i, n);
|
|
m.set(r, a, o);
|
|
}
|
|
return r;
|
|
}, Ti = (t = {}, e = {}, i = "") => Object.keys(t || {}).reduce((n, r) => {
|
|
if (m.isPlainObject(t[r])) {
|
|
let a;
|
|
if (Reflect.has(t[r], "type") && ["field", "router", "query", "string"].includes(t[r].type)) {
|
|
const { type: o, value: s = "", default: l = i } = t[r];
|
|
switch (o) {
|
|
case "field":
|
|
a = m.get(e, s) ?? m.get(e, s.substring(s.indexOf(".") + 1));
|
|
break;
|
|
case "router":
|
|
case "query":
|
|
a = Ee.getPageParams(s);
|
|
break;
|
|
case "string":
|
|
a = s;
|
|
}
|
|
a ?? (a = l);
|
|
} else a = Ti(t[r], e, i);
|
|
m.set(n, r, a);
|
|
}
|
|
return n;
|
|
}, {}), Ft = (t, e) => t && typeof t == "object" ? Array.isArray(t) ? t.map((i) => Ft(i, e)) : Object.keys(t).reduce((i, n) => (e[n] ? i[e[n]] = Ft(t[n], e) : i[n] = Ft(t[n], e), i), {}) : t, Gr = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
|
|
const e = 16 * Math.random() | 0;
|
|
return (t === "x" ? e : 3 & e | 8).toString(16);
|
|
}), Xr = (t) => {
|
|
var e, i;
|
|
return t ? (i = (e = t.match(/^@pkg(?:[^\/]*\/){3}(?<name>[^\/]+)/)) == null ? void 0 : e.groups) == null ? void 0 : i.name : "";
|
|
}, Qr = (t) => {
|
|
var e, i;
|
|
return t ? (i = (e = t.match(/^@pkg(?:[^\/]*\/){2}(?<category>[^\/]+)/)) == null ? void 0 : e.groups) == null ? void 0 : i.category : "";
|
|
}, Zr = (t) => {
|
|
var e, i;
|
|
return t ? (i = (e = t.match(/^@pkg(?:[^\/]*\/){1}(?<owner>[^\/]+)/)) == null ? void 0 : e.groups) == null ? void 0 : i.owner : "";
|
|
}, On = (t, e = 32, i = "auto") => {
|
|
const n = Dt(t), r = i === "auto" ? "x64" : i;
|
|
if (e === 32) return Rt.x86.hash32(n).toString();
|
|
if (e === 128) return r === "x64" ? Rt.x64.hash128(n) : Rt.x86.hash128(n);
|
|
throw new Error("bits 只能是 32 或 128");
|
|
}, Dt = (t) => t == null ? "null" : typeof t == "string" ? t : typeof t == "number" || typeof t == "boolean" ? String(t) : typeof t == "function" ? t.toString() : Array.isArray(t) ? "[" + t.map(Dt).join(",") + "]" : typeof t == "object" ? "{" + Object.keys(t).sort().map((e) => `${e}:${Dt(t[e])}`).join(",") + "}" : String(t), Rn = () => {
|
|
let t = 1;
|
|
const e = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new Map();
|
|
return (...n) => n.length === 0 ? "" : n.map((r) => {
|
|
return String((a = r) === null || typeof a != "object" && typeof a != "function" ? (i.has(a) || i.set(a, t++), i.get(a)) : (e.has(a) || e.set(a, t++), e.get(a)));
|
|
var a;
|
|
}).join("::");
|
|
}, Fn = (t) => {
|
|
if (!t || typeof t != "string" || t.startsWith("/") || t.startsWith("./") || t.startsWith("../")) return !1;
|
|
try {
|
|
let e = t.startsWith("//") ? `http:${t}` : t;
|
|
return e.includes("://") || e.startsWith("//") || (e = `http://${e}`), !!new URL(e).hostname;
|
|
} catch {
|
|
return !1;
|
|
}
|
|
}, ea = (t, e = "") => {
|
|
if (!t || typeof t != "string" || Fn(t)) return t;
|
|
let i = e;
|
|
return !i && typeof window < "u" && window.location && (i = `${window.location.protocol}//${window.location.host}`), t.startsWith("/") ? i ? `${i}${t}` : t : i ? `${i}/${t}` : t;
|
|
};
|
|
var kt, Qe, Ze, Et;
|
|
const $t = class $t {
|
|
constructor(...e) {
|
|
S(this, Qe, []);
|
|
S(this, Ze, (e) => {
|
|
var i;
|
|
for (let n of e) Array.isArray(n[0]) ? c(this, Ze).call(this, n) : c(this, Qe).push(c(i = $t, kt).call(i, n[0], n[1]));
|
|
});
|
|
N(this, "toValue", async (e, i = null) => {
|
|
const n = { getValue: () => e, getRecord: () => i };
|
|
let r = e;
|
|
for (const a of c(this, Qe)) try {
|
|
const o = await a;
|
|
if (typeof o != "function") {
|
|
console.warn("middleware is not a function, skip:", o);
|
|
continue;
|
|
}
|
|
r = await o.call(n, r);
|
|
} catch (o) {
|
|
console.error("middleware error, skip:", o);
|
|
}
|
|
return r;
|
|
});
|
|
N(this, "toRender", (e, i, n = null) => E.createElement(c(this, Et), { value: e, record: i }, n));
|
|
S(this, Et, ({ value: e, record: i, children: n }) => {
|
|
const [r, a] = j(n);
|
|
return dt(() => {
|
|
let o = !1;
|
|
return a(n), this.toValue(e, i).then((s) => !o && a(s)).catch((s) => !o && a(`${s}`)), () => o = !0;
|
|
}, [e, i]), r;
|
|
});
|
|
c(this, Ze).call(this, e);
|
|
}
|
|
};
|
|
kt = new WeakMap(), Qe = new WeakMap(), Ze = new WeakMap(), Et = new WeakMap(), S($t, kt, m.memoize((e, i) => {
|
|
if (typeof e == "function") return e(i);
|
|
if (typeof e == "string") return se.getWidgetComponent(e).then((n) => {
|
|
var r;
|
|
return ((r = n.default) == null ? void 0 : r.call(n, i)) || ((a) => a);
|
|
});
|
|
throw new TypeError("middleware must be a string or a function");
|
|
}, Rn()));
|
|
let bt = $t;
|
|
const ne = E.createContext({ listCode: "", classNames: {}, getBase62params: (t, e) => {
|
|
}, onReload: () => {
|
|
}, onClickCallback: () => {
|
|
}, onConditionChange: () => {
|
|
}, onTabChange: () => {
|
|
}, onSiderChange: () => {
|
|
}, onKeywordChange: () => {
|
|
}, onPageChange: () => {
|
|
}, onPageSizeChange: () => {
|
|
}, reload: () => {
|
|
}, setPage: () => {
|
|
}, setPageSize: () => {
|
|
}, setTab: () => {
|
|
}, setSider: () => {
|
|
}, setKeyword: () => {
|
|
}, setCondition: () => {
|
|
} }), ci = ({ className: t, record: e, column: i, ...n }) => {
|
|
if (i != null && i.editableByJs && (i != null && i.uuid)) {
|
|
const { formSetting: r = { primaryKey: "id" }, widgetSetting: a = {}, widgetContainerSetting: o = {} } = (i == null ? void 0 : i.editableByJsSetting) || {};
|
|
return h(P.Popover, { widget: An, widgetData: { record: e, column: i }, widgetSetting: { widgetSetting: a, formSetting: r }, widgetContainerProps: { title: i != null && i.title ? `${i.title} - 编辑` : "编辑", ...o, width: (o == null ? void 0 : o.width) || 260, arrow: !0 }, children: h("td", { className: O("ff-data-list-cell-editable", t), ...n }) });
|
|
}
|
|
return h("td", { className: t, ...n });
|
|
}, An = ({ record: t, column: e, $close: i, $setting: n }) => {
|
|
const r = _(Tn(m.get(t, e == null ? void 0 : e.dataIndex))), { listCode: a, onClickCallback: o } = le(ne), [s] = ie.useForm(), { formSetting: l, widgetSetting: u } = n, d = (l == null ? void 0 : l.primaryKey) || "id", p = () => {
|
|
s.setFieldsValue({ value: m.get(t, e == null ? void 0 : e.dataIndex), __PROPS__: t });
|
|
};
|
|
return dt(() => p(), [t, e == null ? void 0 : e.dataIndex, a]), h(G, { actions: A(E.Fragment, { children: [h(P, { size: "small", onClick: p, children: "重置" }), A(cn.Compact, { block: !0, children: [h(P, { size: "small", widget: i, children: "取消" }), h(P, { type: "primary", size: "small", widget: () => s.validateFields().then(({ value: f }) => {
|
|
const g = m.get(t, d.substring(d.indexOf(".") + 1));
|
|
if (!g) throw "获取更新主键失败!";
|
|
I.put(`/api/${a}-storeBy-${e == null ? void 0 : e.uuid}/${g}`, { value: f }).msg(() => o(2, t)).then(i);
|
|
}).catch(console.warn), children: "保存" })] })] }), children: A(ie, { form: s, children: [h(Xt, { label: "", type: r.current, code: "value", widget: e == null ? void 0 : e.editableByJs, extras: u }), h(Ht, { noStyle: !0, name: ["__PROPS__"], children: () => {
|
|
} })] }) });
|
|
}, Ln = (t) => function(e) {
|
|
return t(e, getRecord());
|
|
}, jn = (t, e = {}) => K(() => {
|
|
var i;
|
|
return (i = t == null ? void 0 : t.filter(Boolean)) == null ? void 0 : i.map(({ widgetByJs: n, widgetByJsSetting: r, ...a }, o) => {
|
|
const s = (u) => ({ record: u, column: a });
|
|
let l = [];
|
|
return n && l.push([n, r]), l.length > 0 ? (a != null && a.render && l.push([Ln, a.render]), { ...a, onCell: s, render: (u, d) => new bt(l).toRender(u, d, "-") }) : { ...a, onCell: s };
|
|
});
|
|
}, [t, e]), In = (t = {}) => K(() => {
|
|
var e;
|
|
return t.body ?? (t.body = { cell: ci }), (e = t.body).cell ?? (e.cell = ci), t;
|
|
}, [t]), ta = (t) => {
|
|
const [e, i] = j({});
|
|
return V(() => {
|
|
let n = !1;
|
|
return t && I.get(`/api/_/${t}`).then((r) => m.pick(r, ["uuid", "name", "code", "resource", "marginX", "marginY", "cols", "rowHeight", "primaryKey", "columns", "itemOperations", "batchOperations", "isConditionFormLayout", "layout", "tabs", "pageSize", "layoutConfig"])).then((r) => !n && i(r)), () => n = !0;
|
|
}, [t]), e;
|
|
}, ia = (t, e = {}) => {
|
|
const [i, n] = j({ dataSource: [] });
|
|
return ct(() => {
|
|
let r = !1;
|
|
return t && I.get(`/api/${t}/${I.encode({ page: 1, ...e })}`).then((a) => !r && n(a)), () => r = !0;
|
|
}, [t, e]), i;
|
|
}, Oi = (t = [], e = /* @__PURE__ */ new Map(), i = "id", n) => {
|
|
const r = X(n ? (a) => m.get(a, i, m.get(a, [n, i])) : (a) => m.get(a, i), [i, n]);
|
|
return X((a) => t == null ? void 0 : t.filter((o) => !o.uuid || !e.has(o.uuid) || e.get(o.uuid).some((s) => s == r(a))), [t, e, r]);
|
|
}, zt = (t = [], e = /* @__PURE__ */ new Map(), i = [], n = "id", r) => {
|
|
const a = X(r ? (o) => m.get(o, n, m.get(o, [r, n])) : (o) => m.get(o, n), [n, r]);
|
|
return K(() => {
|
|
if (m.isEmpty(t) || !t.some(({ uuid: s }) => Si.check(s))) return !1;
|
|
if (m.isEmpty(e) || m.isEmpty(i)) return !0;
|
|
const o = i.map((s) => a(s));
|
|
return t.some(({ uuid: s }) => !s || !e.has(s) || e.get(s).some((l) => o.some((u) => u == l)));
|
|
}, [t, i, e, a]);
|
|
}, Vn = (t, e, i = "id", n = null) => {
|
|
const r = Nt(), a = _(!1), o = _(t.dataSource), s = _(t.itemOperationsAccess);
|
|
return V(() => (o.current = t.dataSource, s.current = t.itemOperationsAccess, () => a.current = !1), [t.dataSource, t.itemOperationsAccess]), a.current && (t.dataSource = o.current, t.itemOperationsAccess = s.current), [t, (l = 0, u = null) => {
|
|
var d, p;
|
|
if (a.current = !1, l === 1) return (d = t.onReload) == null ? void 0 : d.call(t);
|
|
if (l === 2) {
|
|
const f = m.get(u, "__PARENT_ID__", ""), g = m.get(u, i, m.get(u, [n, i], "")), y = m.findIndex(o.current, ["__PARENT_ID__", f]), w = m.findIndex(y > -1 ? m.get(o.current, [y, "children"]) : o.current, [i, g]);
|
|
if (w === -1) return (p = t.onReload) == null ? void 0 : p.call(t);
|
|
Promise.all([I.get(`/api/${e}/detail/${g}`), I.post(`/api/${e}/list-operations-access`, { ids: g })]).then(([C, k]) => {
|
|
const x = m.get(o.current, y > -1 ? [y, "children", w, "children"] : [w, "children"]);
|
|
o.current = Ci(o.current, y > -1 ? { [y]: { children: { $splice: [[w, 1, { ...C, children: x }]] } } } : { $splice: [[w, 1, { ...C, children: x }]] });
|
|
const $ = new Map(k);
|
|
s.current.forEach((T, F) => {
|
|
var L;
|
|
(L = $.get(F)) != null && L.some((D) => D == g) || s.current.set(F, T.filter((D) => D !== g));
|
|
}), $.forEach((T, F) => {
|
|
s.current.has(F) ? s.current.set(F, m.uniq([...s.current.get(F) || [], ...T])) : s.current.set(F, T);
|
|
});
|
|
}).then(() => {
|
|
a.current = !0, r();
|
|
});
|
|
}
|
|
}];
|
|
}, Mn = (t, e) => {
|
|
const i = Nt(), n = _(e), r = _(/* @__PURE__ */ new Map()), a = _([]), o = m.throttle((l) => {
|
|
a.current = [], I.list(t, m.pick({ ...n.current, ...l }, ["tab", "page", "pageSize", "condition", "sider", "keyword"])).then(({ keyword: u, condition: d, total: p, tab: f, sider: g, page: y, pageSize: w, operationsAccess: C, dataSource: k }) => {
|
|
n.current = { tab: f, condition: d, sider: g, keyword: u, total: p, pageSize: w, page: k != null && k.length ? y : 1 }, a.current = k, r.current = new Map(C), i();
|
|
});
|
|
}, 380, { leading: !1, trailing: !0 });
|
|
dt(() => {
|
|
a.current = [], t && o(e);
|
|
}, [t, e]);
|
|
const s = K(() => m.pick(n.current, ["total", "tab", "page", "pageSize", "condition", "sider", "keyword"]), [n.current]);
|
|
return Object.assign(s, { onTabChange: (l) => o({ tab: l, page: 1 }), onPageChange: (l, u) => o({ page: l, pageSize: u }), onPageSizeChange: (l) => o({ pageSize: l, page: 1 }), onConditionChange: (l, u) => o({ keyword: u, condition: Ci(n.current.condition || {}, { $merge: l || {} }), page: 1 }), onSiderChange: (l) => o({ sider: l, page: 1 }), onKeywordChange: (l) => o({ keyword: l, page: 1 }), itemOperationsAccess: r.current, dataSource: a.current, onReload: o, payload: e == null ? void 0 : e.payload });
|
|
}, Dn = ({ listCode: t, className: e, layouts: i = {}, dataSource: n, isPaginate: r, isItemOperations: a, isBatchOperations: o, batchOperations: s, itemOperations: l, itemOperationsAccess: u, resource: d, primaryKey: p, title: f, itemGridLayout: g, $setting: y, tabs: w, isConditionFormLayout: C, isTreeSider: k, treeSiderConfig: x }) => {
|
|
const { classNames: $, onClickCallback: T } = le(ne), F = m.pick(y, ["column", "colWidth", "beforeRender", "afterRender", "style"]), L = Oi(l, u, p, d), D = X((U, R, M) => h(zn, { className: O("ff-data-list-framework-item", $.item), operations: a ? L(R) : [], data: d ? { [d]: R } : R, children: U, onClickCallback: T }), [d, p, a, T, l, u]);
|
|
return A("div", { className: O("ff-data-list-framework", e), children: [h(i.sider, { isTreeSider: k, ...x }), A("div", { className: O("ff-data-list-container", $ == null ? void 0 : $.container), children: [h(i.filter, { isConditionFormLayout: C }), h(i.toolbar, { title: f, tabs: w }), h(Zn, { ...F, ...g, primaryKey: p, itemRender: D, dataSource: n }), h(i.footer, { isPaginate: r, isOperations: o, operations: s })] })] });
|
|
}, zn = ({ className: t, operations: e, children: i, data: n, onClickCallback: r }) => A("div", { className: O("data-list-grid-layout-item", t), children: [h("div", { className: "data-list-grid-layout-item-container", children: i }), !!(e != null && e.length) && h("div", { className: "data-list-grid-layout-item-actions", children: e.map((a) => h("span", { className: "data-list-grid-layout-item-action", children: h(P.Link, { uuid: a.uuid, type: a.type, name: a.name, widget: a.widget, widgetType: a.widgetType, widgetProps: a.widgetProps, widgetSetting: a.widgetSetting, widgetContainerProps: a.widgetContainerSetting, data: n, confirm: a.confirm, onAfterClick: (o) => o !== !1 && (r == null ? void 0 : r(a.isRefresh, n)) }, a.uuid || jt()) }, (a == null ? void 0 : a.uuid) || jt())) })] }), Wn = ({ listCode: t, className: e, layouts: i = {}, dataSource: n, columns: r, isItemOperations: a, isBatchOperations: o, batchOperations: s, itemOperations: l, itemOperationsAccess: u, resource: d, primaryKey: p, title: f, tabs: g, isPaginate: y, isTreeSider: w, treeSiderConfig: C, isConditionFormLayout: k, ...x }) => {
|
|
const { classNames: $, onClickCallback: T } = le(ne), F = Oi(l, u, p, d), L = zt(l, u, n, p, d);
|
|
return A("div", { className: O("ff-data-table-framework", e), children: [h(i.sider, { isTreeSider: w, ...C }), A("div", { className: O("ff-data-table-container", $ == null ? void 0 : $.container), children: [h(i.filter, { isConditionFormLayout: k }), h(i.toolbar, { title: f, tabs: g }), h(Hn, { ...x, primaryKey: p, className: "ff-data-table-content", columns: r, dataSource: n, operationRender: L ? (D) => {
|
|
var U;
|
|
return h("div", { className: "ff-data-table-actions", children: (U = F(D)) == null ? void 0 : U.map((R, M) => h(P.Link, { size: "small", uuid: R.uuid, type: R.type, name: R.name, widget: R.widget, widgetType: R.widgetType, widgetProps: R.widgetProps, widgetData: R.widgetData, widgetSetting: R.widgetSetting, widgetContainerProps: R.widgetContainerSetting, data: D, confirm: R.confirm, onAfterClick: (v) => v !== !1 && (T == null ? void 0 : T(R.isRefresh, D)) }, R.uuid || M)) });
|
|
} : null }), h(i.footer, { isPaginate: y, isOperations: o, operations: s })] })] });
|
|
}, Yt = (t = [], e, i = null) => {
|
|
var n;
|
|
return (n = m.sortBy(t, ["y", "x"])) == null ? void 0 : n.map(({ i: r, x: a, y: o, w: s, h: l, field: { boxStyle: u, ...d } = {} }, p) => h("div", { className: "grid-layout-item", style: Ri(a, o, s, l, u), children: h(e, { ...d, basicForm: i }) }, r ?? p));
|
|
}, Ri = (t, e, i, n, r = {}, a = 0) => {
|
|
const o = { "--grid-layout-h": `${n}`, "--grid-layout-w": `${i}`, "--grid-layout-x": `${t}`, "--grid-layout-y": `${e}`, "--grid-layout-row-height-offset": "0px" };
|
|
return r != null && r.autoHeight ? o.height = "fit-content" : o["--grid-layout-row"] = `${n}`, r != null && r.alignItems && (o["--grid-layout-box-align-items"] = r.alignItems), r != null && r.justifyContent && (o["--grid-layout-box-justify-content"] = r.justifyContent), o["--grid-layout-box-margin"] = di(r == null ? void 0 : r.marginTop, r == null ? void 0 : r.marginRight, r == null ? void 0 : r.marginBottom, r == null ? void 0 : r.marginLeft), o["--grid-layout-box-padding"] = di(r == null ? void 0 : r.paddingTop, r == null ? void 0 : r.paddingRight, r == null ? void 0 : r.paddingBottom, r == null ? void 0 : r.paddingLeft), a && (o.height = `${a}px`), o;
|
|
}, di = (t, e, i, n) => `${t || 0}px ${e || 0}px ${i || 0}px ${n || 0}px`, na = (t = "Text", e = "@pkg/ff/grid-layouts") => t != null && t.startsWith("@") || t != null && t.startsWith("blob:") ? t : `${e}/${t}`, Fi = ({ className: t, isConditionFormLayout: e }) => {
|
|
var f, g;
|
|
const [i, n] = j({}), { listCode: r, onKeywordChange: a, onConditionChange: o, getBase62params: s, classNames: l } = E.useContext(ne), { keyword: u, condition: d } = (s == null ? void 0 : s()) || {}, [p] = ft.useForm();
|
|
return V(() => {
|
|
r && e && I.get(`/api/_/${r}/list-condition-form-layout`).then(({ resource: y, marginX: w, marginY: C, rowHeight: k, cols: x, fields: $ }) => {
|
|
n({ resource: y, itemMargin: [w, C], rowHeight: k, cols: x, fields: $ });
|
|
}).catch(() => n({}));
|
|
}, [r, e]), V(() => {
|
|
p.setFieldsValue({ keyword: u, ...d });
|
|
}, [JSON.stringify([u, d])]), h("div", { className: O("ff-data-list-filter", l.filter, t), children: h(ft, { form: p, layout: "vertical", autoComplete: "off", onFinish: ((f = i.fields) == null ? void 0 : f.length) > 1 ? (y) => o({ [i.resource]: y[i.resource] }, y.keyword) : () => {
|
|
}, onValuesChange: (y) => {
|
|
m.isEmpty(m.omit(y, ["keyword"])) || p.submit();
|
|
}, children: ((g = i.fields) == null ? void 0 : g.length) > 1 ? h(Qt, { ...i, children: h(Bn, { onReset: () => {
|
|
const { keyword: y, condition: w } = s("init") || {};
|
|
p.setFieldsValue({ keyword: y, ...w });
|
|
} }) }) : h("div", { className: "ff-data-list-filter-default-form ff-grid-layout-form", children: h("div", { className: "grid-layout-item", style: Ri(20, 0, 5, 2), children: h(ft.Item, { name: ["keyword"], children: h(dn.Search, { allowClear: !0, enterButton: "搜索", placeholder: "多关键字 | 分割", onSearch: (y) => a(y) }) }) }) }) }) });
|
|
}, Bn = ({ cols: t, fields: e, onReset: i }) => {
|
|
const [n, r] = j(!1), a = K(() => e == null ? void 0 : e.toReversed().some((o) => o.y > 1 || o.x + o.w >= t - 5), [t, e]);
|
|
return A(ft.Item, { label: " ", style: { "--item-span": 5 }, className: O("ff-data-list-filter-actions", { expanded: n }), children: [h(wt, { onClick: i, children: "重置" }), h(wt, { type: "primary", htmlType: "submit", children: "查询" }), a && h(P.Link, { className: "ff-data-list-filter-expanded-button", widget: () => r((o) => !o), type: "primary", name: n ? "关闭" : "展开", icon: n ? "icon-up" : "icon-down", iconPosition: "end" })] });
|
|
};
|
|
Fi.reservedFields = [{ x: 0, y: 0, h: 3, w: 5, field: { isVirtual: !0, widgetPrefix: "@pkg/ff/grid-layout-forms", widget: "Input", code: "keyword", label: "关键字", placeholder: "多关键字 | 分割", extras: { prefix: "icon-search" } } }];
|
|
const Un = ({ className: t, operations: e, isOperations: i, isPaginate: n }) => {
|
|
const { onPageChange: r, onPageSizeChange: a, onClickCallback: o, getBase62params: s } = E.useContext(ne), { total: l, page: u, pageSize: d } = (s == null ? void 0 : s()) || {};
|
|
return i && !m.isEmpty(e) || n ? A("div", { className: O("ff-data-list-footer", t), children: [h("div", { className: "ff-data-list-actions", children: e == null ? void 0 : e.map((p, f) => h(P, { uuid: p.uuid, type: p.type, name: p.name, widget: p.widget, widgetType: p.widgetType, widgetProps: p.widgetProps, widgetData: p.widgetData, widgetSetting: p.widgetSetting, widgetContainerProps: p.widgetContainerSetting, onAfterClick: (g) => g !== !1 && (o == null ? void 0 : o(p.isRefresh, null)) }, p.uuid || f)) }), n && h(un, { size: "small", total: l, pageSize: d, showSizeChanger: !1, showTotal: (p) => `第 ${u} 页 / 总共 ${p} 条`, onChange: r, onShowSizeChange: a })] }) : null;
|
|
}, qn = [{ title: "parent 1", key: "0-0", children: [{ title: "parent 1-0", key: "0-0-0", disabled: !0, children: [{ title: "leaf", key: "0-0-0-0", disableCheckbox: !0 }, { title: "leaf", key: "0-0-0-1" }] }, { title: "parent 1-1", key: "0-0-1", children: [{ title: h("span", { style: { color: "#1677ff" }, children: "sss" }), key: "0-0-1-0" }] }] }], Kn = ({ className: t, width: e = 280, isTreeSider: i }) => {
|
|
const { classNames: n } = le(ne);
|
|
return i ? h(pn.DirectoryTree, { className: O("ff-data-list-sider", n.sider, t), style: { "--sider-width": e }, showLine: !0, showIcon: !1, treeData: qn }) : null;
|
|
}, _n = ({ className: t, title: e, tabs: i }) => {
|
|
const { getBase62params: n, onTabChange: r, onReload: a, classNames: o } = le(ne), { tab: s } = (n == null ? void 0 : n()) || {}, [l, u] = bn((i == null ? void 0 : i[0].value) ?? (i == null ? void 0 : i[0].code), { value: s, onChange: r });
|
|
return A("div", { className: O("ff-data-list-toolbar", o.toolbar, t), children: [h("div", { className: "ff-data-list-title", children: e }), h(gn, { className: "ff-data-list-tabs", itemRender: ({ label: d, code: p, value: f }) => h("span", { onClick: () => u(f ?? p), className: O("ff-data-list-tab", { active: (f ?? p) == l }), children: d }), items: i }), A("div", { className: "ff-data-list-actions", children: [h(P.Link, { icon: "icon-reload", widget: () => a() }), h(P.Link, { icon: "icon-setting" })] })] });
|
|
}, Ai = ({ isItemGridLayout: t, theme: e, themeProps: i, onClickCallback: n, onReload: r, listCode: a, total: o = 0, page: s = 0, onPageChange: l, pageSize: u = 30, onPageSizeChange: d, tab: p, onTabChange: f, keyword: g, onKeywordChange: y, condition: w, onConditionChange: C, sider: k, onSiderChange: x, layouts: $, classNames: T = {}, payload: F = {}, ...L }) => {
|
|
const [D, U] = j(), R = X((v, B) => {
|
|
const z = { tab: p, page: s, pageSize: u, keyword: g, sider: k, condition: w, total: o, payload: F };
|
|
return v && v != "init" ? m.get(z, v, B) : z;
|
|
}, [JSON.stringify(w), JSON.stringify(F), p, s, u, g, k, o]), M = K(() => {
|
|
let v = { sider: Kn, filter: Fi, footer: Un, toolbar: _n };
|
|
$ === !1 ? v = { sider: null, filter: null, footer: null, toolbar: null } : m.isPlainObject($) && (v = Object.assign({}, v, $));
|
|
for (const B in v) if (v[B]) {
|
|
if (rn(v[B])) {
|
|
const z = v[B];
|
|
v[B] = ($e) => E.cloneElement(z, $e);
|
|
}
|
|
} else v[B] = () => h(E.Fragment, {});
|
|
return v;
|
|
}, [$]);
|
|
return V(() => {
|
|
e ? se.getWidgetComponent(e).then((v) => {
|
|
if (!v) throw `${e} not found`;
|
|
return v;
|
|
}).catch((v) => ({ default: () => `${v}` })).then((v) => U(E.createElement(v.default, { ...L, layouts: M, $setting: i }))) : U(h(t ? Dn : Wn, { ...L, layouts: M, $setting: i }));
|
|
}, [e, i]), h(ne.Provider, { value: { classNames: T, listCode: a, onClickCallback: n, onReload: r, getBase62params: R, onPageChange: l, onPageSizeChange: d, onTabChange: f, onSiderChange: x, onKeywordChange: y, onConditionChange: C, setPage: l, setPageSize: d, setTab: f, setSider: x, setKeyword: y, setCondition: C }, children: D && E.cloneElement(D, L) });
|
|
};
|
|
Ai.propTypes = { classNames: b.exact({ sider: b.string, filter: b.string, footer: b.string, toolbar: b.string, container: b.string, content: b.string, item: b.string }), layouts: b.oneOfType([b.exact({ sider: b.oneOfType([b.elementType, b.element]), filter: b.oneOfType([b.elementType, b.element]), footer: b.oneOfType([b.elementType, b.element]), toolbar: b.oneOfType([b.elementType, b.element]) }), b.bool]) };
|
|
var ve, be, Ie, xt;
|
|
const pe = class pe {
|
|
constructor() {
|
|
S(this, be, null);
|
|
S(this, Ie, /* @__PURE__ */ new Map());
|
|
S(this, xt, () => {
|
|
if (c(this, be)) return c(this, be).port.postMessage({ command: "status", data: [] });
|
|
W(this, be, new SharedWorker(new URL("/ff-worker/res-ws.js", self.location))), c(this, be).port.onmessage = (e) => {
|
|
var i, n;
|
|
(i = e.data) != null && i.uuid ? c(this, Ie).forEach((r, a) => {
|
|
var o;
|
|
(r == "*" || (o = r == null ? void 0 : r.includes) != null && o.call(r, e.data.uuid)) && a(e.data);
|
|
}) : ((n = e.data) == null ? void 0 : n.readyState) == WebSocket.CLOSED && I.get("/api/user-api-token").then(({ token: r, expire_at: a }) => {
|
|
c(this, be).port.postMessage({ command: "initWs", data: [`ws${m.trimStart(I.appUrl, "http")}api/user-resource-status-ws?token=${r}`] });
|
|
});
|
|
}, c(this, be).port.postMessage({ command: "status", data: [] });
|
|
});
|
|
N(this, "subscribe", (e, i = []) => (i ? Array.isArray(i) && i.length == 0 ? i = "*" : Array.isArray(i) || (i = [i].flat()) : i = "*", c(this, Ie).set(e, i), c(this, Ie).size == 1 && c(this, xt).call(this), () => this.unsubscribe(e)));
|
|
N(this, "unsubscribe", (e) => c(this, Ie).delete(e));
|
|
if (c(pe, ve)) return c(pe, ve);
|
|
}
|
|
};
|
|
ve = new WeakMap(), be = new WeakMap(), Ie = new WeakMap(), xt = new WeakMap(), S(pe, ve, null), N(pe, "getInstance", () => (c(pe, ve) || W(pe, ve, new pe()), c(pe, ve)));
|
|
let Wt = pe;
|
|
const Li = Wt.getInstance(), Gt = E.forwardRef(({ listCode: t, base62params: e, className: i, theme: n, themeProps: r, layouts: a, classNames: o }, s) => {
|
|
const [{ resource: l, primaryKey: u, batchOperations: d = [], itemOperations: p = [], columns: f = [], themeConfig: g, theme: y, isConditionFormLayout: w = !1, isTreeSider: C, treeSiderConfig: k, isItemGridLayout: x, itemGridLayout: { themeConfig: $, ...T } = {}, title: F, isPaginate: L, tabs: D }, U] = j({ isItemGridLayout: !1, itemGridLayout: {} }), R = Mn(t, e), [{ dataSource: M, itemOperationsAccess: v, condition: B, tab: z, keyword: $e, page: pt, total: gt, pageSize: Tt, sider: te, onConditionChange: qi, onTabChange: Ki, onKeywordChange: _i, onPageChange: Hi, onPageSizeChange: Ji, onSiderChange: Yi, onReload: Ot, payload: Gi }, ii] = Vn(R, t, u, l), Xi = zt(p, v, M, u), Qi = zt(d);
|
|
V(() => {
|
|
let re = null;
|
|
return t && I.get(`/api/_/${t}`).resp(({ data: ht, res: en }) => {
|
|
ht != null && ht.isDynamicRefresh && (re = Li.subscribe(() => Ot(), en)), U(ht);
|
|
}).catch(() => U({})), () => re == null ? void 0 : re();
|
|
}, [t]), E.useImperativeHandle(s, () => ({ onReload: Ot, onClickCallback: ii }));
|
|
const Zi = { listCode: t, title: F, classNames: o, layouts: a, resource: l, primaryKey: u, theme: n || y, themeProps: r || g, isTreeSider: C, treeSiderConfig: k, isPaginate: L, tabs: D, isItemOperations: Xi, itemOperations: p == null ? void 0 : p.map((re) => m.isEmpty(re == null ? void 0 : re.confirm) ? re : { ...re, confirm: Object.assign({}, re.confirm, { getPopupContainer: () => document.body }) }), isBatchOperations: Qi, batchOperations: d, isItemGridLayout: x, columns: f, itemGridLayout: { ...T, themeProps: $ }, isConditionFormLayout: w, itemOperationsAccess: v, dataSource: M, onConditionChange: qi, onTabChange: Ki, onKeywordChange: _i, onPageChange: Hi, onPageSizeChange: Ji, onSiderChange: Yi, condition: B, tab: z, keyword: $e, page: pt, total: gt, pageSize: Tt, sider: te, payload: Gi };
|
|
return h(Ai, { ...Zi, className: O("ff-data-list-helper", i), onReload: Ot, onClickCallback: ii });
|
|
}), ji = (t, e, i = !0) => i !== !0 && i-- <= 0 ? [] : m.isArray(t) && !m.isEmpty(t) ? t.reduce((n, r) => (Reflect.has(r, e) && Reflect.has(r, "children") && n.push(r[e]), Reflect.has(r, "children") && !m.isEmpty(r.children) ? n.concat(ji(r.children, e, i)) : n), []) : [], Hn = ({ className: t, primaryKey: e, columns: i = [], dataSource: n = [], operationRender: r, operationWidth: a = 180, components: o = {}, ...s }) => {
|
|
const { classNames: l } = le(ne), u = _(null), d = _(null), [p, f] = j([]), [g, y] = j({ width: 0, height: 0 });
|
|
V(() => {
|
|
f(ji(n, e));
|
|
}, [n, e]), an(() => {
|
|
const k = new ResizeObserver(() => {
|
|
var x;
|
|
y({ width: ((x = u.current) == null ? void 0 : x.nativeElement.querySelector(".ant-table-body").scrollWidth) || d.current.offsetWidth, height: d.current.offsetHeight });
|
|
});
|
|
return d.current && k.observe(d.current), () => {
|
|
d.current && k.unobserve(d.current);
|
|
};
|
|
}, []);
|
|
const w = jn(i), C = In(o);
|
|
return h("div", { ref: d, className: O("ff-data-list-table", l.content, t), children: g.height ? h(hn, { bordered: !0, ...s, components: C, ref: u, rowKey: (k) => (k == null ? void 0 : k[e]) ?? Math.random(), columns: w == null ? void 0 : w.concat(r ? [{ title: "操作", align: "center", fixed: "right", width: `${Math.ceil(a / g.width * 100).toFixed(2)}%`, render: (k, x, $) => r(x, $) }] : []), dataSource: n, size: "middle", scroll: { x: "max-content", y: g.height - 50 }, pagination: !1, expandable: { defaultExpandAllRows: !0, expandRowByClick: !0, onExpandedRowsChange: f, expandedRowKeys: p } }) : null });
|
|
}, Jn = "RC_FORM_INTERNAL_HOOKS", Yn = (t) => {
|
|
const [e, i] = E.useState({ items: [] });
|
|
return V(() => {
|
|
t && I.get(`/api/_/${t}`).then(({ uuid: n, code: r, name: a, resource: o, primaryKey: s, marginX: l, marginY: u, cols: d, rowHeight: p, fields: f, theme: g, themeSetting: y, groups: w }) => ({ uuid: n, code: r, name: a, resource: o, primaryKey: s, marginX: l, marginY: u, cols: d, rowHeight: p, theme: g, themeProps: y, groups: w, items: f })).then(i);
|
|
}, [t]), e;
|
|
}, Gn = (t, { initialValue: e, initialValueLanguage: i, convertJs: n, convertJsSetting: r, type: a = "string" }, o = null) => {
|
|
const s = _(!1), l = le(bi), [u, d] = j(), [p, f] = j(i != "javascript" && t ? l.getFieldValue(t) : void 0), { registerWatch: g } = l.getInternalHooks(Jn) || {};
|
|
return V(() => g == null ? void 0 : g((y, w, C) => {
|
|
if (!s.current) return;
|
|
const k = m.get(w, t);
|
|
m.isEqual(k, p) || f(oe(k, a));
|
|
}), [p]), V(() => {
|
|
i == "javascript" && e ? Fe.exec(e, {}, { getFieldValueForBasicForm: (y) => o ? o.getFieldValue(y) : l.getFieldValue(y), getFieldValue: (y) => l.getFieldValue(y) }).then((y) => f(oe(y, a))).catch((y) => notification.error({ message: `布局数据错误: ${JSON.stringify(y)}` })).finally(() => s.current = !0) : (e && f(oe(e ?? l.getFieldValue(t), a)), s.current = !0);
|
|
}, [e, i]), ct(() => {
|
|
s.current && n && new bt([n, r]).toValue(p, l.getFieldsValue(!0)).then(d).catch((y) => {
|
|
d(y), console.error("布局数据转换错误: ", y, n);
|
|
});
|
|
}, [p, n, r]), [u ?? p, p];
|
|
}, ra = (t, e, i = null) => K(() => Yt(t, e, i), [t]), Ii = (t, e, i = {}, n = {}, r = {}, a = null) => {
|
|
const o = le(bi), s = Nt(), l = _(!0), u = _([]), [d, p] = j(e), [f, g] = j(), y = ie.useWatch((w) => JSON.stringify(m.pick(w, u.current)), o) || "{}";
|
|
return dt(() => {
|
|
t && Fe.exec(t, i, { ...n, getFieldValueForBasicForm: (w) => r ? r.getFieldValue(w) : null, getFieldValue: m.wrap(o.getFieldValue, (w, C) => (u.current.some((k) => m.isEqual(k, C)) || (u.current.push(C), s()), w == null ? void 0 : w(C))), isFieldTouched: o.isFieldTouched, isFieldsTouched: o.isFieldsTouched }).then((w) => {
|
|
l.current && (p(w), g(null));
|
|
}).catch((w) => {
|
|
l.current && (p(e), g(w));
|
|
});
|
|
}, [t, y, o, i, n]), V(() => () => l.current = !1, []), t ? [a ? oe(d, a) : d, f] : [a ? oe(e, a) : e, null];
|
|
}, Xn = ({ widget: t, widgetPrefix: e = "@pkg/ff/grid-layouts", basicForm: i, ...n }) => {
|
|
const r = t != null && t.startsWith("@") || t != null && t.startsWith("blob:") ? t : `${e}/${t}`, [a, o] = j();
|
|
return V(() => {
|
|
r && se.getWidgetComponent(r).then(({ defaultProps: s = {}, default: l }) => ({ default: Qn(l, s, i) })).catch((s) => ({ default: () => `${s}` })).then((s) => o(E.createElement(s.default, n)));
|
|
}, [r]), a;
|
|
}, Qn = (t, e = {}, i = null) => (n) => {
|
|
const { code: r, label: a, extras: o, isVirtual: s, initialValue: l, initialValueLanguage: u, convertJs: d, convertJsSetting: p, value: f, ...g } = m.merge({}, e, n), [y, w] = Gn(s ? null : r, { initialValue: l, initialValueLanguage: u, convertJs: d, convertJsSetting: p, type: (g == null ? void 0 : g.type) || "string" }, i), C = K(() => {
|
|
const $ = Object.keys((e == null ? void 0 : e.extras) || {});
|
|
return m.over([m.partialRight(m.pick, $), m.partialRight(m.omit, $)]);
|
|
}, [e == null ? void 0 : e.extras]), [k, x] = C(g);
|
|
return h(t, { ...x, value: y, rawValue: w, $setting: Object.assign({}, o, k) });
|
|
}, Vi = ({ theme: t, basicForm: e, items: i = [{ key: "default", label: "默认" }], fields: n = [], itemRender: r, chunks: a = [], children: o, $setting: s = {}, ...l }) => {
|
|
const [u, d] = j();
|
|
V(() => {
|
|
t ? se.getWidgetComponent(t).then((f) => {
|
|
if (!(f != null && f.default)) throw "not found";
|
|
return f;
|
|
}).catch((f) => ({ default: () => `${t} ${f}` })).then((f) => d(E.createElement(f.default, {}))) : d(null);
|
|
}, [t]);
|
|
const p = K(() => i == null ? void 0 : i.map((f) => ({ ...f, children: r(f, n == null ? void 0 : n.filter((g) => !(g != null && g.group) && f.key == "default" || g.group == f.key), f.key == "default" ? o : null) })).concat(a), [i, o, a]);
|
|
return u && E.cloneElement(u, { items: p, basicForm: e, $setting: { ...s, ...l } });
|
|
}, Mi = ({ name: t, form: e = null, basicForm: i = null, style: n = {}, className: r, cols: a = 12, rowHeight: o = 21, containerPadding: s = [0, 0], itemMargin: l = [4, 0], formProps: u = {}, formFields: d = [], fields: p = [], data: f, theme: g, themeProps: y = {}, groups: w = [{ key: "default", label: "默认" }], children: C, ...k }) => {
|
|
const [x] = ie.useForm(e), $ = K(() => [{ name: "__PROPS__", value: u }].concat(d), [u, d]);
|
|
ct(() => (x.setFieldsValue(f), () => x.resetFields()), [f]);
|
|
const T = (F, L, D) => {
|
|
const U = Yt(L, Xn, i);
|
|
return A("div", { className: O("ff-grid-layout", r), style: { ...n, "--grid-layout-item-margin-y": `${(l == null ? void 0 : l[0]) || 0}px`, "--grid-layout-item-margin-x": `${(l == null ? void 0 : l[1]) || 0}px`, "--grid-layout-container-padding-y": `${(s == null ? void 0 : s[0]) || 0}px`, "--grid-layout-container-padding-x": `${(s == null ? void 0 : s[1]) || 0}px`, "--grid-layout-cols": a, "--grid-layout-row-height": `${o}px` }, children: [U, D && E.cloneElement(D, { cols: a, rowHeight: o, itemMargin: l, containerPadding: s, fields: L, basicForm: i })] });
|
|
};
|
|
return h(ie, { ...k, fields: $, form: x, component: !1, children: g ? h(Vi, { ...y, items: w, theme: g, itemRender: T, fields: p, children: C, basicForm: i }) : T(0, p, C) });
|
|
}, aa = /* @__PURE__ */ ((t) => function({ code: e, data: i, ...n }) {
|
|
const { uuid: r, resource: a, items: o, hides: s, rowHeight: l, marginX: u, marginY: d, cols: p, theme: f, themeProps: g, groups: y } = Yn(e) || {}, w = K(() => [{ name: "__RESOURCE__", value: a }, { name: "__LAYOUT_KEY__", value: e }, { name: "__LAYOUT_UUID__", value: r }], [e, r, a]);
|
|
return a && h(t, { name: e, theme: f, themeProps: g, groups: y, ...n, fields: o, formFields: w, rowHeight: l, cols: p, itemMargin: [u, d], data: a ? { [a]: i } : i });
|
|
})(Mi), Zn = ({ column: t = 0, colWidth: e = 0, cols: i, rowHeight: n, itemMargin: r, fields: a, primaryKey: o, dataSource: s, itemClassName: l, beforeRender: u = null, afterRender: d = null, itemRender: p = (x, $, T) => x, empty: f = h(mn, { description: null }), className: g, style: y = {}, theme: w, themeProps: C = {}, groups: k = [{ key: "default", label: "默认" }] }) => {
|
|
const { classNames: x } = le(ne), $ = K(() => h(Mi, { groups: k, theme: w, themeProps: C, cols: i, rowHeight: n, itemMargin: r, fields: a, className: l }), [a, i, n, r, k, w, C]), T = m.isEmpty(s);
|
|
return A("div", { className: O("ff-data-list-content", x.content, g), style: Object.assign({}, y, t && { "--col-num": t }, e && { "--col-width": e }), children: [u == null ? void 0 : u(s), T ? f : s.map((F, L) => {
|
|
const D = p(E.cloneElement($, { data: F }), F, L);
|
|
return E.cloneElement(D, { key: `${(F == null ? void 0 : F[o]) ?? L}-${On(F)}` });
|
|
}), d == null ? void 0 : d(s)] });
|
|
}, er = ({ component: t, $props: e }) => {
|
|
const { base62params: i } = lt(e, {});
|
|
return h(G, { children: h(Gt, { listCode: t, base62params: I.decode(i) }) });
|
|
}, oa = () => h(Di, {}), Di = () => "Empty", tr = ({ component: t, $setting: e, $props: i }) => {
|
|
const [n, r] = j();
|
|
V(() => {
|
|
if (!t) return r(h(Di, { description: null }));
|
|
se.getWidgetComponent(t).catch((o) => ({ default: () => `${o}` })).then((o) => E.createElement(o.default, { $setting: e })).then(r);
|
|
}, [t]);
|
|
const a = lt(i, {});
|
|
return n ? E.cloneElement(n, a) : null;
|
|
}, sa = () => "NotFoundPage";
|
|
var Ne, ae, Pe, Te, et, tt;
|
|
const ge = class ge {
|
|
constructor() {
|
|
S(this, ae, /* @__PURE__ */ new Map());
|
|
S(this, Pe, {});
|
|
S(this, Te, null);
|
|
N(this, "init", (e, i) => {
|
|
W(this, ae, e), W(this, Pe, i);
|
|
});
|
|
N(this, "get", (e) => (c(this, ae).has(e) || (e = Array.from(c(this, ae).keys()).find((i) => c(this, ae).get(i).uri === e)), c(this, ae).get(e) || {}));
|
|
N(this, "redirect", (e, i, n = {}) => {
|
|
const { uri: r, type: a, widgetProps: o } = this.get(e) || {}, { router: s, query: l, ...u } = i || {}, d = Object.assign({}, u, s), p = Object.assign({}, u, l);
|
|
a == "list" && (d.base62params = I.encode(d != null && d.base62params ? d.base62params : d));
|
|
let f = Cn(r || e, d);
|
|
const g = new URLSearchParams();
|
|
for (const y in o || {}) (o == null ? void 0 : o.type) == "query" && Object.has(p, y) && g.append(y, JSON.stringify(p[y]));
|
|
return g.size > 0 && (f = `${f}?${g.toString()}`), n != null && n.isOpenWindow ? window.open(f) : c(this, Te).navigate(f, { replace: !!(n != null && n.isReplaceRouteHistory) });
|
|
});
|
|
N(this, "getMenus", (e) => {
|
|
var i;
|
|
return ((i = c(this, Pe)) == null ? void 0 : i[e]) || [];
|
|
});
|
|
N(this, "findMenuPathByUuid", (e) => {
|
|
let i = [];
|
|
for (const n in c(this, Pe)) if (i = c(this, et).call(this, c(this, Pe)[n], e, [n]), i.length > 1) return i;
|
|
return i;
|
|
});
|
|
N(this, "getMenusByRouteUuid", (e) => c(this, tt).call(this, e, Object.values(c(this, Pe)).flat()));
|
|
S(this, et, (e, i, n = []) => {
|
|
if (m.isEmpty(e)) return n;
|
|
for (const { uuid: r, children: a } of e) {
|
|
if (r == i) return n.concat(r);
|
|
if (!m.isEmpty(a)) return n.concat(r, c(this, et).call(this, a, i));
|
|
}
|
|
return n;
|
|
});
|
|
S(this, tt, (e, i) => {
|
|
var r;
|
|
let n = [];
|
|
for (const a of i) a.widgetType == "redirect" && (a.uuid == e || a.widget == e ? n.push(a) : (r = a.children) != null && r.length && (n = n.concat(c(this, tt).call(this, e, a.children))));
|
|
return n;
|
|
});
|
|
N(this, "getCurrentMenu", () => {
|
|
const { uuid: e } = this.getCurrentRoute() || {};
|
|
if (!e) return;
|
|
const i = this.getMenusByRouteUuid(e);
|
|
return m.isEmpty(i) ? void 0 : i[0];
|
|
});
|
|
N(this, "getCurrentRoute", (e = 0) => {
|
|
var n;
|
|
const i = (n = c(this, Te).state.matches[c(this, Te).state.matches.length - 1 - e]) == null ? void 0 : n.route;
|
|
if (!i) return null;
|
|
for (let [r, a] of c(this, ae)) if (a.uri === i.path) return a;
|
|
return null;
|
|
});
|
|
N(this, "getPageParams", (e) => {
|
|
var r, a, o;
|
|
let i = "", n = {};
|
|
if (ki()) n = kn(), i = (r = En()) == null ? void 0 : r.search;
|
|
else {
|
|
const { location: s = {}, matches: l = [] } = ((a = c(this, Te)) == null ? void 0 : a.state) || {};
|
|
n = ((o = l[l.length - 1]) == null ? void 0 : o.params) || {}, i = s.search;
|
|
}
|
|
return i && new URLSearchParams(i).forEach((s, l) => {
|
|
n[l] = s;
|
|
}), e ? m.get(n, e) : n;
|
|
});
|
|
N(this, "createBrowserRouter", (e = {}) => {
|
|
if (c(this, ae).size == 0) return null;
|
|
const i = Me.get("Common.WEBSITE_DEFAULT_THEME", "@pkg/ff/frameworks/DefaultTheme"), n = Me.get(se.checkUserToken() ? "Common.WEBSITE_LOGIN_REDIRECT" : "Common.WEBSITE_DEFAULT", "/index"), r = { [i]: 0 }, a = (s, l) => () => Promise.all([se.getWidgetComponent(s), lt(l)]).then(([u, d]) => [u.default || function() {
|
|
return `${s}`;
|
|
}, d]).then(([u, d]) => ({ Component: () => E.createElement($i, {}, E.createElement(u, { $setting: d })) })), o = Array.from(c(this, ae).values()).reduce((s, { uuid: l, uri: u, name: d, type: p, component: f, widgetSetting: g, widgetProps: y, isLogin: w, isLayout: C, extra: k }) => {
|
|
let x = {}, $ = 0;
|
|
switch (p) {
|
|
case "list":
|
|
x.element = E.createElement(er, { component: f, $props: y });
|
|
break;
|
|
case "fsdpf-component":
|
|
x.element = E.createElement(tr, { key: f, component: f, $setting: g, $props: y });
|
|
}
|
|
const T = (k == null ? void 0 : k.theme) ?? (k == null ? void 0 : k.layout);
|
|
if (T) {
|
|
const F = (k == null ? void 0 : k.themeProps) ?? (k == null ? void 0 : k.layoutProps);
|
|
if (!r[T]) return r[T] = s.length, [...s, { path: "/", lazy: a(T, F), children: [{ path: u, ...x }] }];
|
|
$ = r[T];
|
|
}
|
|
return C && $ > -1 ? (s[$].children.push({ path: u, ...x }), s) : [...s, { path: u, ...x }];
|
|
}, [{ path: "/", lazy: a(i, {}), children: [] }]);
|
|
return o.push({ index: !0, element: E.createElement(ir, { to: n, replace: !0 }) }), W(this, Te, $n(o, e));
|
|
});
|
|
if (c(ge, Ne)) return c(ge, Ne);
|
|
}
|
|
};
|
|
Ne = new WeakMap(), ae = new WeakMap(), Pe = new WeakMap(), Te = new WeakMap(), et = new WeakMap(), tt = new WeakMap(), S(ge, Ne, null), N(ge, "getInstance", () => (c(ge, Ne) || W(ge, Ne, new ge()), c(ge, Ne)));
|
|
let Bt = ge;
|
|
const ir = ({ to: t, replace: e }) => ki() ? E.createElement(xn, { to: t, replace: e }) : (window.document.location = t, "redirect"), Ee = Bt.getInstance(), De = new Worker(new URL("/ff-worker/index.js", self.location)), ui = { getConfigure: (t) => Me.get(t), route: { redirect: (...t) => Ee.redirect(...t), getPageParams: (...t) => Ee.getPageParams(...t), getCurrentRoute: () => Ee.getCurrentRoute() }, popup: { notification: (...t) => ee.notification(...t), success: (...t) => ee.success(...t), error: (...t) => ee.error(...t), form: (...t) => ee.form(...t), modal: (...t) => ee.modal(...t), confirm: (...t) => ee.confirm(...t) } };
|
|
var St, Ue, Oe;
|
|
const q = class q {
|
|
constructor() {
|
|
N(this, "exec", (e, i = {}, n = {}, r = "") => new Promise((a, o) => {
|
|
if (!/^(?!\s*(\/\/|\/\*|\*)).*?\S+/m.test(e)) return a();
|
|
const s = ai(q, St)._++;
|
|
c(q, Ue).set(s, n), q.mQueue.set(s, [a, o]), De.postMessage({ id: s, session: r, category: "eval", method: e, args: i });
|
|
}));
|
|
N(this, "clear", (e) => De.postMessage({ session: e, category: "clear" }));
|
|
if (c(q, Oe)) return c(q, Oe);
|
|
Promise.resolve().then(() => Pr).then((e) => {
|
|
ui.http = e.http;
|
|
}), De.addEventListener("message", ({ data: { id: e, task_id: i, method: n, args: r, category: a, data: o, error: s, session: l } }) => {
|
|
if (a === "eval" && q.mQueue.has(e)) s !== null ? q.mQueue.get(e)[1](s) : q.mQueue.get(e)[0](o), c(q, Ue).delete(e), q.mQueue.delete(e);
|
|
else if (a === "util") try {
|
|
const u = m.get(ui, n.split("/")) || m.get(c(q, Ue).get(i), n.split("/"));
|
|
if (!m.isFunction(u)) throw `${n} not found`;
|
|
Promise.resolve(Reflect.apply(u, void 0, r)).then((d) => {
|
|
De.postMessage({ id: e, task_id: i, category: a, method: n, args: r, session: l, data: d, error: null });
|
|
}).catch((d) => {
|
|
De.postMessage({ id: e, task_id: i, category: a, method: n, args: r, session: l, data: null, error: d });
|
|
});
|
|
} catch (u) {
|
|
De.postMessage({ id: e, task_id: i, category: a, method: n, args: r, session: l, data: null, error: u });
|
|
}
|
|
}, !1);
|
|
}
|
|
};
|
|
St = new WeakMap(), Ue = new WeakMap(), Oe = new WeakMap(), N(q, "mQueue", /* @__PURE__ */ new Map()), S(q, St, 0), S(q, Ue, /* @__PURE__ */ new Map()), S(q, Oe, null), N(q, "getInstance", () => (c(q, Oe) || W(q, Oe, new q()), c(q, Oe)));
|
|
let Ut = q;
|
|
const Fe = Ut.getInstance(), Nt = () => {
|
|
const t = _(!0), [, e] = E.useReducer((i) => i + 1, 0);
|
|
return V(() => () => t.current = !1, []), () => t.current && e();
|
|
}, la = (t) => {
|
|
const e = _();
|
|
return V(() => {
|
|
e.current = t;
|
|
}, [t]), e.current;
|
|
}, ca = (t) => {
|
|
const [e, i] = j(t), n = _(null), r = X((a, o) => {
|
|
n.current = o, i(a);
|
|
}, []);
|
|
return V(() => {
|
|
n.current && (n.current(e), n.current = null);
|
|
}, [e]), [e, r];
|
|
}, ct = (t = (n) => {
|
|
}, e, i = m.isEqual) => {
|
|
const n = E.useRef();
|
|
i(e, n.current) || (n.current = m.cloneDeep(e)), E.useEffect(t, [n.current]);
|
|
}, dt = ct, zi = (t, e = "string") => {
|
|
var i;
|
|
if (!Array.isArray(t)) return t;
|
|
for (let n = 0; n < t.length; n++) t[n].value = oe((i = t[n]) == null ? void 0 : i.value, e), t[n] && Reflect.has(t[n], "children") && (t[n].children = zi(t[n].children, e));
|
|
return t;
|
|
}, da = (t, e = "json", i = "string", n, r = null) => {
|
|
const [a] = ie.useForm(n), [o, s] = j([{ label: "无", value: "", disabled: !0 }]), l = _([]), u = ie.useWatch((d) => l.current.length === 0 ? null : m.pick(d, l.current), a) || null;
|
|
return V(() => {
|
|
Array.isArray(t) ? s(t) : e === "javascript" && t ? Fe.exec(t, {}, { getFieldValue: (d) => (l.current.includes(d) || l.current.push(d), a.getFieldValue(d)), getFieldValueForBasicForm: (d) => (l.current.includes(d) || l.current.push(d), r ? r.getFieldValue(d) : a.getFieldValue(d)) }).then((d) => {
|
|
s(oe(d, "array"));
|
|
}).catch((d) => console.error("useOptions", d)) : t && s(oe(t, "array"));
|
|
}, [t, e, u]), zi(o, i);
|
|
}, ua = (t) => {
|
|
const [e, i] = j(), n = { type: "GET" };
|
|
if (typeof t == "string" ? n.url = t : m.isPlainObject(t) && Object.assign(n, t), !(n != null && n.url)) throw "url is required";
|
|
const r = (a) => I.request(n, !1).resp((o) => (console.log("useSubscribeRequest", a), i(o), o));
|
|
return ct(() => {
|
|
let a = null;
|
|
return r().then((o) => {
|
|
a = Li.subscribe(m.throttle(r, 180, { leading: !1, trailing: !0 }), o.res);
|
|
}), () => a == null ? void 0 : a();
|
|
}, n), e;
|
|
}, nr = (t) => {
|
|
const [e, i] = E.useState({ items: [], hides: [] });
|
|
return E.useEffect(() => {
|
|
t && I.get(`/api/_/${t}`).then(({ pk: n, uuid: r, code: a, resource: o, align: s, cols: l, rowHeight: u, marginX: d, marginY: p, listenChangeFields: f, listenChangeFieldsFunc: g, fields: y, theme: w, themeSetting: C, groups: k }) => ({ pk: n, uuid: r, code: a, resource: o, align: s, cols: l, rowHeight: u, marginX: d, marginY: p, theme: w, themeProps: C, groups: k, listenChangeFields: f, listenChangeFieldsFunc: g, ...y.reduce((x, $) => {
|
|
var T;
|
|
return (T = $ == null ? void 0 : $.field) != null && T.hidden ? x.hides.push($ == null ? void 0 : $.field) : x.items.push($), x;
|
|
}, { items: [], hides: [] }) })).then(i);
|
|
}, [t]), e;
|
|
}, rr = ({ max: t = 0, min: e = 0, type: i = "", message: n, pattern: r, required: a = !1, validator: o } = {}, s, l) => {
|
|
const [u, d] = j([]);
|
|
return V(() => {
|
|
const p = [];
|
|
if (a) {
|
|
let f = l;
|
|
switch (l) {
|
|
case "number":
|
|
case "string":
|
|
case "array":
|
|
break;
|
|
case "bool":
|
|
f = "boolean";
|
|
break;
|
|
case "json":
|
|
f = "object";
|
|
}
|
|
p.push({ type: f, required: !0, whitespace: !0, message: "该项必填" });
|
|
}
|
|
switch (i) {
|
|
case "string":
|
|
p.push({ type: i, max: t, min: e, message: n || (e && t ? `字符必须在 ${e} ~ ${t} 之间` : `${t ? "最多能有" : "最少要有"} ${e || t} 个字符`) });
|
|
break;
|
|
case "pattern":
|
|
p.push({ type: "string", pattern: r, message: n });
|
|
break;
|
|
case "validator":
|
|
o && p.push(({ getFieldValue: f }) => ({ validator: async (g, y) => {
|
|
const w = await Fe.exec(o, { value: y, fieldName: s }, { getFieldValue: f });
|
|
return m.isString(w) && w ? Promise.reject(w) : m.isBoolean(w) && !w ? Promise.reject(n) : Promise.resolve();
|
|
} }));
|
|
}
|
|
d(p);
|
|
}, [t, e, i, n, r, a, o]), u;
|
|
}, ar = (t, e, i) => {
|
|
const [n, r] = j(null);
|
|
return V(() => {
|
|
const { initDataUri: a = `/api/${t}`, initDataMethod: o = "GET" } = i || {};
|
|
e && I.request({ method: o, url: m.trimEnd(`${a}/${e}`, "/") }).then((s) => {
|
|
r(s);
|
|
});
|
|
}, [t, e, i]), n;
|
|
}, or = (t, e, i) => X((n, r = { serialize: (a) => a, onSuccess: () => {
|
|
}, onFail: (a) => (a == null ? void 0 : a.errorFields) && ee.error("请先完善表单信息", { duration: 2e3 }) }) => {
|
|
const a = n.getFieldValue("__RESOURCE__"), { submitDataUri: o = `/api/${t}`, submitDataMethod: s = "POST" } = i || {};
|
|
return n.validateFields().then((l) => a ? m.pick(l, [a]) : l).then(r.serialize).then((l) => I.request({ method: s, url: m.trimEnd(`${o}/${e || ""}`, "/"), data: l }).msg(r.onSuccess)).catch(r.onFail);
|
|
}, [t, e, i]), sr = (t, e, i, n) => {
|
|
const r = ar(e, i, n);
|
|
V(() => {
|
|
r ? t.setFieldsValue(r) : t.resetFields();
|
|
}, [t, r]);
|
|
const a = or(e, i, n);
|
|
return m.partial(a, t);
|
|
}, lr = (t, e, i = [], n = {}) => {
|
|
const r = _({}), a = _(), o = m.debounce(Nt(), 180), s = ["disabled", "required"], l = (f, g) => {
|
|
s.includes(f) && (r.current[f] = g), o();
|
|
}, u = K(() => ({ setDisabled: (f) => l("disabled", f), setRequired: (f) => l("required", f), getDisabled: () => r.current.disabled, getRequired: () => r.current.required }), [e]), [d, p] = Ii(e, -1, {}, u, n);
|
|
if (!p && a.current != d && (d >= 0 || !m.isEmpty(i == null ? void 0 : i[d]))) {
|
|
a.current = d;
|
|
const { widget: f, widgetPrefix: g, props: y } = i == null ? void 0 : i[d];
|
|
t = vi(f, g), r.current = m.merge(y, m.pick(r.current, s));
|
|
}
|
|
return [t, r.current];
|
|
}, pi = (t) => t === void 0 || t === !1 ? "" : (Array.isArray(t) ? t : [t]).join("_"), pa = ({ value: t, onChange: e }, i = null) => {
|
|
const n = _(), [r] = ie.useForm(i), a = _({});
|
|
return dt(() => {
|
|
m.isEqual(n.current, t) || r.setFieldsValue(t);
|
|
}, [t]), V(() => () => r.resetFields(), []), [K(() => r.__INTERNAL__ ? r : { ...r, __INTERNAL__: { itemRef: (o) => (s) => {
|
|
const l = pi(o);
|
|
s ? a.current[l] = s : delete a.current[l];
|
|
} }, scrollToField: (o, s = {}) => {
|
|
console.warn("useMergedFormValuesChange scrollToField not work, unreferenced antd form");
|
|
}, focusField: (o) => {
|
|
console.warn("useMergedFormValuesChange focusField not work, unreferenced antd form");
|
|
}, getFieldInstance: (o) => {
|
|
const s = pi(o);
|
|
return a.current[s];
|
|
} }, [r]), (o, s) => {
|
|
n.current = s, e == null || e(s);
|
|
}];
|
|
}, Xt = ({ widget: t = "Input", widgetPrefix: e = "@pkg/ff/grid-layout-forms", widgetDecorator: i, subWidgets: n = [], basicForm: r, ...a }) => {
|
|
const o = vi(t, e), [s, l] = lr(o, i, n, r), [u, d] = j();
|
|
return V(() => {
|
|
s && se.getWidgetComponent(s).then(({ defaultProps: p = {}, default: f }) => ({ default: cr(f, p, r) })).catch((p) => ({ default: () => `${p}` })).then((p) => d(E.createElement(p.default, a)));
|
|
}, [s]), u && E.cloneElement(u, { ...a, ...l });
|
|
}, cr = (t, e = {}, i = null) => (n) => {
|
|
const { type: r, code: a, label: o, noStyle: s, style: l, placeholder: u, required: d = !1, extras: p, validators: f, help: g, isVirtual: y, $isReserved: w, initialValue: C, initialValueLanguage: k, ...x } = m.omit(m.merge({}, e, n), ["convertJs", "convertJsSetting", "widget", "widgetPerfix", "widgetDecorator", "subWidgets", "boxStyle"]), $ = rr(Object.assign({}, f, d ? { required: !0 } : {}), a, r), T = K(() => {
|
|
const R = Object.keys((e == null ? void 0 : e.extras) || {});
|
|
return m.over([m.partialRight(m.pick, R), m.partialRight(m.omit, R)]);
|
|
}, [e == null ? void 0 : e.extras]), [F, L] = T(x), D = { label: o, noStyle: s, style: l, colon: !1, layout: "vertical" }, U = X((R) => R == null ? void 0 : oe(R, r), [r]);
|
|
return h(Ht, { name: a, rules: $, initialValue: U(C), normalize: U, children: (R, M, v) => {
|
|
var B;
|
|
return h(t, { type: r, rcform: v, basicForm: i, itemProps: { validateStatus: M.errors.length > 0 ? "error" : "success", tooltip: g || null, help: M.errors.length > 0 ? M.errors.join("、") : null, required: ((B = $ == null ? void 0 : $[0]) == null ? void 0 : B.required) || !1, ...D }, fieldProps: { placeholder: u, ...L, ...R }, $setting: Object.assign({}, p, F) });
|
|
} });
|
|
}, Qt = ({ name: t, form: e = null, basicForm: i = null, style: n = {}, className: r, cols: a = 24, rowHeight: o = 16, itemMargin: s = [8, 16], containerPadding: l = [0, 0], fields: u = [], hides: d = [], primaryKey: p = 0, formProps: f = {}, formFields: g = [], listenChangeFields: y, listenChangeFieldsFunc: w, onValuesChange: C, theme: k, themeProps: x = {}, groups: $ = [{ key: "default", label: "默认" }], children: T, ...F }) => {
|
|
const [L] = ie.useForm(e), D = X((M, v) => {
|
|
C == null || C(M, v), w && Array.isArray(y) && Fe.exec(w, { changedValues: M, allValues: v }, { getFieldValue: L.getFieldValue, setFieldValue: L.setFieldValue, setFieldsValue: L.setFieldsValue, isFieldTouched: L.isFieldTouched, isFieldsTouched: L.isFieldsTouched }).catch((B) => console.error("onFormValuesChange", t, B));
|
|
}, [t, L, C, y, w]), U = K(() => [{ name: "__PROPS__", value: f }, { name: "__PRIMARY_KEY__", value: p }].concat(g), [p, f, g]), R = (M, v, B) => {
|
|
const z = Yt(v, Xt, i);
|
|
return A("div", { className: O("ff-grid-layout-form", r), style: { ...n, "--grid-layout-item-margin-x": `${(s == null ? void 0 : s[0]) ?? 8}px`, "--grid-layout-item-margin-y": `${(s == null ? void 0 : s[1]) ?? 16}px`, "--grid-layout-container-padding-y": `${(l == null ? void 0 : l[0]) || 0}px`, "--grid-layout-container-padding-x": `${(l == null ? void 0 : l[1]) || 0}px`, "--grid-layout-cols": a, "--grid-layout-row-height": `${o}px` }, children: [z, B && E.cloneElement(B, { cols: a, rowHeight: o, itemMargin: s, containerPadding: l, fields: v, basicForm: i })] });
|
|
};
|
|
return A(ie, { ...F, form: L, fields: U, onValuesChange: D, children: [k ? h(Vi, { ...x, items: $, theme: k, itemRender: R, fields: u, children: T, basicForm: i }) : R(0, u, T), d == null ? void 0 : d.map((M) => {
|
|
var v;
|
|
return h(Ht, { name: M.code, children: h(dr, { form: L, basicForm: i, name: M.code, type: M.type, initialValue: M.initialValue, initialValueLanguage: (v = M.extras) == null ? void 0 : v.initialValueLanguage }) }, JSON.stringify(M.code));
|
|
})] });
|
|
}, dr = ({ type: t, initialValue: e, initialValueLanguage: i, onChange: n, basicForm: r }) => {
|
|
const [a, o] = Ii(i == "javascript" && e, i == "javascript" ? void 0 : e, {}, {}, r);
|
|
return V(() => {
|
|
i == "javascript" ? n(oe(a, t)) : e && n(oe(e, t));
|
|
}, [t, e, a]), null;
|
|
};
|
|
Qt.propTypes = { fields: b.array, hides: b.array };
|
|
const ur = /* @__PURE__ */ ((t) => ({ code: e, isPreview: i = !1, ...n }) => {
|
|
const { align: r, autoComplete: a, resource: o, items: s, hides: l, rowHeight: u, marginX: d, marginY: p, cols: f, listenChangeFields: g, listenChangeFieldsFunc: y, pk: w, uuid: C, theme: k, themeProps: x, groups: $ } = nr(e), T = K(() => [{ name: "__PK__", value: w }, { name: "__RESOURCE__", value: o }, { name: "__LAYOUT_KEY__", value: e }, { name: "__LAYOUT_UUID__", value: C }], [w, e, C, o]);
|
|
return h(t, { name: e, autoComplete: a, theme: k, themeProps: x, groups: $, ...n, formFields: T, listenChangeFields: g, listenChangeFieldsFunc: y, fields: s, hides: l, cols: f, rowHeight: u, itemMargin: [d, p] });
|
|
})(Qt), Wi = ({ $setting: t, $close: e, extras: i, code: n, primaryKey: r, ...a }) => {
|
|
const [o] = ie.useForm(), s = sr(o, n, r, t);
|
|
return h(G, { actions: A(E.Fragment, { children: [h(P, { name: (t == null ? void 0 : t.okText) || "保存", type: "primary", widget: () => s({ onSuccess: e }) }), h(P, { name: (t == null ? void 0 : t.cancelText) || "取消", widget: () => e(!1) })] }), extras: i, children: h(ur, { form: o, code: n, primaryKey: r, ...a }) });
|
|
}, gi = /* @__PURE__ */ new Set(), qt = (t = [], e = 0) => {
|
|
const i = t[e];
|
|
if (i.length && !gi.has(i)) {
|
|
const n = document.createElement("script");
|
|
n.setAttribute("src", i), n.setAttribute("data-namespace", i), t.length > e + 1 && (n.onload = () => {
|
|
qt(t, e + 1);
|
|
}, n.onerror = () => {
|
|
qt(t, e + 1);
|
|
}), gi.add(i), document.body.appendChild(n);
|
|
}
|
|
}, Ct = ({ className: t, type: e, style: i = {}, ...n }) => h("span", { role: "img", className: O("ff-iconfont", t), style: i, ...n, children: h("svg", { style: { width: "1em", height: "1em", fill: "currentColor", overflow: "hidden" }, viewBox: "0 0 1024 1024", children: h("use", { xlinkHref: `#${e}` }) }) });
|
|
Ct.propTypes = { className: b.string, type: b.string.isRequired, style: b.object }, Ct.init = qt;
|
|
const pr = (t, e, i, n) => Ee.redirect(i, e, n), gr = (t, e = {}, i, n = {}) => {
|
|
var a;
|
|
const r = (a = n.router) == null ? void 0 : a.reduce((o, [s, l, u]) => {
|
|
const d = m.get(e, ["router", s]);
|
|
if (!d && d !== 0 && l) throw `请传入 ${u}`;
|
|
return `${o}/${d}`;
|
|
}, `/api/${i}`);
|
|
return I.del(r, e.param).msg();
|
|
}, hi = (t, e, i, { status: { loading: n, disabled: r }, setStatus: a }) => {
|
|
const o = { loading: (s) => s === void 0 ? n : a((l) => ({ ...l, loading: s })), disabled: (s) => s === void 0 ? r : a((l) => ({ ...l, disabled: s })) };
|
|
return m.isFunction(i) ? i.call(null, { ...e, ...o }) : m.isString(i) && i ? Fe.exec(i, e, o) : null;
|
|
}, mi = (t, e, i, n, r) => m.isString(i) && i ? se.getWidgetComponent(i).then(({ default: a }) => ee.modal(a, { ...e, $setting: n }, r != null && r.title ? { ...r, title: m.template(r.title)(t) } : r)).catch((a) => {
|
|
ee.error(i, { content: a.toString() });
|
|
}) : ee.modal(i, { ...e, $setting: n }, r != null && r.title ? { ...r, title: m.template(r.title)(t) } : r), hr = (t, e, i, n, r) => ee.modal(Wi, { ...e, $setting: n, code: i }, r != null && r.title ? { ...r, title: m.template(r.title)(t) } : r), mr = (t, e, i, n, r) => ee.modal(Gt, { base62params: e, $setting: n, listCode: i }, r != null && r.title ? { ...r, title: m.template(r.title)(t) } : r), fr = ({ widget: t, widgetType: e, widgetData: i, widgetProps: n, widgetSetting: r, widgetContainerProps: a }, { onAfterClick: o, onBeforeClick: s } = {}) => {
|
|
const l = le(ne), [u, d] = j({ leading: !0, trailing: !1 }), p = K(() => {
|
|
switch (e) {
|
|
case "redirect":
|
|
return m.partialRight(pr, t, r);
|
|
case "func":
|
|
return m.partialRight(hi, (r == null ? void 0 : r.code) ?? t, { status: u, setStatus: d });
|
|
case "component":
|
|
case "fsdpf-component":
|
|
return m.partialRight(mi, t, r, a);
|
|
case "grid-layout-form":
|
|
return m.partialRight(hr, t, r, a);
|
|
case "data-list":
|
|
return m.partialRight(mr, t, r, a);
|
|
case "destroy":
|
|
return m.partialRight(gr, t, r, a);
|
|
default:
|
|
if (ei(t) || E.isValidElement(t)) return m.partialRight(mi, t, r, a);
|
|
if (m.isFunction(t)) return m.partialRight(hi, (r == null ? void 0 : r.code) || t, { status: u, setStatus: d });
|
|
}
|
|
return (...f) => console.error("useButton unknown widgetType", e, ...f);
|
|
}, [t, e]);
|
|
return [m.debounce((f) => (s == null || s(f), Promise.resolve(lt(n, f, { list: l })).then((g) => p(f, { ...i, ...g })).then((g) => o == null ? void 0 : o(g)).catch(console.error)), 300, { leading: !0, trailing: !1 }), u];
|
|
}, Bi = ({ type: t, name: e, className: i, icon: n, iconPosition: r, size: a }, o = "default") => K(() => {
|
|
const s = { type: "primary", className: O("ff-button", i), iconPosition: r, size: a };
|
|
return t === "danger" ? s.danger = !0 : t === "default" && (s.type = t), o === "link" || o === "dashed" ? (s.type = o, t === "default" && (s.className = O(s.className, "ff-default"))) : o !== "circle" && o !== "round" || (s.shape = o), n && (s.icon = h(Ct, { type: n })), e && (s.children = e), s;
|
|
}, [o, t, i, n, r]), Pt = ({ data: t, widget: e, widgetType: i = "fsdpf-component", widgetData: n, widgetProps: r, widgetSetting: a, widgetContainerProps: o, onAfterClick: s, onBeforeClick: l, children: u, extras: d }) => {
|
|
const p = le(ne), [f, g] = j(!1), [y, w] = j("hover"), [C, k] = j({}), [x, $] = j(), { placement: T, align: F, zIndex: L, arrow: D = { pointAtCenter: !0 }, getPopupContainer: U, isPopupMountBodyContainer: R = !0, ...M } = o || {};
|
|
V(() => {
|
|
i == "grid-layout-form" ? $(E.createElement(Wi, { ...n, $setting: a, code: e })) : i == "data-list" ? $(E.createElement(Gt, { base62params: t, $setting: a, listCode: e })) : m.isString(e) ? se.getWidgetComponent(e).then(({ default: z }) => {
|
|
$(E.createElement(z, { ...n, $setting: a }));
|
|
}).catch((z) => $(z.toString())) : ei(e) ? $(E.createElement(e, { ...n, $setting: a })) : E.isValidElement(e) && $(E.cloneElement(e, { ...n, $setting: a }));
|
|
}, [e, i, n]), V(() => {
|
|
Promise.resolve(lt(r, t, { list: p })).then(k);
|
|
}, [r, t, p.getBase62params]);
|
|
const v = (z, $e = !1) => (g(z), !z && w("hover"), z ? l == null ? void 0 : l(C) : s == null ? void 0 : s($e)), B = (z) => {
|
|
g(!0), w("click");
|
|
};
|
|
return h(fn, { zIndex: L, placement: T, onPopupClick: B, onClick: B, open: f, align: F, arrow: D, trigger: y, getPopupContainer: U || R ? void 0 : (z) => z, content: h(yr, { ...M, extras: d, children: x && E.cloneElement(x, { ...C, $close: (z) => v(!1, z) }) }), children: u, onOpenChange: v });
|
|
}, yr = ({ title: t, className: e, classNames: i, children: n, extras: r, width: a, height: o, ...s }) => {
|
|
const [l, u] = j({}), d = X((y, w) => u((C) => ({ ...C, [y]: w })), []), p = X((y) => u((w) => ({ ...w, [y]: void 0 })), []), f = t ? E.createElement("div", { className: "ff-popup-title" }, t) : l == null ? void 0 : l.title, g = r ?? E.createElement("div", { className: "ff-popup-reserved-extras" }, r);
|
|
return h(st.Provider, { value: { ele: l, mount: d, unmount: p }, children: A("div", { className: O("ff-popup ff-popover", e, l.rootClassName), style: { width: a ?? 260, height: o }, ...s, children: [A("div", { className: O("ff-popup-header", "ff-popover-header", i == null ? void 0 : i.header), children: [f, l == null ? void 0 : l["sub-title"]] }), h("div", { className: O("ff-popup-body", "ff-popover-body", i == null ? void 0 : i.body), children: n }), A("div", { className: O("ff-popup-footer", "ff-popover-footer", i == null ? void 0 : i.footer), children: [g, l == null ? void 0 : l.extras, l == null ? void 0 : l.actions] })] }) });
|
|
};
|
|
Pt.propTypes = { widgetType: b.oneOf(["fsdpf-component", "grid-layout-form", "data-list"]) };
|
|
const ut = (t) => function({ className: e, variant: i, children: n, name: r, icon: a, type: o = "default", iconPosition: s = "start", noAuthType: l, onAfterClick: u, onBeforeClick: d, data: p, loading: f, disabled: g, tooltip: y, confirm: w, widget: C = () => {
|
|
}, widgetType: k, widgetData: x, widgetProps: $, widgetSetting: T, widgetContainerProps: F, ...L }) {
|
|
const { mode: D, ...U } = F || {}, R = Bi({ className: e, name: r, type: o, icon: a, iconPosition: s }, i ?? t), M = h(wt, { ...R, ...L, children: n || r });
|
|
if (D === "popover" && !["destroy", "redirect", "func"].includes(k)) return h(Pt, { data: p, widget: C, widgetType: k, widgetData: x, widgetProps: $, widgetSetting: T, widgetContainerProps: U, onAfterClick: u, onBeforeClick: d, children: M });
|
|
const v = m.isEmpty(y) || !y.enabled ? {} : y, B = m.isEmpty(w) ? { enabled: !1 } : Object.assign({ enabled: !0 }, w), [z, $e] = j(!1), [pt, { disabled: gt, loading: Tt }] = fr({ widget: C, widgetType: k, widgetData: x, widgetProps: $, widgetSetting: T, widgetContainerProps: U }, { onAfterClick: u, onBeforeClick: d });
|
|
return h(yn, { okText: "确定", cancelText: "取消", getPopupContainer: (te) => te, ...B, disabled: gt || g, open: z, onOpenChange: (te) => {
|
|
if (!te) return $e(te);
|
|
B.enabled ? $e(te) : pt(p);
|
|
}, onConfirm: (te) => {
|
|
pt(p, te);
|
|
}, onClick: (te) => {
|
|
te.stopPropagation();
|
|
}, children: h(wn, { getPopupContainer: (te) => te, ...v, title: z ? null : v == null ? void 0 : v.title, trigger: ["hover", "click"], children: E.cloneElement(M, { loading: Tt || f, disabled: gt || g }) }) });
|
|
}, P = ut("default");
|
|
P.propTypes = { type: b.oneOf(["primary", "default", "danger", ""]), size: b.oneOf(["large", "middle", "small"]), name: b.string, icon: b.string, iconPosition: b.oneOf(["start", "end"]), data: b.any, widget: b.any, widgetType: b.oneOf(["destroy", "redirect", "func", "component", "fsdpf-component", "grid-layout-form", "grid-layout", "data-list"]), widgetData: b.object, widgetProps: b.object, widgetSetting: b.object, widgetContainerProps: b.object, tooltip: b.exact({ title: b.string.isRequired, placement: b.oneOf(["top", "left", "right", "bottom", "topLeft", "topRight", "bottomLeft", "bottomRight", "leftTop", "leftBottom", "rightTop", "rightBottom"]), enabled: b.oneOfType([b.bool, b.number]), getPopupContainer: b.func }), confirm: b.exact({ title: b.string.isRequired, cancelText: b.string, okText: b.string, okType: b.oneOf(["primary", "default", "danger", ""]), placement: b.oneOf(["top", "left", "right", "bottom", "topLeft", "topRight", "bottomLeft", "bottomRight", "leftTop", "leftBottom", "rightTop", "rightBottom"]), enabled: b.oneOfType([b.bool, b.number]), getPopupContainer: b.func, arrow: b.oneOfType([b.bool, b.exact({ pointAtCenter: b.bool })]) }) };
|
|
const wr = ut("link"), br = ut("circle"), Cr = ut("round"), kr = ut("dashed"), fi = ({ options: t = [], triggerWeights: e = ["grid-layout-form", "grid-layout", "fsdpf-component", "print"], onAfterClick: i = (g, y, w) => {
|
|
}, onBeforeClick: n = (g, y, w) => {
|
|
}, labelVariant: r = "link", labelSize: a, labelRender: o, btnVariant: s, btnSize: l, btnRender: u = (g, y) => h(P, { ...g, data: y }, g.uuid || jt()), widgetContainerProps: d = {}, children: p, data: f }) => {
|
|
if (m.isEmpty(t)) return p;
|
|
const [g, y] = K(() => (t || []).reduce((C, k) => {
|
|
const x = e.indexOf(k.widgetType);
|
|
return x === -1 ? C[1].push(k) : C[0] ? x < e.indexOf(C[0].widgetType) ? (C[1].push(C[0]), C[0] = k) : C[1].push(k) : C[0] = k, C;
|
|
}, [null, []]), [t, e]);
|
|
o ? p = o(g, f) || p : p || (p = h(wt, { ...Bi(Object.assign(g != null && g.name || g != null && g.icon ? {} : { icon: "icon-location" }, g, { size: a }), r) }));
|
|
const w = y.map((C) => u(Object.assign({ uuid: C.uuid, type: C.type, name: C.name, widget: C.widget, widgetType: C.widgetType, widgetProps: C.widgetProps, widgetData: C.widgetData, widgetSetting: C.widgetSetting, widgetContainerProps: C.widgetContainerSetting, confirm: C.confirm, onAfterClick: m.partialRight(i, C, f), onBeforeClick: m.partialRight(n, C, f) }, { size: l, variant: s }), f));
|
|
return h(Pt, { widget: g == null ? void 0 : g.widget, widgetType: g == null ? void 0 : g.widgetType, widgetProps: g == null ? void 0 : g.widgetProps, widgetSetting: g == null ? void 0 : g.widgetSetting, widgetContainerProps: Object.assign({}, d, g == null ? void 0 : g.widgetContainerProps), data: f, widgetData: g == null ? void 0 : g.widgetData, extras: w, onAfterClick: m.partialRight(i, g, f), onBeforeClick: m.partialRight(n, g, f), children: p });
|
|
};
|
|
fi.propTypes = { triggerWeights: b.array, options: b.arrayOf(b.shape({ ...P.propTypes, widgetType: P.propTypes.widgetType.isRequired })), btnSize: P.propTypes.size, btnRender: b.func, btnVariant: b.oneOf(["", "default", "link", "circle", "round", "dashed"]), labelVariant: b.oneOf(["", "default", "link", "circle", "round", "dashed"]), labelRender: b.func, labelSize: P.propTypes.size, onAfterClick: b.func, onBeforeClick: b.func, widgetContainerProps: P.propTypes.widgetContainerProps, data: P.propTypes.data }, P.Link = wr, P.Link.defaultProps = P.defaultProps, P.Link.propTypes = P.propTypes, P.Circle = br, P.Circle.defaultProps = P.defaultProps, P.Circle.propTypes = P.propTypes, P.Round = Cr, P.Round.defaultProps = P.defaultProps, P.Round.propTypes = P.propTypes, P.Dashed = kr, P.Dashed.defaultProps = P.defaultProps, P.Dashed.propTypes = P.propTypes, P.Popover = Pt, P.GroupPopover = fi;
|
|
const Er = ({ fields: t, formProps: e, $close: i }) => {
|
|
const [n] = ie.useForm(), r = K(() => [{ name: "__PROPS__", value: e }], [e]);
|
|
return h(G, { actions: A(E.Fragment, { children: [h(P, { name: "取消", widget: () => i(!1) }), h(P, { name: "确定", type: "primary", widget: () => n.validateFields(!0).then(i) })] }), children: h(ie, { fields: r, form: n, className: "ff-modal-form", children: t == null ? void 0 : t.map(({ code: a, ...o }) => h(Xt, { code: a, ...o }, a)) }) });
|
|
}, $r = ({ className: t, classNames: e, $close: i, children: n, title: r, subTitle: a, actions: o, extras: s, ...l }) => A(Sn, { ...l, prefixCls: "ff-drawer", className: O("ff-popup", t), maskMotion: { motionAppear: !0, motionName: "mask-motion" }, motion: (u) => ({ motionAppear: !0, motionName: `panel-motion-${u}` }), children: [A("div", { className: O("ff-popup-header", "ff-drawer-header", e == null ? void 0 : e.header), children: [h("button", { "aria-label": "Close", className: O("ff-popup-close", "ff-drawer-close", e == null ? void 0 : e.close), onClick: l.onClose, children: h(Jt, { type: "close" }) }), r, a] }), h("div", { className: O("ff-popup-body", "ff-drawer-body", e == null ? void 0 : e.body), children: n }), A("div", { className: O("ff-popup-footer", "ff-drawer-footer", e == null ? void 0 : e.footer), children: [s, o] })] }), xr = ({ className: t, classNames: e, $close: i, $event: n, children: r, title: a, subTitle: o, actions: s, extras: l, placement: u, ...d }) => {
|
|
const p = (n == null ? void 0 : n.pageX) === void 0 ? { animation: null, maskAnimation: null, mousePosition: { x: null, y: null } } : { animation: "zoom", maskAnimation: "fade", mousePosition: { x: n == null ? void 0 : n.pageX, y: n == null ? void 0 : n.pageY } };
|
|
return h(vn, { ...d, ...p, prefixCls: "ff-modal", modalRender: () => A("div", { className: O("ff-modal-content ff-popup", t), children: [A("div", { className: O("ff-popup-header", "ff-modal-header", e == null ? void 0 : e.header), children: [h("button", { "aria-label": "Close", className: O("ff-popup-close", "ff-modal-close", e == null ? void 0 : e.close), onClick: d.onClose, children: h(Jt, { type: "close" }) }), a, o] }), h("div", { className: O("ff-popup-body", "ff-modal-body", e == null ? void 0 : e.body), children: r }), A("div", { className: O("ff-popup-footer", "ff-modal-footer", e == null ? void 0 : e.footer), children: [l, s] })] }) });
|
|
}, Ui = ({ placement: t, $close: e, $event: i, children: n, title: r, ...a }) => {
|
|
const [o, s] = j({}), [l, u] = j(!0), d = X((y, w) => s((C) => ({ ...C, [y]: w })), []), p = X((y) => s((w) => ({ ...w, [y]: void 0 })), []);
|
|
let f = { ...a, className: o.rootClassName, title: o.title || r && E.createElement("div", { className: O("ff-popup-title") }, r), subTitle: o["sub-title"], actions: o.actions, extras: o.extras, children: n, $close: e, $event: i, onClose: () => u(!1) };
|
|
const g = () => {
|
|
e(!1);
|
|
};
|
|
return h(st.Provider, { value: { ele: o, mount: d, unmount: p }, children: t && t !== "center" ? h($r, { ...f, placement: t, open: l, afterOpenChange: (y) => !y && g() }) : h(xr, { ...f, visible: l, afterClose: g }) });
|
|
};
|
|
Ui.propTypes = { placement: b.oneOf(["center", "left", "top", "right", "bottom"]) };
|
|
const Z = () => {
|
|
const [t, e] = on({ maxCount: 6, motion: { motionName: "ff-notification-fade", motionAppear: !0, motionEnter: !0, motionLeave: !0, onLeaveStart: (a) => {
|
|
const { offsetHeight: o } = a;
|
|
return { height: o };
|
|
}, onLeaveActive: () => ({ height: 0, opacity: 0, margin: 0 }) }, prefixCls: "ff-notification" }), [, i] = E.useReducer((a) => a + 1, 0);
|
|
V(() => {
|
|
Z.$onClick = n, Z.$queue.forEach(([a, o, s], l, u) => {
|
|
r([o, s], ...a), delete u[l];
|
|
});
|
|
}, []);
|
|
const n = (a, o = {}, s = {}) => new Promise((l, u) => r([l, u], a, o, s)), r = ([a, o], s, l = {}, u = {}) => {
|
|
const d = Z.$index++, p = (f) => ((g, y) => (Z.$popups.delete(g), i(), y == null ? void 0 : y()))(d, () => a(f));
|
|
if (s === xi) return t.open({ ...u, key: d, content: E.createElement(s, { ...l, $close: () => t.close(d) }) });
|
|
Z.$popups.set(d, E.createElement(Ui, { maskClosable: !1, $event: l == null ? void 0 : l.$event, ...u, key: d, $close: p }, E.isValidElement(s) ? E.cloneElement(s, { ...l, $close: p }) : s != null && s.name || oi.isForwardRef(s) || (s == null ? void 0 : s.$$typeof) === oi.ForwardRef ? E.createElement(s, { ...l, $close: p }) : s)), i();
|
|
};
|
|
return A(E.Fragment, { children: [Array.from(Z.$popups).map(([a, o]) => o), e] });
|
|
};
|
|
Z.$popups = /* @__PURE__ */ new Map(), Z.$index = 0, Z.$queue = [], Z.$onClick = (...t) => new Promise((e, i) => {
|
|
Z.$queue.push([t, e, i]);
|
|
});
|
|
const yi = (t, e, i = {}) => Z.$onClick(t, e, i), At = (t, { showProgress: e, duration: i, ...n } = { duration: 1.5 }) => Z.$onClick(xi, { content: t, ...n }, { showProgress: e, duration: i }), ee = { modal: yi, confirm: (t, e = {}) => Z.$onClick(Nn, { content: t, ...e }, { placement: "center" }), form: (t, e = {}, i = {}) => yi(Er, { formProps: i, fields: t }, { placement: "center", ...e }).then((n) => {
|
|
if (n === !1) throw !1;
|
|
return n;
|
|
}), notification: At, success: (t, e = { duration: 1.5 }) => At(t, { ...e, className: "ff-notification-success", icon: "check" }), error: (t, e = { duration: 1.5 }) => At(t, { ...e, className: "ff-notification-error", icon: "close" }) };
|
|
Je.configure({ showSpinner: !1 }), Ae.interceptors.request.use((t) => {
|
|
t.headers.Platform = "web", t.headers.SaaS = window.localStorage.getItem("SaaS");
|
|
const e = window.localStorage.getItem(yt);
|
|
return t.headers.Authorization = e ? `Bearer ${e} ` : void 0, Je.inc(), t;
|
|
}, (t) => (Je.done(), Promise.reject({ code: -1, msg: t }))), Ae.interceptors.response.use(({ data: t, headers: e }) => (Je.done(), { ...t, res: e == null ? void 0 : e.res }), function(t) {
|
|
return Je.done(), Promise.reject(t.message);
|
|
}), window.addEventListener("unhandledrejection", It.onUnhandledRejection), It.onMsg = (t, e) => ee[[0, 1].includes(t) ? "success" : "error"](e).then(() => t === 20300 && Ee.redirect(Me.get("Common.WEBSITE_LOGIN_PAGE")));
|
|
var qe, Ve, Ke;
|
|
const J = class J {
|
|
constructor() {
|
|
N(this, "appUrl", "");
|
|
S(this, qe, null);
|
|
return c(J, Ve) || (W(J, Ke, new It()), W(J, Ve, new Proxy(this, { get: (e, i) => i in e ? typeof e[i] == "function" ? e[i].bind(e) : e[i] : c(J, Ke)[i] }))), c(J, Ve);
|
|
}
|
|
init(e, i, n) {
|
|
Ae.defaults.baseURL = this.appUrl = n, Ae.defaults.timeout = 15e3, c(J, Ke).init(e, i, Ae);
|
|
}
|
|
get driver() {
|
|
return Ae;
|
|
}
|
|
mock(e = {}) {
|
|
return c(this, qe) ?? W(this, qe, new sn(Ae, { onNoMatch: "passthrough", ...e }));
|
|
}
|
|
unmock() {
|
|
var e;
|
|
(e = c(this, qe)) == null || e.restore(), W(this, qe, null);
|
|
}
|
|
};
|
|
qe = new WeakMap(), Ve = new WeakMap(), Ke = new WeakMap(), S(J, Ve), S(J, Ke), N(J, "getInstance", () => c(J, Ve) ?? W(J, Ve, new J()));
|
|
let Kt = J;
|
|
const I = Kt.getInstance();
|
|
class Zt extends Error {
|
|
constructor(e, i) {
|
|
super(i), Error.captureStackTrace && Error.captureStackTrace(this, Zt), !i instanceof Ye && (this.name = `${e} Error Runtime`);
|
|
}
|
|
}
|
|
class Ye extends Error {
|
|
constructor(e, ...i) {
|
|
super(...i), Error.captureStackTrace && Error.captureStackTrace(this, Ye), this.name = `${e} Not Found`;
|
|
}
|
|
}
|
|
const Lt = "mine", yt = "token";
|
|
var Re, _e;
|
|
const he = class he {
|
|
constructor() {
|
|
S(this, _e, /* @__PURE__ */ new Map());
|
|
N(this, "setVendor", (e, i) => c(this, _e).set(e, new Ei(i, async (n, r) => {
|
|
var o, s;
|
|
if (!(n != null && n.default)) throw "@pkg not found";
|
|
let a = () => r;
|
|
switch ("function") {
|
|
case typeof (a = (o = n.default) == null ? void 0 : o[`./${r}/index.jsx`]):
|
|
case typeof (a = (s = n.default) == null ? void 0 : s[`./${r}/index.js`]):
|
|
return a();
|
|
}
|
|
throw new Ye(r);
|
|
})));
|
|
N(this, "getWidgetComponent", async (e) => {
|
|
if (!e) throw "getWidgetComponent widget is required";
|
|
if (e != null && e.startsWith("blob:") || e != null && e.startsWith("http:") || e != null && e.startsWith("https:")) return await import(e);
|
|
const [, i] = e == null ? void 0 : e.split("@pkg/");
|
|
if (!i) throw new Ye(e);
|
|
try {
|
|
return c(this, _e).has("pkg") ? await c(this, _e).get("pkg").get(i) : await import(`${I.appUrl}/api/pkg-import/web?name=${e}`);
|
|
} catch (n) {
|
|
throw new Zt(e, n);
|
|
}
|
|
});
|
|
N(this, "getRoutes", () => I.get("/api/my-router").then((e) => [...e, { uuid: "data-list-setting", isLayout: !0, uri: "/data-list-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/DataListSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "grid-layout-setting", isLayout: !0, uri: "/grid-layout-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/GridLayoutSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "grid-layout-form-setting", isLayout: !0, uri: "/grid-layout-form-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/GridLayoutFormSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "resource-api-setting", isLayout: !0, uri: "/resource-api-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/ResourceApiSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "charts-setting", isLayout: !0, uri: "/resource-api-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/ChartsSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "fsm-setting", isLayout: !0, uri: "/fsm-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/FsmSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "component-setting", isLayout: !0, uri: "/component-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/ff-design/components/ComponentSetting", extra: { layout: "@pkg/ff-design/frameworks/DesignTheme" } }, { uuid: "login", uri: "/login", name: "登录", type: "fsdpf-component", isLogin: !1, component: "@pkg/ff/components/Login" }, { uuid: "not-found", uri: "*", name: "Not Found", type: "fsdpf-component", isLogin: !1, component: "@pkg/ff/components/NotFound" }].map(({ uuid: i, ...n }) => [i, { uuid: i, ...n }])).then((e) => new Map(e)));
|
|
N(this, "getMenus", () => I.get("/api/my-menu"));
|
|
N(this, "getConfigure", () => I.get("api/init-configure"));
|
|
N(this, "getWidgetOperationAuth", () => I.get("/api/init-widget-operation-auth").then((e) => e.reduce((i, { uuid: n, auth: r }) => [...i, [n, r]], [])));
|
|
N(this, "getPhoneNumber", (e) => I.get(`/api/user-wx-phone-number/${e}`));
|
|
N(this, "getUserToken", () => {
|
|
const e = window.localStorage.getItem(yt);
|
|
if (!e) return "";
|
|
const i = e.split(".");
|
|
if (!Array.isArray(i) || i.length !== 3) throw "登录令牌无效!";
|
|
const { iat: n } = JSON.parse(window.atob(i[1]));
|
|
if (Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - n > 2592e3) throw "登录令牌已过期, 请重新登录!";
|
|
return e;
|
|
});
|
|
N(this, "checkUserToken", () => {
|
|
try {
|
|
return !!this.getUserToken();
|
|
} catch {
|
|
return !1;
|
|
}
|
|
});
|
|
N(this, "getUserInfo", (e = !0) => {
|
|
var i;
|
|
try {
|
|
const n = this.getUserToken();
|
|
if (!n) return Promise.resolve(null);
|
|
const { iat: r } = JSON.parse(window.atob((i = n == null ? void 0 : n.split(".")) == null ? void 0 : i[1])), { iat: a, ...o } = I.decode(window.localStorage.getItem(Lt) || "", {});
|
|
return a === r ? Promise.resolve(o) : I.get("/api/mine-info").then(({ User: s = null }) => (window.localStorage.setItem(Lt, I.encode({ ...s, iat: r })), s));
|
|
} catch (n) {
|
|
console.error(n), e && ee.error("请登录").then(this.logout);
|
|
}
|
|
return Promise.resolve(null);
|
|
});
|
|
N(this, "login", (e, i, n = {}) => I.post("/api/user-token", { username: e, passwd: ln.hash(i), platform: "web", ...n }).then(({ token: r }) => (window.localStorage.setItem(yt, r), r)).then(async (r) => (await this.initAppEnv(), r)));
|
|
N(this, "logout", (e) => (window.localStorage.removeItem(Lt), window.localStorage.removeItem(yt), e == null ? void 0 : e()));
|
|
N(this, "initAppEnv", async () => {
|
|
const [e, i, n, r] = await Promise.all([this.getWidgetOperationAuth(), this.getRoutes(), this.getMenus(), this.getConfigure()]);
|
|
return Si.init(e), Me.init(r), Ee.init(i, n), Ct.init(Me.get("Common.ICONFONT")), { widgetOperationAuth: e, routes: i, menus: n, configures: r };
|
|
});
|
|
if (c(he, Re)) return c(he, Re);
|
|
}
|
|
};
|
|
Re = new WeakMap(), _e = new WeakMap(), S(he, Re, null), N(he, "getInstance", () => (c(he, Re) || W(he, Re, new he()), c(he, Re)));
|
|
let _t = he;
|
|
const se = _t.getInstance(), Sr = E.createContext({ user: {}, initUser: () => {
|
|
}, initUserComplete: !1 }), vr = E.createContext({ set: () => {
|
|
}, get: () => {
|
|
}, assign: () => {
|
|
}, currentRoute: () => {
|
|
} }), ei = (t) => !!(t != null && t.name) && (t.prototype instanceof E.Component || /^[A-Z]/.test(t.name)), Nr = (t, e) => {
|
|
if (!t || typeof window > "u") return;
|
|
let i = document.querySelector(`style[ff-style-token="${e}"]`);
|
|
return i ? (i.innerHTML = t, t) : (i = document.createElement("style"), i.setAttribute("ff-style-token", e), i.setAttribute("type", "text/css"), i.innerHTML = t, document.head.appendChild(i), t);
|
|
}, Pr = Object.freeze(Object.defineProperty({ __proto__: null, AppContext: Sr, AppGlobalParamsContext: vr, cache: Ei, configure: Me, default: se, func: Fe, http: I, insertStyle: Nr, isReactComponent: ei, route: Ee }, Symbol.toStringTag, { value: "Module" }));
|
|
var Ce, He, ke, me, fe, Q, Y, H, ye, it, nt, rt, at, vt, ot;
|
|
const ti = class ti {
|
|
constructor(e, i = "/") {
|
|
S(this, Ce, "/");
|
|
S(this, He, /* @__PURE__ */ new Set());
|
|
S(this, ke, (e) => {
|
|
for (const i of c(this, He)) try {
|
|
i(e);
|
|
} catch (n) {
|
|
console.error("Error in VirtualFS event listener:", n);
|
|
}
|
|
});
|
|
S(this, me, (e) => {
|
|
const i = Date.now();
|
|
if (e && (e.lastModified = i), c(this, Ce) != "/") {
|
|
const n = c(this, H).call(this, c(this, Ce));
|
|
n && (n.lastModified = i);
|
|
}
|
|
this.root.lastModified = i;
|
|
});
|
|
S(this, fe, (e) => {
|
|
let i = ce.normalize(e);
|
|
return i.startsWith("/") || (i = "/" + i), i.length > 1 && i.endsWith("/") && (i = i.slice(0, -1)), i;
|
|
});
|
|
S(this, Q, (e) => {
|
|
const i = ce.join(c(this, Ce), e);
|
|
return c(this, fe).call(this, i);
|
|
});
|
|
S(this, Y, (e) => {
|
|
if (!e || typeof e != "string") return !1;
|
|
const i = c(this, fe).call(this, e);
|
|
return !i.includes("..") && i.startsWith("/");
|
|
});
|
|
S(this, H, (e) => {
|
|
var a;
|
|
const i = c(this, fe).call(this, e);
|
|
if (i === "/") return this.root;
|
|
const n = i.split("/").filter((o) => o);
|
|
let r = this.root;
|
|
for (const o of n) {
|
|
if (r.type !== "dir") return null;
|
|
const s = (a = r.children) == null ? void 0 : a.find((l) => l.name === o);
|
|
if (!s) return null;
|
|
r = s;
|
|
}
|
|
return r;
|
|
});
|
|
S(this, ye, (e) => {
|
|
const i = c(this, fe).call(this, e), n = ce.basename(i), r = ce.dirname(i);
|
|
return { parent: c(this, H).call(this, r), name: n };
|
|
});
|
|
S(this, it, (e, i, n) => n === !1 ? e : n === "root" ? e.map((r) => ce.join(i, r)) : n === !0 || n === "working" ? e.map((r) => ce.relative(c(this, Ce), ce.join(i, r))) : e);
|
|
S(this, nt, async (e, i, n, r = "") => {
|
|
const a = [], o = c(this, H).call(this, e);
|
|
if (!o || o.type !== "dir") return a;
|
|
const s = o.children;
|
|
for (const l of s) {
|
|
const u = l.name, d = e === "/" ? `/${u}` : `${e}/${u}`, p = r ? `${r}/${u}` : u;
|
|
try {
|
|
if (l.type === "file") i(n ? p : u) && a.push(p);
|
|
else if (l.type === "dir" && n) {
|
|
const f = await c(this, nt).call(this, d, i, n, p);
|
|
a.push(...f);
|
|
}
|
|
} catch {
|
|
continue;
|
|
}
|
|
}
|
|
return a;
|
|
});
|
|
S(this, rt, async (e, i, n, r = "") => {
|
|
const a = [], o = Array.isArray(i) ? i : [i], s = c(this, H).call(this, e);
|
|
if (!s || s.type !== "dir") return a;
|
|
if (!n) {
|
|
for (const u of o) if (c(this, at).call(this, u)) {
|
|
const d = await c(this, vt).call(this, e, u);
|
|
a.push(...d);
|
|
} else {
|
|
const d = ce.join(e, u), p = c(this, fe).call(this, d);
|
|
c(this, H).call(this, p) && a.push(u);
|
|
}
|
|
return a;
|
|
}
|
|
const l = s.children;
|
|
for (const u of l) {
|
|
const d = u.name, p = e === "/" ? `/${d}` : `${e}/${d}`, f = r ? `${r}/${d}` : d;
|
|
try {
|
|
if (u.type === "file") for (const g of o) {
|
|
let y = !1;
|
|
if (y = c(this, at).call(this, g) ? c(this, ot).call(this, d, g) : d === g, y) {
|
|
a.push(f);
|
|
break;
|
|
}
|
|
}
|
|
else if (u.type === "dir") {
|
|
const g = await c(this, rt).call(this, p, i, n, f);
|
|
a.push(...g);
|
|
}
|
|
} catch {
|
|
continue;
|
|
}
|
|
}
|
|
return a;
|
|
});
|
|
S(this, at, (e) => /[*?[\]{}]/.test(e));
|
|
S(this, vt, async (e, i) => {
|
|
const n = [], r = c(this, H).call(this, e);
|
|
if (!r || r.type !== "dir") return n;
|
|
const a = r.children.map((o) => o.name);
|
|
for (const o of a) c(this, ot).call(this, o, i) && n.push(o);
|
|
return n;
|
|
});
|
|
S(this, ot, (e, i) => {
|
|
const n = i.replace(/\./g, "\\.").replace(/\*/g, ".*").replace(/\?/g, ".").replace(/\{([^}]+)\}/g, (r, a) => "(" + a.split(",").join("|") + ")");
|
|
return new RegExp(`^${n}$`).test(e);
|
|
});
|
|
var n, r, a;
|
|
W(this, Ce, i), this.root = { name: "/", type: "dir", children: [], lastModified: Date.now() }, Array.isArray(e) ? this.root.children = e : e && typeof e == "object" && (e.name && e.name !== "/" ? this.root.children.push(e) : (this.root = e, (n = this.root).name ?? (n.name = "/"), (r = this.root).children ?? (r.children = []), (a = this.root).lastModified ?? (a.lastModified = Date.now())));
|
|
}
|
|
async stat(e) {
|
|
const i = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, i)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const n = c(this, H).call(this, i);
|
|
if (!n) throw new Error(`ENOENT: no such file or directory, stat '${e}'`);
|
|
return { isFile: () => n.type === "file", isDirectory: () => n.type === "dir", lastModified: n.lastModified };
|
|
}
|
|
async dir(e) {
|
|
const i = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, i)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const n = c(this, H).call(this, i);
|
|
if (!n) throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);
|
|
if (n.type !== "dir") throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);
|
|
return n.children.map((r) => r.name);
|
|
}
|
|
async readFile(e) {
|
|
const i = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, i)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const n = c(this, H).call(this, i);
|
|
if (!n) throw new Error(`ENOENT: no such file or directory, open '${e}'`);
|
|
if (n.type !== "file") throw new Error("EISDIR: illegal operation on a directory, read");
|
|
return n.content || "";
|
|
}
|
|
async writeFile(e, i) {
|
|
const n = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, n)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const { parent: r, name: a } = c(this, ye).call(this, n);
|
|
if (!r) throw new Error(`ENOENT: no such file or directory, open '${e}'`);
|
|
if (r.type !== "dir") throw new Error("ENOTDIR: not a directory");
|
|
const o = r.children.findIndex((u) => u.name === a), s = o >= 0, l = { name: a, type: "file", content: i, lastModified: Date.now() };
|
|
s ? r.children[o] = l : r.children.push(l), c(this, me).call(this, r), c(this, ke).call(this, { action: s ? "update" : "create", path: n, type: "file", timestamp: Date.now() });
|
|
}
|
|
async mkdir(e, i = {}) {
|
|
const n = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, n)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const { recursive: r } = i;
|
|
if (r) {
|
|
const a = n.split("/").filter((s) => s);
|
|
let o = "/";
|
|
for (const s of a)
|
|
if (o = ce.join(o, s), !c(this, H).call(this, o)) {
|
|
const { parent: l, name: u } = c(this, ye).call(this, o);
|
|
if (l && l.type === "dir") {
|
|
const d = { name: u, type: "dir", children: [], lastModified: Date.now() };
|
|
l.children.push(d), c(this, me).call(this, l), c(this, ke).call(this, { action: "create", path: c(this, fe).call(this, o), type: "dir", timestamp: Date.now() });
|
|
}
|
|
}
|
|
} else {
|
|
const { parent: a, name: o } = c(this, ye).call(this, n);
|
|
if (!a) throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);
|
|
if (a.type !== "dir") throw new Error("ENOTDIR: not a directory");
|
|
if (a.children.find((l) => l.name === o)) throw new Error(`EEXIST: file already exists, mkdir '${e}'`);
|
|
const s = { name: o, type: "dir", children: [], lastModified: Date.now() };
|
|
a.children.push(s), c(this, me).call(this, a), c(this, ke).call(this, { action: "create", path: n, type: "dir", timestamp: Date.now() });
|
|
}
|
|
}
|
|
async unlink(e) {
|
|
const i = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, i)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const { parent: n, name: r } = c(this, ye).call(this, i);
|
|
if (!n) throw new Error(`ENOENT: no such file or directory, unlink '${e}'`);
|
|
const a = n.children.findIndex((o) => o.name === r);
|
|
if (a < 0) throw new Error(`ENOENT: no such file or directory, unlink '${e}'`);
|
|
if (n.children[a].type !== "file") throw new Error(`EISDIR: illegal operation on a directory, unlink '${e}'`);
|
|
n.children.splice(a, 1), c(this, me).call(this, n), c(this, ke).call(this, { action: "delete", path: i, type: "file", timestamp: Date.now() });
|
|
}
|
|
async rmdir(e, i = {}) {
|
|
const n = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, n)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const { parent: r, name: a } = c(this, ye).call(this, n);
|
|
if (!r) throw new Error(`ENOENT: no such file or directory, rmdir '${e}'`);
|
|
const o = r.children.findIndex((l) => l.name === a);
|
|
if (o < 0) throw new Error(`ENOENT: no such file or directory, rmdir '${e}'`);
|
|
const s = r.children[o];
|
|
if (s.type !== "dir") throw new Error(`ENOTDIR: not a directory, rmdir '${e}'`);
|
|
if (!i.recursive && s.children.length > 0) throw new Error(`ENOTEMPTY: directory not empty, rmdir '${e}'`);
|
|
r.children.splice(o, 1), c(this, me).call(this, r), c(this, ke).call(this, { action: "delete", path: n, type: "dir", timestamp: Date.now() });
|
|
}
|
|
async rename(e, i) {
|
|
const n = c(this, Q).call(this, e), r = c(this, Q).call(this, i);
|
|
if (!c(this, Y).call(this, n)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
if (!c(this, Y).call(this, r)) throw new Error(`EINVAL: invalid path '${i}'`);
|
|
if (!c(this, H).call(this, n)) throw new Error(`ENOENT: no such file or directory, rename '${e}' -> '${i}'`);
|
|
const { parent: a, name: o } = c(this, ye).call(this, n), { parent: s, name: l } = c(this, ye).call(this, r);
|
|
if (!s) throw new Error(`ENOENT: no such file or directory, rename '${e}' -> '${i}'`);
|
|
if (c(this, H).call(this, r)) throw new Error(`EEXIST: file already exists, rename '${e}' -> '${i}'`);
|
|
const u = a.children.findIndex((p) => p.name === o), d = { ...a.children[u], name: l, lastModified: Date.now() };
|
|
a.children.splice(u, 1), s.children.push(d), c(this, me).call(this, a), a !== s && c(this, me).call(this, s), c(this, ke).call(this, { action: "rename", path: r, oldPath: n, type: d.type, timestamp: Date.now() });
|
|
}
|
|
async exists(e) {
|
|
const i = c(this, Q).call(this, e);
|
|
return c(this, Y).call(this, i) ? c(this, H).call(this, i) !== null : !1;
|
|
}
|
|
getLastModified() {
|
|
return this.root.lastModified;
|
|
}
|
|
subscribe(e) {
|
|
if (typeof e != "function") throw new Error("Callback must be a function");
|
|
return c(this, He).add(e), () => {
|
|
c(this, He).delete(e);
|
|
};
|
|
}
|
|
getWorkingDirectory() {
|
|
return c(this, Ce);
|
|
}
|
|
scope(e = "/") {
|
|
const i = c(this, fe).call(this, e);
|
|
if (!c(this, Y).call(this, i)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const n = c(this, H).call(this, i);
|
|
if (!n) throw new Error(`ENOENT: no such file or directory '${e}'`);
|
|
if (n.type !== "dir") throw new Error(`ENOTDIR: not a directory '${e}'`);
|
|
return n.children ?? (n.children = []), n.lastModified ?? (n.lastModified = Date.now()), new ti(this.root, i);
|
|
}
|
|
async findFiles(e, i, n = {}) {
|
|
const r = c(this, Q).call(this, e);
|
|
if (!c(this, Y).call(this, r)) throw new Error(`EINVAL: invalid path '${e}'`);
|
|
const a = c(this, H).call(this, r);
|
|
if (!a) throw new Error(`ENOENT: no such file or directory '${e}'`);
|
|
if (a.type !== "dir") throw new Error(`ENOTDIR: not a directory '${e}'`);
|
|
const { recursive: o = !1, fullPath: s = !1 } = n;
|
|
if (typeof i == "function") {
|
|
const u = await c(this, nt).call(this, r, i, o);
|
|
return c(this, it).call(this, u, r, s);
|
|
}
|
|
const l = await c(this, rt).call(this, r, i, o);
|
|
return c(this, it).call(this, l, r, s);
|
|
}
|
|
};
|
|
Ce = new WeakMap(), He = new WeakMap(), ke = new WeakMap(), me = new WeakMap(), fe = new WeakMap(), Q = new WeakMap(), Y = new WeakMap(), H = new WeakMap(), ye = new WeakMap(), it = new WeakMap(), nt = new WeakMap(), rt = new WeakMap(), at = new WeakMap(), vt = new WeakMap(), ot = new WeakMap();
|
|
let wi = ti;
|
|
const Tr = async (t, e = "/", i = "") => {
|
|
try {
|
|
const n = await t.stat(e), r = e === "/" ? "/" : ce.basename(e), a = { title: r, key: i ? `${i}${e}` : e, isLeaf: n.isFile() };
|
|
if (n.isDirectory()) {
|
|
const o = await t.dir(e);
|
|
if (o.length > 0) {
|
|
a.children = [];
|
|
const s = [], l = [];
|
|
for (const u of o) {
|
|
const d = e === "/" ? `/${u}` : `${e}/${u}`;
|
|
try {
|
|
(await t.stat(d)).isDirectory() ? s.push(u) : l.push(u);
|
|
} catch (p) {
|
|
console.warn(`Failed to stat ${d}:`, p.message);
|
|
}
|
|
}
|
|
s.sort(), l.sort();
|
|
for (const u of [...s, ...l]) {
|
|
const d = e === "/" ? `/${u}` : `${e}/${u}`;
|
|
try {
|
|
const p = await Tr(t, d, i);
|
|
a.children.push(p);
|
|
} catch (p) {
|
|
console.warn(`Failed to process ${d}:`, p.message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return a;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
export {
|
|
Nt as $,
|
|
Ai as A,
|
|
Fi as B,
|
|
_n as C,
|
|
bt as D,
|
|
Kn as E,
|
|
Un as F,
|
|
aa as G,
|
|
Jn as H,
|
|
Gt as I,
|
|
ne as J,
|
|
Hn as K,
|
|
Zn as L,
|
|
Dn as M,
|
|
Wn as N,
|
|
jn as O,
|
|
In as P,
|
|
ta as Q,
|
|
Li as R,
|
|
ia as S,
|
|
Oi as T,
|
|
zt as U,
|
|
Vn as V,
|
|
Mn as W,
|
|
er as X,
|
|
tr as Y,
|
|
oa as Z,
|
|
sa as _,
|
|
vi as a,
|
|
la as a0,
|
|
ca as a1,
|
|
ct as a2,
|
|
dt as a3,
|
|
da as a4,
|
|
ua as a5,
|
|
ur as a6,
|
|
Qt as a7,
|
|
Xt as a8,
|
|
Wi as a9,
|
|
Ee as aA,
|
|
Sr as aB,
|
|
vr as aC,
|
|
wi as aD,
|
|
Tr as aE,
|
|
nr as aa,
|
|
rr as ab,
|
|
ar as ac,
|
|
or as ad,
|
|
sr as ae,
|
|
lr as af,
|
|
pa as ag,
|
|
Ct as ah,
|
|
P as ai,
|
|
Si as aj,
|
|
fr as ak,
|
|
G as al,
|
|
st as am,
|
|
$i as an,
|
|
Z as ao,
|
|
ee as ap,
|
|
Hr as aq,
|
|
Jr as ar,
|
|
Yr as as,
|
|
se as at,
|
|
ei as au,
|
|
Nr as av,
|
|
I as aw,
|
|
Ei as ax,
|
|
Me as ay,
|
|
Fe as az,
|
|
Tn as b,
|
|
lt as c,
|
|
Ni as d,
|
|
Xr as e,
|
|
Qr as f,
|
|
Pn as g,
|
|
Zr as h,
|
|
On as i,
|
|
Fn as j,
|
|
ea as k,
|
|
Ri as l,
|
|
Rn as m,
|
|
na as n,
|
|
Yt as o,
|
|
ji as p,
|
|
Mi as q,
|
|
Ft as r,
|
|
Xn as s,
|
|
oe as t,
|
|
Gr as u,
|
|
Vi as v,
|
|
Yn as w,
|
|
Gn as x,
|
|
ra as y,
|
|
Ii as z
|
|
};
|