Skip to content

bug(wasm): pageDropTarget is a no-op — drag-and-drop image attachment disabled on web #189

Description

@tstapler

Summary

pageDropTarget (kmp/src/wasmJsMain/kotlin/dev/stapler/stelekit/ui/components/PageDropTarget.kt) returns the unmodified Modifier on WASM. Dragging an image file onto a page on the web target does nothing.

Root cause

Compose Multiplatform for WASM renders entirely into a single <canvas> element. HTML5 drag events (dragenter, dragover, drop) fire on the canvas DOM element, not on individual Compose composables. There is no supported Compose WASM API to intercept these events and route them into the onFilesDropped: (List<Any>) -> Unit callback.

The JVM implementation uses AWT DropTarget which maps natively into the component hierarchy — that mechanism doesn't exist on WASM.

Proposed fix

Add a JS drop event listener on document.querySelector('canvas') (or the Compose viewport element), extract the DataTransfer.files list, read each file as an ArrayBuffer, and post the result back to a Kotlin-side callback via a shared channel (e.g., a Channel<List<JsAny>> consumed by a coroutine in Main.kt). This requires threading the callback through Main.kt and connecting it to the modifier via a CompositionLocal.

Affected files

  • kmp/src/wasmJsMain/kotlin/dev/stapler/stelekit/ui/components/PageDropTarget.kt
  • kmp/src/commonMain/kotlin/dev/stapler/stelekit/ui/components/PageDropTargetModifier.kt
  • kmp/src/wasmJsMain/kotlin/dev/stapler/stelekit/browser/Main.kt

Labels

bug, platform: web, needs-design

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions