editor icon indicating copy to clipboard operation
editor copied to clipboard

feature request: duplicate project

Open kleenkanteen opened this issue 8 months ago • 8 comments

I would like to duplicate a public project and then work off of it. Ok if I take a crack at this?

kleenkanteen avatar Mar 24 '26 05:03 kleenkanteen

@anton-pascal any thoughts before I start implementing it?

kleenkanteen avatar Mar 25 '26 04:03 kleenkanteen

Hey @kleenkanteen, thanks for the interest! Happy to share some thoughts on how this could work.

The editor package itself is client-side only — it doesn't handle project storage or CRUD directly. The scene data is a SceneGraph ({ nodes, rootNodeIds }) that the host app manages via the onSave callback and the applySceneGraphToEditor() function.

So "duplicate project" would need to happen at the host/integration level rather than inside the editor package. That said, there are a couple of things the editor could expose to make this easier:

  1. Scene serialization — we already have SceneGraph as a clean export type and applySceneGraphToEditor() to load it. A getSceneGraph() / snapshot utility that deep-clones the current scene with fresh node IDs would be the main editor-side contribution.

  2. ID regeneration — when duplicating, all node IDs need to be regenerated while preserving parent-child relationships (buildings → levels → walls/items/zones etc). This is the tricky part since references between nodes (e.g. items attached to walls, zones referencing levels) need to be remapped correctly.

  3. The actual "duplicate" button/flow — this would live in the host app, not the editor package, since it involves creating a new project record in whatever backend the host uses.

If you want to contribute to the editor package specifically, the most useful piece would be a cloneSceneGraph(sceneGraph: SceneGraph): SceneGraph utility in packages/core that:

  • Deep clones all nodes
  • Generates new UUIDs for every node
  • Remaps all internal references (parentId, children arrays, etc.)
  • Returns a clean SceneGraph ready to be saved as a new project

Would you like to take that approach? Happy to review a PR.

anton-pascal avatar Mar 25 '26 04:03 anton-pascal

@anton-pascal Thanks for the guidance, I'll take a crack at it asap

kleenkanteen avatar Mar 25 '26 20:03 kleenkanteen

@anton-pascal Are new UUIDs for every node necessary to achieve duplication? My understanding is that it's not if these 2 cases are true:

  1. The backend does not require all UUIDs to be globally unique
  2. The frontend only loads in one scene at a time

Given this, does it still make sense to create a cloneSceneGraph util?

kleenkanteen avatar Mar 26 '26 00:03 kleenkanteen

Good question! You're right that if both of those hold, a plain deep clone would technically work without ID conflicts.

That said, I'd still recommend regenerating IDs as the default behavior for a few reasons:

  1. Host app assumptions vary — we can't know what backends consumers use. Some might store node IDs globally (across projects) for analytics, cross-project references, or collaboration features. Same IDs in two projects would break those.

  2. Future-proofing — even if a host app only loads one scene at a time today, features like project comparison, merge, or multi-tab editing could surface later. Unique IDs across projects keep that door open.

  3. It's the safer default — generating fresh UUIDs is cheap, and it means the cloned scene is truly independent with no hidden coupling to the original.

That said, we could make it a parameter: cloneSceneGraph(scene, { regenerateIds?: boolean }) defaulting to true. That way hosts that know they don't need it can skip the remapping. But I'd still implement the full ID regeneration + reference remapping as the primary path since that's where the real utility value is.

Does that make sense? Happy to answer more questions as you dig in.

anton-pascal avatar Mar 26 '26 00:03 anton-pascal

Will take a shot at it then. Btw am curious do you pass my questions through a llm first?

kleenkanteen avatar Mar 26 '26 00:03 kleenkanteen

@anton-pascal ready for review: #178

kleenkanteen avatar Mar 26 '26 04:03 kleenkanteen

Resolved by #178 — cloneSceneGraph() is now available as a public export from @pascal-app/core.

open-pascal avatar Mar 28 '26 22:03 open-pascal