react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
196 lines (195 loc) • 4.89 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { List } from "./list/index.js";
import { C, a, D, F, I, b, b as b2, R, S, c, T } from "./Switch-pL2VHH0m.js";
import { S as S2 } from "./Section-ColPnZCN.js";
import { L } from "./Loader-DiwrlZ4F.js";
import { G, P } from "./Post-DGMrLEoA.js";
import { A, M, P as P2, b as b3, a as a2 } from "./ProtectedRoute-Bh9R7Iat.js";
import { G as G2, d, M as M2, U, u, b as b4, c as c2, a as a3 } from "./MainContext-CrnhXpyN.js";
import { c as c3, u as u2, b as b5, a as a4 } from "./useForm-nHibry26.js";
import { u as u3 } from "./useAccess-DsPOTmRD.js";
import { A as A2 } from "./Protected-x1KgaSB5.js";
import { Formula } from "./formula/index.js";
import { A as A3, a as a5 } from "./ActionButton-CzHgTuNE.js";
import { B as BaseBuilder } from "./BaseBuilder-dOpE6Uh1.js";
import { jsx, Fragment } from "react/jsx-runtime";
import React from "react";
class Condition extends BaseBuilder {
constructor() {
super(...arguments);
__publicField(this, "_items", []);
__publicField(this, "_default");
__publicField(this, "_data");
}
/**
* Add a conditional item
*/
add(key, condition, content) {
this._items.push({ key, condition, content });
return this;
}
/**
* Add a condition with content (fluent API)
*/
when(condition, content) {
this._items.push({ condition, content });
return this;
}
/**
* Set default content when no conditions match
*/
default(content) {
this._default = content;
return this;
}
/**
* Alias for default()
*/
otherwise(content) {
return this.default(content);
}
/**
* Set data to evaluate conditions against
*/
data(value) {
this._data = value;
return this;
}
/**
* Check which condition matches and return its content
*/
_resolveContent() {
for (const item of this._items) {
if (item.condition(this._data)) {
return typeof item.content === "function" ? item.content() : item.content;
}
}
if (this._default) {
return typeof this._default === "function" ? this._default() : this._default;
}
return null;
}
/**
* Clear all conditions
*/
clear() {
this._items = [];
this._default = void 0;
return this;
}
/**
* Get count of conditions
*/
count() {
return this._items.length;
}
/**
* Render the matching content
*/
render() {
if (this._config.hidden) {
return null;
}
return this._resolveContent();
}
}
class ConditionGroup extends BaseBuilder {
constructor() {
super(...arguments);
__publicField(this, "_conditions", /* @__PURE__ */ new Map());
__publicField(this, "_activeKeys", []);
}
/**
* Add a named condition
*/
add(key, condition, content) {
this._conditions.set(key, { key, condition, content });
return this;
}
/**
* Check conditions and update active items
*/
checkCondition(data) {
this._activeKeys = [];
for (const [key, item] of this._conditions.entries()) {
if (item.condition(data)) {
this._activeKeys.push(key);
}
}
return this;
}
/**
* Get currently active condition keys
*/
getActiveKeys() {
return [...this._activeKeys];
}
/**
* Clear all conditions
*/
clear() {
this._conditions.clear();
this._activeKeys = [];
return this;
}
/**
* Render all matching conditions
*/
render() {
if (this._config.hidden) {
return null;
}
return /* @__PURE__ */ jsx(Fragment, { children: this._activeKeys.map((key, index) => {
const item = this._conditions.get(key);
if (!item) return null;
const content = typeof item.content === "function" ? item.content() : item.content;
return /* @__PURE__ */ jsx(React.Fragment, { children: content }, key || index);
}) });
}
}
export {
A2 as AccessGuard,
A3 as Action,
a5 as ActionButton,
A as AppLayout,
BaseBuilder,
C as Checkbox,
a as CheckboxGroup,
Condition,
ConditionGroup,
D as DatePicker,
F as FormFieldBuilder,
Formula,
G as Get,
G2 as GlobalStore,
I as Input,
List,
L as Loader,
M as Main,
d as MainContext,
M2 as MainProvider,
P as Post,
P2 as ProfileMenu,
b3 as Protected,
a2 as ProtectedRoute,
b as Radio,
b2 as RadioGroup,
R as RangePicker,
S2 as Section,
S as Select,
c as Switch,
T as TextArea,
U as UserState,
u3 as useAccess,
c3 as useForm,
u2 as useGet,
b5 as useList,
u as useMain,
a4 as usePost,
b4 as useStore,
c2 as useStoreActions,
a3 as useUser
};
//# sourceMappingURL=index.js.map