Skip to content

Commit

Permalink
Merge pull request #60 from Respo/keyup
Browse files Browse the repository at this point in the history
expose a global keyup handler
  • Loading branch information
NoEgAm authored Nov 27, 2023
2 parents 33e7e92 + e6f6bda commit 62fad03
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 12 deletions.
79 changes: 75 additions & 4 deletions calcit.cirru

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{} (:package |respo)
:configs $ {} (:init-fn |respo.main/main!) (:reload-fn |respo.main/reload!) (:version |0.16.1)
:configs $ {} (:init-fn |respo.main/main!) (:reload-fn |respo.main/reload!) (:version |0.16.2)
:modules $ [] |memof/ |lilac/ |calcit-test/
:entries $ {}
:files $ {}
Expand All @@ -21,6 +21,9 @@
comp-global-keydown
{} $ :disabled-commands (#{} "\"s" "\"p")
fn (e d!) (js/console.log "\"keydown" e)
comp-global-keyup
{} $ :disabled-commands (#{} "\"s" "\"p")
fn (e d!) (js/console.log "\"keyup" e)
|style-global $ %{} :CodeEntry (:doc |)
:code $ quote
def style-global $ {} (:font-family |Avenir,Verdana)
Expand All @@ -33,7 +36,7 @@
respo.core :refer $ defcomp div span <> >> a
respo.app.comp.todolist :refer $ comp-todolist
respo.comp.space :refer $ =<
respo.comp.global-keydown :refer $ comp-global-keydown
respo.comp.global-keydown :refer $ comp-global-keydown comp-global-keyup
|respo.app.comp.task $ %{} :FileEntry
:defs $ {}
|comp-task $ %{} :CodeEntry (:doc |)
Expand Down Expand Up @@ -382,14 +385,20 @@
|comp-global-keydown $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-global-keydown (options on-event) (; "\"dirty solution: proxy window keydown event to a `<span/>`, comes with some restrictions. however Respo does not allow effects to modify states.")
[] (effect-listen-keyboard options)
[] (effect-listen-keyboard options "\"keydown")
span $ {}
:on-keydown $ fn (e d!) (on-event e d!)
|comp-global-keyup $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-global-keyup (options on-event) (; "\"dirty solution: proxy window keydown event to a `<span/>`, comes with some restrictions. however Respo does not allow effects to modify states.")
[] (effect-listen-keyboard options "\"keyup")
span $ {}
:on-keyup $ fn (e d!) (on-event e d!)
|dirty-field $ %{} :CodeEntry (:doc |)
:code $ quote (def dirty-field "\"_global_listener")
|effect-listen-keyboard $ %{} :CodeEntry (:doc |)
:code $ quote
defeffect effect-listen-keyboard (options) (action el at?)
defeffect effect-listen-keyboard (options event-name) (action el at?)
cond
or (= action :mount) (= action :update)
let
Expand All @@ -404,13 +413,13 @@
.!dispatchEvent el $ new js/KeyboardEvent (.-type event) event
if-let
prev-listener $ aget el dirty-field
js/window.removeEventListener "\"keydown" prev-listener
js/window.removeEventListener event-name prev-listener
aset el dirty-field handler
js/window.addEventListener "\"keydown" handler
js/window.addEventListener event-name handler
(= action :unmount)
let
handler $ aget el dirty-field
js/window.removeEventListener "\"keydown" handler
js/window.removeEventListener event-name handler
aset el dirty-field nil
true nil
:ns $ %{} :CodeEntry (:doc |)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.16.1",
"version": "0.16.2",
"dependencies": {
"@calcit/procs": "^0.8.9"
},
Expand Down

0 comments on commit 62fad03

Please sign in to comment.