mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 13:05:08 +09:00
29 lines
657 B
TypeScript
29 lines
657 B
TypeScript
import ObjectId from "bson-objectid";
|
|
import { type Style, type Instance } from "@webstudio-is/sdk";
|
|
import { primitives } from "~/shared/component";
|
|
|
|
export const createInstance = ({
|
|
component,
|
|
id,
|
|
children,
|
|
style,
|
|
}: {
|
|
component: Instance["component"];
|
|
id?: Instance["id"];
|
|
children?: Instance["children"];
|
|
style?: Style;
|
|
}): Instance => {
|
|
const primitive = primitives[component];
|
|
return {
|
|
component,
|
|
id: id === undefined ? ObjectId().toString() : id,
|
|
style: style ?? {},
|
|
children:
|
|
children === undefined
|
|
? "children" in primitive
|
|
? primitive.children
|
|
: []
|
|
: children,
|
|
};
|
|
};
|