fix: maplibre reactive signal bugs and stale signal re-push #3

Merged
ryan merged 3 commits from worktree-datastar-research into main 2026-02-20 18:31:27 +00:00

3 Commits

Author SHA1 Message Date
Ryan Hamamura
3c3ce57055 fix: signal-backed marker reactivity and stale signal re-push
Some checks failed
CI / Build and Test (push) Failing after 35s
CI / Build and Test (pull_request) Failing after 31s
Two issues discovered during testing:

1. data-effect expressions for signal-backed markers short-circuited
   before reading $signalID when the map hadn't loaded yet. Datastar
   never tracked those signals as dependencies, so the effect never
   re-ran. Fix: read signal values unconditionally before the guard.

2. prepareSignalsForPatch never reset changed=false on regular signals
   (only computed ones), causing every SyncSignals() call to re-push
   all signals — including stale server-side values for the draggable
   pin, overwriting the client-side drag position.
2026-02-20 08:29:24 -10:00
Ryan Hamamura
b2474bf79d fix: draggable pin writeback and click-to-place event collision
Three related bugs in the maplibre reactive signal plumbing:

1. Draggable marker coordinates never updated because dragendHandlerJS
   queries for hidden inputs matching LngSignal/LatSignal IDs, but
   Element() never rendered those inputs. Add them after the marker
   data-effect divs.

2. Click-to-place marker didn't appear until moveend because Element()
   rendered a bare hidden input for each event signal, colliding with
   the user's action-bearing input (same data-bind, querySelector finds
   the bare one first). Remove the internal event inputs — the user
   provides their own via MapEvent.Input().

3. The moveend handler dispatched 'input' on ALL data-bind inputs in
   the wrapper, accidentally triggering event inputs. Add an else-return
   so only the 5 viewport signal inputs get dispatched.
2026-02-20 08:29:24 -10:00
Ryan Hamamura
7eb86999b2 feat: refactor maplibre for reactive signals and Via-native API
- Export Signal type (signal → Signal) so subpackages can reference it
- Expose viewport signals as public fields (CenterLng, CenterLat, Zoom,
  Bearing, Pitch) for .Text() display and .Bind() usage
- Add signal-backed marker positions (LngSignal/LatSignal) with
  data-effect reactivity for server push and dragend writeback
- Add event system (MapEvent, OnClick, OnLayerClick, OnMouseMove,
  OnContextMenu) using hidden inputs + action triggers
- Add Source interface replacing type-switch, with RawSource escape hatch
- Add CameraOptions for FlyTo/EaseTo/JumpTo/FitBounds/Stop
- Add Control interface with NavigationControl, ScaleControl,
  GeolocateControl, FullscreenControl
- Expand Options with interaction toggles, MaxBounds, and Extra map
- Add effectspike example to validate data-effect with server-pushed signals
- Update maplibre example to showcase all new features
2026-02-20 08:29:24 -10:00