Skip to content

Commit

Permalink
chore: Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hron committed Dec 3, 2024
1 parent 017828b commit b5d6239
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
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.
25 changes: 13 additions & 12 deletions e2e-tests/util/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@ export const IsCI = process.env.CI === 'true'
export const modKey = IsMac ? 'Meta' : 'Control'

export function randomString(length: number) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'

let result = '';
const charactersLength = characters.length;
let result = ''
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}

return result;
return result
}

export function randomLowerString(length: number) {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'

let result = '';
const charactersLength = characters.length;
let result = ''
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}

return result;
return result
}

export function randomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min)
}

export function randomBoolean(): boolean {
return Math.random() < 0.5;
return Math.random() < 0.5
}
129 changes: 74 additions & 55 deletions e2e-tests/util/keyboard-event-cap.html
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>
22 changes: 11 additions & 11 deletions index.html
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>

0 comments on commit b5d6239

Please sign in to comment.