ng-layout-form
Version:
layout form
99 lines (97 loc) • 4.07 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/tabPanel/index.tsx
var tabPanel_exports = {};
__export(tabPanel_exports, {
default: () => tabPanel_default
});
module.exports = __toCommonJS(tabPanel_exports);
var import_ng_lib_tsx = require("ng-lib-tsx");
var import_react = require("react");
var import_baseConfig = require("../config/baseConfig");
var import_util = require("../util/util");
var import_index = require("./index.less");
function TabPanelComp(props) {
const { formConf, outRef, type = "line", forceRender, panelHeight, ...others } = props;
const [panes, setPanes] = (0, import_react.useState)(() => []);
const [activeKey, setActiveKey] = (0, import_ng_lib_tsx.useRefValue)(props.activeKey, props.defaultActiveKey);
(0, import_react.useEffect)(() => {
var _a;
const p = (Array.isArray(formConf) ? formConf : formConf.children || []).map((item) => {
item["key"] = item.id;
return item;
});
setPanes(p);
p.every(({ key }) => key !== activeKey) && setActiveKey((_a = p[0]) == null ? void 0 : _a.key);
}, [formConf]);
const onInnerChange = (0, import_ng_lib_tsx.useRefCallback)((key) => {
var _a;
setActiveKey(key);
(_a = props.onChange) == null ? void 0 : _a.call(props, key);
});
const getItems = () => {
const childArray = import_ng_lib_tsx.NG.flatArray(props.children || []);
const t = childArray.reduce((acc, it) => {
const tabId = it.props && it.props["data-tabid"] || it.key;
tabId && (acc[tabId] = it);
return acc;
}, {});
const getChildItem = (item) => {
if (t[item.id]) {
return t[item.id];
} else {
const Comp = (import_baseConfig.Comp_Info[item.xtype] || item.xtype && (0, import_ng_lib_tsx.getRegisterComponent)(item.xtype) && {
instance: (0, import_ng_lib_tsx.getRegisterComponent)(item.xtype)
} || { instance: item.xtype }).instance;
if (import_baseConfig.Comp_Info[item.xtype])
return /* @__PURE__ */ React.createElement(Comp, { config: item });
return import_ng_lib_tsx.NG.isFunction(Comp) ? /* @__PURE__ */ React.createElement(Comp, { config: item }) : Comp;
}
};
return panes.filter((p) => !p.hidden).map((pane) => {
var _a;
const contentItemProps = ((_a = t[pane.id]) == null ? void 0 : _a.props) || {};
return {
label: pane.title,
key: pane.id,
forceRender: contentItemProps["data-forceRender"] || pane.forceRender || forceRender,
children: /* @__PURE__ */ React.createElement("div", { style: { minHeight: contentItemProps.panelHeight || pane.height || panelHeight } }, getChildItem(pane))
};
});
};
return /* @__PURE__ */ React.createElement(
import_ng_lib_tsx.NGTabs,
{
...others,
type,
ref: outRef,
fitHeight: true,
size: "small",
onChange: onInnerChange,
activeKey: activeKey + "",
style: props.style,
className: import_ng_lib_tsx.NG.classNames("ng-tab-panel", props.className),
items: getItems()
}
);
}
var TabPanel = (0, import_ng_lib_tsx.compHoc)((0, import_util.LayConfWrap)(TabPanelComp));
var tabPanel_default = TabPanel;
(0, import_ng_lib_tsx.registerComponent)({ TabPanel });
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});