Add event bindings and data-sx-emit processing
- adapter-dom.sx: detect :on-click/:on-submit etc. in render-dom-element — if attr starts with "on-" and value is callable, wire via dom-listen - orchestration.sx: add process-emit-elements for data-sx-emit attrs — auto-dispatch custom events on click with optional JSON detail - bootstrap_js.py: add processEmitElements RENAME - Regenerate sx-ref.js with all changes - Update reactive-islands status table Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1087,10 +1087,11 @@
|
||||
(mark-processed! el "verb")
|
||||
(process-one el)))
|
||||
els))
|
||||
;; Also process boost, SSE, inline handlers
|
||||
;; Also process boost, SSE, inline handlers, emit attributes
|
||||
(process-boosted root)
|
||||
(process-sse root)
|
||||
(bind-inline-handlers root)))
|
||||
(bind-inline-handlers root)
|
||||
(process-emit-elements root)))
|
||||
|
||||
|
||||
(define process-one
|
||||
@@ -1104,6 +1105,40 @@
|
||||
(bind-preload-for el))))))
|
||||
|
||||
|
||||
;; --------------------------------------------------------------------------
|
||||
;; data-sx-emit — auto-dispatch custom events for lake→island bridge
|
||||
;; --------------------------------------------------------------------------
|
||||
;;
|
||||
;; Elements with data-sx-emit="event-name" get a click listener that
|
||||
;; dispatches a CustomEvent with that name. Optional data-sx-emit-detail
|
||||
;; provides JSON payload.
|
||||
;;
|
||||
;; Example:
|
||||
;; <button data-sx-emit="cart:add"
|
||||
;; data-sx-emit-detail='{"id":42,"name":"Widget"}'>
|
||||
;; Add to Cart
|
||||
;; </button>
|
||||
;;
|
||||
;; On click → dispatches CustomEvent "cart:add" with detail {id:42, name:"Widget"}
|
||||
;; The event bubbles up to the island container where bridge-event catches it.
|
||||
|
||||
(define process-emit-elements
|
||||
(fn (root)
|
||||
(let ((els (dom-query-all (or root (dom-body)) "[data-sx-emit]")))
|
||||
(for-each
|
||||
(fn (el)
|
||||
(when (not (is-processed? el "emit"))
|
||||
(mark-processed! el "emit")
|
||||
(let ((event-name (dom-get-attr el "data-sx-emit")))
|
||||
(when event-name
|
||||
(dom-listen el "click"
|
||||
(fn (e)
|
||||
(let ((detail-json (dom-get-attr el "data-sx-emit-detail"))
|
||||
(detail (if detail-json (json-parse detail-json) (dict))))
|
||||
(dom-dispatch el event-name detail))))))))
|
||||
els))))
|
||||
|
||||
|
||||
;; --------------------------------------------------------------------------
|
||||
;; History: popstate handler
|
||||
;; --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user