Skip to content

feat: adds initial file drag and drop functionality - #376

Merged
itsdouges merged 18 commits into
pmndrs:mainfrom
noel-schenk:main
Jan 21, 2026
Merged

feat: adds initial file drag and drop functionality#376
itsdouges merged 18 commits into
pmndrs:mainfrom
noel-schenk:main

Conversation

@noel-schenk

@noel-schenk noel-schenk commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Hey @itsdouges amazing software you have created! We want to use it for this year's Global Game Jam.

We figured it would be nice to be able to drag and drop components into scenes. This PR adds an initial version of that.
I would suggest not merging it, as it still has some issues and flaws. But I wanted to first thank you very much for this wonderful extension and second, maybe help contribute a bit for a future feature.

Closes #43

@vercel

vercel Bot commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

@noel-schenk is attempting to deploy a commit to the Triplex Team on Vercel.

A member of the Team first needs to authorize it.

@itsdouges

itsdouges commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator

sweet! appreciate the contribution, where do you see the major points are to look at in the PR that need work? could you annotate the PR with comments on interesting piece of code / behavior / anything? video walk through would go a treat as well

tldr what do we need to do to get this merged?

@noel-schenk

noel-schenk commented Jan 8, 2026

Copy link
Copy Markdown
Contributor Author

Sure, :) currently working and then some holiday, but after, before the GGJ, I might have some time to fix more.

  • Currently the scene rendering needs a padding for the drag and drop because the iframe captures the drag and drop event.
  • Export default does not work it needs to be a named export
  • Imports are full path and not relative
  • The component gets added at the end of the first export that is found in the scene file
  • Multiple components can't get added in one drag n drop they need to be added individually

Probably more issues I haven't found yet.

Recording.2026-01-08.143251.mp4

@itsdouges

Copy link
Copy Markdown
Collaborator

oh cool I like that it uses native vscode drag and drop, good work so far! I'll x-link this to discord

@itsdouges

itsdouges commented Jan 9, 2026

Copy link
Copy Markdown
Collaborator

Currently the scene rendering needs a padding for the drag and drop because the iframe captures the drag and drop event.

we should be able to do something about this

Export default does not work it needs to be a named export

easy enough fix, default could select the first component on drop, then a have hotkey to show a UI to select a specific one?

Imports are full path and not relative

easy enough to massage this

The component gets added at the end of the first export that is found in the scene file

do you think we could immediately add the component during the drag when it hits the scene and then you can position it while still dragging?

Multiple components can't get added in one drag n drop they need to be added individually

like if you drag multiple files? is this a limitation or something we can code around to add them all at the same time?

@Bellian

Bellian commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

I took over the PR now.
Fixed the following issues:

  • Imports are relative now
  • The renderer now also accept the DND.
    This resolves the iframe issue.
    In the long run we might do things like preview the model while draging, place where the mouse cursor points to etc.
    But for this i need some feedback how the communication from the server back works @itsdouges
  • Default exports are supported and prefered.
    If a file has multiple components but a default export, the default export will be added to the current scene.
  • Added support for vscode remote drag and drop (for example WSL).

- implemented requestVSCE. Sends data to server and awaits the response.
- implemented component select. If the imported file contains multiple component and no default component, you can select wich item to add.
- fixed name collisions. The there is already a 'Scene' in the current file and you want to import a component names 'Scene' it gets aliased to 'Scene_1', 'Scene_2' etc
@Bellian

Bellian commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Improved drag and drop:

  • implemented requestVSCE. Sends data to server and awaits the response.
  • implemented component select. If the imported file contains multiple component and no default component, you can select wich item to add.
  • fixed name collisions. The there is already a 'Scene' in the current file and you want to import a component names 'Scene' it gets aliased to 'Scene_1', 'Scene_2' etc

@Bellian

Bellian commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

@itsdouges Do you mind having a look and get some feedback?
Would be a blast having this for the game Jam at the end of the month XD

@itsdouges

itsdouges commented Jan 17, 2026

Copy link
Copy Markdown
Collaborator

im trying to push commits to your remote branch but can't, do you have contributors not being allowed to push set? going to fix some formatting and then go over the code

@itsdouges

itsdouges commented Jan 17, 2026

Copy link
Copy Markdown
Collaborator

@Bellian great fix where you can drop it immediately after "dropping" it into the triplex editor (after pressing shift)!

{...bindingsDND}
>
{errorData && errorData.type === 'unknown' && (
<Dialog onDismiss={onDismissError}>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having our own error dialog can we use the error toasts in vscode? There should be a bridge message to trigger for it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this https://github.com/pmndrs/triplex/blob/main/packages/@triplex/editor-next/src/util/bridge.ts#L112 but if we are only waiting for the response for the error I reckon delete all this and show a vscode native toast instead

async updateCode(
data:
| {
code: string;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix all the formatting changes? Check your IDE is using the prettier from triplex

return await document.insertComponent(data);
}),
on(panel.webview, "send-request", async ({ data, event, id }) => {
const results = await execCallback(event, data);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we only waiting for the result to see if we have to show an error? If so we can just show a vscode toast message instead rather that having to round trip back through the editor.

Would let us delete a lot of code as well

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also sends the information what components are abke to load for the select dialog.
If a file has more than 1 export and no defaukt export there is a promt to select the imported component.

{errorData && errorData.type === 'multiple-exports' && (
<Dialog onDismiss={onDismissError}>
<form className="flex flex-col gap-2.5 p-2.5" onSubmit={onSubmit}>
<span className="text-heading select-none font-medium">

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see an error could be this. I want to look what we have available during a drag because it would be cool if we can start checking before the user drops 🤔

}

if (!componentFile) {
throw new DNDError(`Component file not found: ${componentPath}`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just throw a standard error. Whats the need to subclass?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently for typing because of the multiple compnent data.

export function resolveRemoteURL(path: string) {
if (path.startsWith('vscode-remote://')) {
// we hav a remote file drop!
path = path.replace(/vscode-remote:\/\/[^/]*/, 'file://');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me more about how vscode remote files work with triplex

Comment thread packages/lib/src/use-dnd.ts Outdated
}


export function useDND(sendCallback: any, activeScene: string, scenePath: string) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anys will be a lint violation

Comment thread packages/lib/src/use-dnd.ts Outdated
e.stopPropagation();
};

const handleDragEnter = (e: DragEvent<HTMLDivElement>) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hooks is pretty specific to the vscode dnd. Does the renderer need the dnd logic or can the editor take care of it for now?

<Tunnel.Out />
<DebugAttributes />
{isDragging && (
<div

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't doing anything anymore right

}): Scene | null {

if (modules == undefined || modules == null) {
return null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I regulary got en error loading stuff here. Do not know precisely what went wrong.
Got a "try to access prop of undefined"

@itsdouges

itsdouges commented Jan 18, 2026

Copy link
Copy Markdown
Collaborator

@Bellian I have some changes to push

  • fix formatting
  • use pragmatic drag and drop instead of custom (this will let us also drag and drop into the element tree later)
  • remove vsce request logic and replace it with calls using useSubscription (removes possibility for stale content)
  • remove renderer dnd (we can't get drag data before drop so no point having any dnd logic here)
  • consolidate on the existing "/scene/:path/:exportName/object" api to add components to a scene (if there's any bugs we can fix it there)

all good if I push here?

@noel-schenk

Copy link
Copy Markdown
Contributor Author

@itsdouges sure I've added you as a collaborator to the branch :)

Sorry for the delay we are in a totally different time zone :D

@itsdouges

itsdouges commented Jan 18, 2026

Copy link
Copy Markdown
Collaborator

hey folks I pushed a few changes, my main goal was to try and reduce the total amount of code we needed to add for this feature. here's what I did:

  • use client side checks instead of server side (e.g. gets the export name from the client side then sends it to the server to add)
  • use subscriptions instead of the custom request API, let's us keep things fresh if the data changes when the select component dialog is shown :-) and is more familiar with the rest of the codebase
  • use pragmatic dnd for the dropzone, which lets us have a story for adding support for dragging a component as a child to an element in the element tree as a follow up - where we already use pdnd!
  • use the pre-existing add API instead of a new one, sorry to delete a lot of code as this was the bulk of your PR but most of the logic is already there, if there's edge cases or bugs we need to handle now can you add them to the "/scene/:path/:exportName/object" API please?
  • tweaked the select compenent UI
  • removed dnd drop zone from the renderer, since we can't get the data during a drag there's no need to keep it there
  • fixed some edge cases, dragging the same component into the scene, disabling iframe pointer events during a drag

can you test and let me know how it goes? and if there's any issues feel free to push some fixes.

I haven't applied the vscode-remote file stuff, feels like there is a bigger story for triplex to properly support it.. maybe? e.g. can you open a remote file in triplex today? would love a contribution to make that overarching story better, i've never actually used those kinds of files before.

@vercel

vercel Bot commented Jan 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
triplex-cloud Ignored Ignored Preview Jan 21, 2026 11:22am
triplex-docs Ignored Ignored Preview Jan 21, 2026 11:22am

@itsdouges
itsdouges merged commit d233b75 into pmndrs:main Jan 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drag & drop to add components to a scene

3 participants