mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
15 lines
415 B
TypeScript
15 lines
415 B
TypeScript
import ObjectId from "bson-objectid";
|
|
import produce from "immer";
|
|
import { type Instance } from "@webstudio-is/sdk";
|
|
|
|
const updateIds = (instance: Instance) => {
|
|
instance.id = ObjectId().toString();
|
|
for (const child of instance.children) {
|
|
if (typeof child === "string") continue;
|
|
updateIds(child);
|
|
}
|
|
};
|
|
|
|
export const cloneInstance = (instance: Instance): Instance =>
|
|
produce(updateIds)(instance);
|