2023-12-01 11:52:37 +08:00
|
|
|
import {apply as json_logic_apply} from "json-logic-js";
|
2023-11-30 17:26:17 +08:00
|
|
|
import {componentsList} from "./components/components";
|
|
|
|
import {true_type_of} from "./utils";
|
|
|
|
|
|
|
|
export function ProcessOptions({options, data, target, id}) {
|
|
|
|
let options_t = true_type_of(options);
|
|
|
|
|
|
|
|
if (options_t === "array") {
|
|
|
|
return Array.from(
|
|
|
|
options.map((option_item, i) => ProcessOptions({
|
|
|
|
options: option_item,
|
|
|
|
data: data,
|
|
|
|
target: target,
|
|
|
|
id: id + i
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
} else if (options_t === "object") {
|
|
|
|
if (
|
|
|
|
true_type_of(options.type) === "string" &&
|
|
|
|
(true_type_of(options.args) === "object" || true_type_of(options.items) === "array")
|
|
|
|
) {
|
|
|
|
if (options.type in componentsList) {
|
|
|
|
return componentsList[options.type](target, id + options.type, data, options.args);
|
|
|
|
} else if (options.type === "Group") {
|
|
|
|
return (
|
|
|
|
<div className="border rounded" key={id + "group"}>
|
|
|
|
{ProcessOptions({
|
2023-12-01 11:52:37 +08:00
|
|
|
options: json_logic_apply(options.items, data),
|
2023-11-30 17:26:17 +08:00
|
|
|
data: data,
|
|
|
|
target: target,
|
|
|
|
id: id
|
|
|
|
})}
|
|
|
|
</div>);
|
|
|
|
} else {
|
|
|
|
return componentsList["Default"](options.type, id + "missing");
|
|
|
|
}
|
|
|
|
} else {
|
2023-12-01 11:52:37 +08:00
|
|
|
return ProcessOptions({options: json_logic_apply(options, data), data: data, target: target, id: id});
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|