js-maker integration

This commit is contained in:
2026-07-02 15:36:03 +02:00
parent d71f326d88
commit 9a670acf15
2 changed files with 36 additions and 32 deletions
+1
View File
@@ -28,6 +28,7 @@
"web-server-lib"
"net-cookies-lib"
"simple-log"
"js-maker"
)
)
+35 -32
View File
@@ -398,12 +398,9 @@
(define-syntax with-id->el
(syntax-rules (<-)
((_ <- id el e1 ...)
(js/expression (let ((el (send document getElementById (inject id))))
e1 ...)))
(syntax-rules ()
((_ id el e1 ...)
(js (let ((el (send document getElementById (inject id))))
(js (let ((el (send document getElementById (eval id))))
e1 ...)))
)
)
@@ -433,7 +430,7 @@
(syntax-rules ()
((_ selector func)
(js
(return (send window rkt_with_selector (inject selector) func))))
(return (send window rkt_with_selector (eval selector) func))))
)
)
; (format "return window.rkt_with_selector('~a', ~a)"
@@ -588,22 +585,26 @@
(define/contract (webview-set-menu! wv menu)
(-> wv-win? is-wv-menu? symbol?)
(let* ((json (wv-menu->json menu))
(js (string-append "window._web_wire_menu('"
json
"');"))
(js-code (js (send window _web_wire_menu (eval json))))
;(string-append "window._web_wire_menu('"
; json
; "');"))
)
(webview-run-js wv js)
(webview-run-js wv js-code)
)
)
(define/contract (webview-popup-menu! wv menu x y)
(-> wv-win? is-wv-menu? number? number? symbol?)
(let* ((json (wv-menu->json menu))
(js (string-append "window._web_wire_popup_menu(JSON.parse('"
json "'), " (format "~a, ~a" x y)
");"))
(js-code (js (send window _web_wire_popup_menu
(send JSON parse (eval json))
(eval x) (eval y))))
;(string-append "window._web_wire_popup_menu(JSON.parse('"
; json "'), " (format "~a, ~a" x y)
; ");"))
)
(webview-run-js wv js)))
(webview-run-js wv js-code)))
(define (loglevel? x)
(and (symbol? x)
@@ -633,8 +634,10 @@
(define/contract (webview-navigate! wv place)
(-> wv-win? string? symbol?)
(webview-run-js wv
(format "window.location = '~a';"
(esc-quote place))))
(js (set! (js-dot window location) (eval place)))
;(format "window.location = '~a';"
; (esc-quote place))))
))
(define/contract (webview-base-url wv)
(-> wv-win? url?)
@@ -803,9 +806,9 @@
(-> wv-win? symbol? (or/c string? xexpr?) symbol?)
(if (string? html)
(let ((r (webview-call-js wv
(with-id->el <- id el
(with-id->el id el
(set! (js-dot el innerHTML) (eval html))
#t))))
(return #t)))))
;(with-id id el
; ("el.innerHTML = '~a'; return true;"
; (esc-quote html))))))
@@ -822,10 +825,10 @@
(= (js-dot el type) "checkbox")
(= (js-dot el type) "radio"))
(set! (js-dot el checked)
(inject
(eval
(if (eq? val #f) #f #t)))
(set! (js-dot el value)
(inject
(eval
(cond
((g:date? val) (date->string val))
((g:time? val) (time->string val))
@@ -865,11 +868,11 @@
(define/contract (webview-value wv id)
(-> wv-win? symbol? (or/c string? boolean?))
(let ((v (webview-call-js wv
(with-id->el <- id el
(with-id->el id el
(if (or (= (js-dot el type) "checkbox")
(= (js-dot el type) "radio"))
(js-dot el checked)
(js-dot el value))))))
(return (js-dot el checked))
(return (js-dot el value)))))))
;(with-id id el
; ((string-append "let f = function() {\n"
; " if (el.type == 'checkbox' || el.type == 'radio') {\n"
@@ -915,13 +918,13 @@
)
(webview-call-js wv (with-selector sel
(λ (id el)
(let ((cl (inject cl)))
(let ((cl (eval cl)))
(send cl forEach
(λ (c)
(send (js-dot el classList) add c)
)
)
id)))
(return id))))
)
)
)
@@ -949,7 +952,7 @@
(webview-call-js wv
(with-selector sel
(λ (id el)
(let ((cl (inject cl)))
(let ((cl (eval cl)))
(send cl forEach
(λ (c)
(send (js-dot el classList) remove c))))
@@ -986,7 +989,7 @@
(webview-call-js wv
(with-selector sel
(λ (id el)
(let ((cl (inject cl)))
(let ((cl (eval cl)))
(send cl forEach
(λ (st)
(set! (js-ref
@@ -1025,7 +1028,7 @@
(let ((r (webview-call-js wv
(with-selector sel
(λ (id el)
(let ((cl (inject cl))
(let ((cl (eval cl))
(r (make-hash)))
(send cl forEach
(λ (st)
@@ -1075,7 +1078,7 @@
(webview-call-js wv
(with-selector sel
(λ (id el)
(let ((cl (inject cl)))
(let ((cl (eval cl)))
(send cl forEach
(λ (st)
(set! (js-ref
@@ -1122,7 +1125,7 @@
(webview-call-js wv
(with-selector sel
(λ (id el)
(let ((cl (inject cl)))
(let ((cl (eval cl)))
(send cl forEach
(λ (av)
(send el setAttribute (js-ref av 0)
@@ -1148,8 +1151,8 @@
(define/contract (webview-attr wv id attr)
(-> wv-win? symbol? (or/c symbol? string?) (or/c string? boolean?))
(let ((v (webview-call-js wv
(with-id->el <- id el
(send el getAttribute (eval attr))))))
(with-id->el id el
(return (send el getAttribute (eval attr)))))))
;(with-id id el
; -> (format "el.getAttribute('~a');" attr))
;)))