@magicbe/design
Version:
React + Antd Drag Drop Visual design
39 lines (38 loc) • 1.94 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment, useMemo } from "react";
import { SchemaUtil } from "../utils/schema";
import { SchemaContextProvider } from "./Context";
import Widget from "./Widget";
import { find } from "lodash";
import { DATA_WIDGET } from "../utils/const";
import { useDesignContext } from "../context";
/**递归渲染组件 */
export var DeepRenderComponent = function (props) {
var schemas = props.schemas;
return (_jsx(Fragment, { children: schemas === null || schemas === void 0 ? void 0 : schemas.map(function (schema) { return (_jsx(SchemaContextProvider, __assign({ value: { schema: schema } }, { children: _jsx(SchemaComponent, __assign({}, schema)) }), schema.uuid)); }) }));
};
/**渲染组件 */
export var SchemaComponent = function (_a) {
var _b;
var widget = _a.widget, group = _a.group, uuid = _a.uuid, properties = _a.properties;
var _c = useDesignContext().schemas, schemas = _c === void 0 ? [] : _c;
var widgets = SchemaUtil.getWidgets();
var Component = useMemo(function () { return find(widgets, { widget: widget, group: group }); }, [schemas]);
var target_attr = (_b = {}, _b[DATA_WIDGET] = uuid, _b);
var nexts = useMemo(function () { return schemas.filter(function (_a) {
var parent = _a.parent;
return parent === uuid;
}); }, [schemas, uuid]);
return (_jsx(Widget, __assign({}, __assign(__assign({}, properties), target_attr), { Component: Component, widget: widget, slot: _jsx(DeepRenderComponent, { schemas: nexts }) })));
};