From 9a670acf154186d83fa3b0299c045555da507a8b Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Thu, 2 Jul 2026 15:36:03 +0200 Subject: [PATCH] js-maker integration --- info.rkt | 1 + racket-webview.rkt | 67 ++++++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/info.rkt b/info.rkt index 6dc2900..f390dc1 100644 --- a/info.rkt +++ b/info.rkt @@ -28,6 +28,7 @@ "web-server-lib" "net-cookies-lib" "simple-log" + "js-maker" ) ) diff --git a/racket-webview.rkt b/racket-webview.rkt index 8872415..cc523b9 100644 --- a/racket-webview.rkt +++ b/racket-webview.rkt @@ -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)) ;)))