UNPKG

@zhsz/cool-design-crud

Version:

77 lines (76 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const lodashEs = require("lodash-es"); const index = require("./index.js"); function processItem(item, fieldNames = { value: "value", label: "label", children: "children" }) { const outputItem = {}; if (index.isObject(item)) { for (const key in fieldNames) { outputItem[key] = item[fieldNames[key]]; } if (item[fieldNames.children] && item[fieldNames.children].length > 0) { outputItem.children = item[fieldNames.children].map( (s) => processItem(s, fieldNames) ); } return lodashEs.pickBy(outputItem, (value) => value !== void 0); } else { for (const key in fieldNames) { if (key !== "children") { outputItem[key] = item; } } return lodashEs.pickBy(outputItem, (value) => value !== void 0); } } function extractDefaultsRecursively(source, result = {}) { for (const key in source) { const node = source[key]; if (node.type === "void" && node.properties) { extractDefaultsRecursively(node.properties, result); } else { result[key] = node.default !== void 0 ? node.default : void 0; } } return result; } function processProperties(properties, formHook, form, type) { for (const prop in properties) { const property = properties[prop]; if (property.hook) { formHook[type]({ hook: property.hook, prop, value: form[prop], form }); } if (property.type === "void" && property.properties) { processProperties(property.properties, formHook, form, type); } else if (property.properties) { iterateProperties(property.properties, formHook, form, type); } } } function iterateProperties(properties, formHook, form, type) { for (const prop in properties) { const property = properties[prop]; if (property.type !== "void") { formHook[type]({ hook: property.hook, prop, value: form[prop], form }); } else if (property.properties) { processProperties(property.properties, formHook, form, type); } } } exports.extractDefaultsRecursively = extractDefaultsRecursively; exports.processItem = processItem; exports.processProperties = processProperties;