UNPKG

@magicbe/design

Version:

React + Antd Drag Drop Visual design

49 lines (48 loc) 1.81 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { v4 } from "uuid"; import { find, isFunction, flattenDeep } from "lodash"; var SchemaUtil = /** @class */ (function () { function SchemaUtil() { } SchemaUtil.generatorId = function () { return v4().replace(/\-/g, ""); }; SchemaUtil.setWidgets = function (widgets) { SchemaUtil.widgets = widgets; }; SchemaUtil.getWidgets = function () { return SchemaUtil.widgets; }; SchemaUtil.createSchemas = function (component, parent, properties) { if (properties === void 0) { properties = {}; } if (!component) return []; if (!isFunction(component)) return SchemaUtil.createSchemas(find(SchemaUtil.widgets, component), parent); var next_component = component; var widget = next_component.widget, group = next_component.group, _a = next_component.slots, slots = _a === void 0 ? [] : _a; var schema = { uuid: SchemaUtil.generatorId(), widget: widget, group: group, properties: properties, title: widget, parent: parent, }; var next_slots = slots.map(function (component) { return SchemaUtil.createSchemas(component, schema.uuid); }); return __spreadArray([schema], flattenDeep(next_slots), true); }; SchemaUtil.widgets = []; return SchemaUtil; }()); export { SchemaUtil };