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