-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# `logseq` Sample Plugin | ||
|
||
This is a template for `logseq` plugin. It has a very basic structure and e2e tests setup. | ||
This is a template for `logseq` plugin. It has a very basic structure and e2e tests setup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,83 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script> | ||
'use strict' | ||
|
||
<head> | ||
<script> | ||
'use strict'; | ||
const keys = [ | ||
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent | ||
// without deprecated / non-standard | ||
'altKey', | ||
'code', | ||
'ctrlKey', | ||
'isComposing', | ||
'key', | ||
'locale', | ||
'location', | ||
'metaKey', | ||
'repeat', | ||
'shiftKey', | ||
] | ||
|
||
const keys = [ | ||
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent | ||
// without deprecated / non-standard | ||
"altKey", "code", "ctrlKey", "isComposing", "key", "locale", "location", "metaKey", | ||
"repeat", "shiftKey" | ||
] | ||
let output_list = [] | ||
let last_timestamp = Date.now() | ||
|
||
let output_list = []; | ||
let last_timestamp = Date.now(); | ||
|
||
function select_keys(obj, keys) { | ||
let new_obj = {} | ||
for (let k in event) | ||
if (keys.indexOf(k) != -1) | ||
new_obj[k] = event[k]; | ||
return new_obj | ||
} | ||
|
||
let key_handler_builder = (event_type) => (event) => { | ||
if (event["target"].id != "input") | ||
return; | ||
let cur_timestamp = Date.now(); | ||
let output = { | ||
"event_type": event_type, | ||
"event": select_keys(event, keys), | ||
"latency": cur_timestamp - last_timestamp // Time to wait before firing event | ||
function select_keys(obj, keys) { | ||
let new_obj = {} | ||
for (let k in event) if (keys.indexOf(k) != -1) new_obj[k] = event[k] | ||
return new_obj | ||
} | ||
last_timestamp = cur_timestamp; | ||
output_list.push(output); | ||
let to_print = JSON.stringify( | ||
output_list, | ||
undefined, | ||
2); | ||
document.getElementById("outputs").innerText = to_print; | ||
} | ||
|
||
document.addEventListener('keydown', key_handler_builder('keydown'), false); | ||
document.addEventListener('keyup', key_handler_builder('keyup'), false); | ||
document.addEventListener('keypress', key_handler_builder('keypress'), false); | ||
document.addEventListener('compositionstart', key_handler_builder('compositionstart'), false); | ||
document.addEventListener('compositionend', key_handler_builder('compositionend'), false); | ||
document.addEventListener('compositionupdate', key_handler_builder('compositionupdate'), false); | ||
|
||
window.onload = (e) => { | ||
document.getElementById("input").focus(); | ||
} | ||
let key_handler_builder = (event_type) => (event) => { | ||
if (event['target'].id != 'input') return | ||
let cur_timestamp = Date.now() | ||
let output = { | ||
event_type: event_type, | ||
event: select_keys(event, keys), | ||
latency: cur_timestamp - last_timestamp, // Time to wait before firing event | ||
} | ||
last_timestamp = cur_timestamp | ||
output_list.push(output) | ||
let to_print = JSON.stringify(output_list, undefined, 2) | ||
document.getElementById('outputs').innerText = to_print | ||
} | ||
|
||
</script> | ||
</head> | ||
document.addEventListener( | ||
'keydown', | ||
key_handler_builder('keydown'), | ||
false | ||
) | ||
document.addEventListener('keyup', key_handler_builder('keyup'), false) | ||
document.addEventListener( | ||
'keypress', | ||
key_handler_builder('keypress'), | ||
false | ||
) | ||
document.addEventListener( | ||
'compositionstart', | ||
key_handler_builder('compositionstart'), | ||
false | ||
) | ||
document.addEventListener( | ||
'compositionend', | ||
key_handler_builder('compositionend'), | ||
false | ||
) | ||
document.addEventListener( | ||
'compositionupdate', | ||
key_handler_builder('compositionupdate'), | ||
false | ||
) | ||
|
||
<body> | ||
<input id="input" /> | ||
<h2>Key Down</h2> | ||
<p id="outputs" style="white-space: pre;" /> | ||
</body> | ||
window.onload = (e) => { | ||
document.getElementById('input').focus() | ||
} | ||
</script> | ||
</head> | ||
|
||
</html> | ||
<body> | ||
<input id="input" /> | ||
<h2>Key Down</h2> | ||
<p id="outputs" style="white-space: pre" /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" | ||
/> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>Document</title> | ||
</head> | ||
</head> | ||
|
||
<body> | ||
<body> | ||
<div id="app"></div> | ||
<script src="./index.ts" type="module"></script> | ||
</body> | ||
|
||
</html> | ||
</body> | ||
</html> |