UNPKG

ng-layout-form

Version:

layout form

229 lines (227 loc) 7.09 kB
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/util/util.tsx var util_exports = {}; __export(util_exports, { LayConfWrap: () => import_ng_lib_tsx.LayConfWrap, fomatValues: () => fomatValues, formFomatValues: () => formFomatValues, getComp: () => getComp, getCompPorps: () => getCompPorps, getObjValue: () => getObjValue, getProperty: () => getProperty, getSubscribeFn: () => getSubscribeFn, isHelpField: () => isHelpField, listToObj: () => listToObj, parseFunction: () => parseFunction, setObjValue: () => setObjValue }); module.exports = __toCommonJS(util_exports); var import_ng_lib_tsx = require("ng-lib-tsx"); var import_baseConfig = require("../config/baseConfig"); var emptyArray = []; function getComp(item) { if (!item.xtype) return { instance: import_baseConfig.Comp_Info["NGInput"].instance }; if (typeof item.xtype === "function") return { instance: item.xtype }; if (item.xtype && typeof item.xtype === "object" && item.xtype.render && item.xtype.$$typeof) return { instance: item.xtype }; return function(_type) { const type = import_ng_lib_tsx.helpXtypeRef[_type] || _type; if (import_baseConfig.Comp_Info[type]) { if (["Input", "NGInput"].includes(type) && ["prc", "amt", "amount", "qty", "rate", "percent"].includes(item.type) && import_baseConfig.Comp_Info["NGInputNumber"]) { return { instance: import_baseConfig.Comp_Info["NGInputNumber"].instance, props: import_baseConfig.Comp_Info["NGInputNumber"].defaultProps }; } return { instance: import_baseConfig.Comp_Info[type].instance, props: import_baseConfig.Comp_Info[type].defaultProps }; } const ins = (0, import_ng_lib_tsx.getRegisterComponent)(type, _type); if (ins) { return { instance: ins, props: (0, import_ng_lib_tsx.getRegisterComponentProps)(type, _type) }; } else if (import_ng_lib_tsx.businessHelpRef[type]) { const { type: helpType, ...others } = import_ng_lib_tsx.businessHelpRef[type]; return { instance: (0, import_ng_lib_tsx.getRegisterComponent)(helpType), props: { ...others, ...(0, import_ng_lib_tsx.getRegisterComponentProps)(helpType) } }; } return { instance: import_baseConfig.Comp_Info["NGInput"].instance }; }(item.xtype); } function getCompPorps(item, config, commonPropsType) { const p = config; let t = Object.keys(p).reduce((acc, curr) => { acc[curr] = item[curr] ? item[curr] : p[curr]["defaultValue"]; return acc; }, item.antProps || {}); p["data"] && (t["data"] = (item == null ? void 0 : item.data) || emptyArray); (item.xtype === "ngCheckbox" || item.xtype === "Checkbox") && delete t.value; return t; } function fomatValues(name, type, opt, key, initVals) { let vals = initVals; return merge; function merge(values) { if (typeof vals !== typeof values) { vals = values || vals; } else if (Array.isArray(vals)) { vals = vals.concat(values); } else if (typeof vals === "object") { vals = { ...vals, ...values }; } else { vals = values; } if (!values) return { [name]: { [type]: vals ? { key, [opt]: vals } : { key } } }; return merge; } } function formFomatValues(key, initVals) { let vals = {}; let optType = "newRow"; if (Object.prototype.toString.call(initVals) === "[object Object]") { initVals = [initVals]; } if (Array.isArray(initVals)) { vals = initVals.reduce((p, n) => ({ ...p, ...n }), {}); return { ["form"]: { key, [vals[key] ? "modifiedRow" : "newRow"]: vals } }; } return merge; function merge(values) { if (typeof vals !== typeof values) { vals = values || vals; } else if (Array.isArray(vals)) { vals = vals.concat(values); } else if (typeof vals === "object") { vals = { ...vals, ...values }; } else { vals = values; } if (!values) { return { ["form"]: vals ? { key, [optType]: vals } : { key } }; } if (values[key]) optType = "modifiedRow"; return merge; } } function listToObj(c) { if (!c) return {}; return c.reduce((acc, item) => { acc[item.name] = item; return acc; }, {}); } function getProperty(o, keys) { if (typeof keys === "string" || typeof keys === "number") { return o && o[keys]; } for (let i = 0; i < keys.length; i++) { if (!o) return; o = o[keys[i]]; } return o; } function parseFunction(str) { if (str && typeof str === "string") { return (...args) => { try { const fn = new Function("return " + str)(); return fn(...args); } catch (error) { console.log("erro:======", error, str); } }; } return str; } function getObjValue(obj, pathKeys) { return import_ng_lib_tsx.NG.getObjValue(obj, pathKeys); } function setObjValue(obj, pathKeys, value) { import_ng_lib_tsx.NG.setObjValue(obj, pathKeys, value); } function getSubscribeFn(outRef) { return (fn, type, name) => { var _a, _b, _c, _d; if (!outRef.current._compIns) { return () => { }; } if (name && name.length > 0) { const arr = import_ng_lib_tsx.NG.isArray(name) ? name : [name]; const loop = (obj, prevKey = "") => Object.keys(obj).some((k) => { if (import_ng_lib_tsx.NG.isObject(obj[k]) && loop(obj[k], k)) { return true; } return arr.includes(prevKey ? `${prevKey}.${k}` : k); }); return (_b = (_a = outRef.current).innerSubscribe) == null ? void 0 : _b.call( _a, (p) => { fn({ ...p, name }); }, type, ({ args }) => loop(args[0]) ); } else { return (_d = (_c = outRef.current).innerSubscribe) == null ? void 0 : _d.call(_c, fn, type); } }; } function isHelpField(type) { var _a; return import_ng_lib_tsx.NG.isString(type) && ((_a = (0, import_ng_lib_tsx.getRegisterComponent)(type)) == null ? void 0 : _a.isHelp); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { LayConfWrap, fomatValues, formFomatValues, getComp, getCompPorps, getObjValue, getProperty, getSubscribeFn, isHelpField, listToObj, parseFunction, setObjValue });