js transformer enhanced and focus method added in wv-element
This commit is contained in:
@@ -254,6 +254,27 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define (make-eval-result v)
|
||||
(cond
|
||||
((or (symbol? v) (string? v))
|
||||
(format "\"~a\"" (esc-double-quote (format "~a" v))))
|
||||
((list? v)
|
||||
(string-append "[ "
|
||||
(string-join (map make-eval-result v) ", ")
|
||||
" ]"))
|
||||
((number? v)
|
||||
(format "~a" v))
|
||||
(else
|
||||
(error "Not supported result by js-eval, supported: string, symbol, number or list of previous")
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(define-syntax js-eval
|
||||
(syntax-rules ()
|
||||
((_ v)
|
||||
(make-eval-result v))))
|
||||
|
||||
(define-for-syntax js-ops '(+ * / - and or send list cons))
|
||||
|
||||
(define-syntax (js1 stx)
|
||||
@@ -277,7 +298,9 @@
|
||||
((eq? (syntax->datum #'a) '<) #'(js-infix < (b c)))
|
||||
((eq? (syntax->datum #'a) '>=) #'(js-infix >= (b c)))
|
||||
((eq? (syntax->datum #'a) '<=) #'(js-infix <= (b c)))
|
||||
((eq? (syntax->datum #'a) '=) #'(js-infix = (b c)))
|
||||
((eq? (syntax->datum #'a) '==) #'(js-infix == (b c)))
|
||||
((eq? (syntax->datum #'a) '===) #'(js-infix === (b c)))
|
||||
((eq? (syntax->datum #'a) '!=) #'(js-infix != (b c)))
|
||||
((memq (syntax->datum #'a) js-ops) #'(js-op a b c))
|
||||
((eq? (syntax->datum #'a) 'define) #'(js-def b (c)))
|
||||
((eq? (syntax->datum #'a) 'lambda) #'(js-lambda b c))
|
||||
@@ -297,6 +320,7 @@
|
||||
(cond
|
||||
((eq? (syntax->datum #'a) 'return) #'(js-return b))
|
||||
((eq? (syntax->datum #'a) 'quote) #'(js-quote b))
|
||||
((eq? (syntax->datum #'a) 'eval) #'(js-eval b))
|
||||
;string-append
|
||||
; "\"" (esc-double-quote (format "~a" 'b)) "\""))
|
||||
(else
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
(require racket/class
|
||||
"racket-webview.rkt"
|
||||
"private/js-transform.rkt"
|
||||
)
|
||||
|
||||
(provide wv-element%)
|
||||
@@ -87,6 +88,13 @@
|
||||
(define/public (attr/datetime attr)
|
||||
(webview-attr/datetime wv element-id attr))
|
||||
|
||||
(define/public (focus!)
|
||||
(let ((s (js (let* ((el (send document getElementById (eval element-id))))
|
||||
(if (=== el null)
|
||||
(console.log (+ "Element " (eval element-id) " not found"))
|
||||
(send el focus))))))
|
||||
(webview-run-js wv s)))
|
||||
|
||||
(super-new)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user