change serialization

This commit is contained in:
Jonathan Kelley committed 2024-02-27 19:23:36 -08:00
1 parent 925d0617da
commit f196514b4f
3 files changed
+72 -565

No files matched your search

+1 -1
View File
@@ -1 +1 @@
16803007677292896021
12494364440840058490
+33 -191
View File
@@ -169,6 +169,21 @@ System.register("serialize", [], function (exports_3, context_3) {
"use strict";
var __moduleName = context_3 && context_3.id;
function serializeEvent(event) {
var _a;
if (event instanceof InputEvent) {
if (event.target instanceof HTMLInputElement) {
var target = event.target;
var value = (_a = target.value) !== null && _a !== void 0 ? _a : target.textContent;
if (target.type === "checkbox") {
value = target.checked ? "true" : "false";
}
return {
value: value,
values: {},
};
}
return {};
}
if (event instanceof KeyboardEvent) {
return {
char_code: event.charCode,
@@ -185,6 +200,24 @@ System.register("serialize", [], function (exports_3, context_3) {
code: event.code,
};
}
if (event instanceof MouseEvent) {
return {
alt_key: event.altKey,
button: event.button,
buttons: event.buttons,
client_x: event.clientX,
client_y: event.clientY,
ctrl_key: event.ctrlKey,
meta_key: event.metaKey,
offset_x: event.offsetX,
offset_y: event.offsetY,
page_x: event.pageX,
page_y: event.pageY,
screen_x: event.screenX,
screen_y: event.screenY,
shift_key: event.shiftKey,
};
}
if (event instanceof PointerEvent) {
return {
alt_key: event.altKey,
@@ -211,24 +244,6 @@ System.register("serialize", [], function (exports_3, context_3) {
is_primary: event.isPrimary,
};
}
if (event instanceof MouseEvent) {
return {
alt_key: event.altKey,
button: event.button,
buttons: event.buttons,
client_x: event.clientX,
client_y: event.clientY,
ctrl_key: event.ctrlKey,
meta_key: event.metaKey,
offset_x: event.offsetX,
offset_y: event.offsetY,
page_x: event.pageX,
page_y: event.pageY,
screen_x: event.screenX,
screen_y: event.screenY,
shift_key: event.shiftKey,
};
}
if (event instanceof TouchEvent) {
return {
alt_key: event.altKey,
@@ -287,179 +302,6 @@ System.register("serialize", [], function (exports_3, context_3) {
return {};
}
exports_3("serializeEvent", serializeEvent);
function isElementNode(node) {
return node.nodeType == 1;
}
function eventBubbles(eventName) {
switch (eventName) {
case "copy":
return true;
case "cut":
return true;
case "paste":
return true;
case "compositionend":
return true;
case "compositionstart":
return true;
case "compositionupdate":
return true;
case "keydown":
return true;
case "keypress":
return true;
case "keyup":
return true;
case "focus":
return false;
case "focusout":
return true;
case "focusin":
return true;
case "blur":
return false;
case "change":
return true;
case "input":
return true;
case "invalid":
return true;
case "reset":
return true;
case "submit":
return true;
case "click":
return true;
case "contextmenu":
return true;
case "doubleclick":
return true;
case "dblclick":
return true;
case "drag":
return true;
case "dragend":
return true;
case "dragenter":
return false;
case "dragexit":
return false;
case "dragleave":
return true;
case "dragover":
return true;
case "dragstart":
return true;
case "drop":
return true;
case "mousedown":
return true;
case "mouseenter":
return false;
case "mouseleave":
return false;
case "mousemove":
return true;
case "mouseout":
return true;
case "scroll":
return false;
case "mouseover":
return true;
case "mouseup":
return true;
case "pointerdown":
return true;
case "pointermove":
return true;
case "pointerup":
return true;
case "pointercancel":
return true;
case "gotpointercapture":
return true;
case "lostpointercapture":
return true;
case "pointerenter":
return false;
case "pointerleave":
return false;
case "pointerover":
return true;
case "pointerout":
return true;
case "select":
return true;
case "touchcancel":
return true;
case "touchend":
return true;
case "touchmove":
return true;
case "touchstart":
return true;
case "wheel":
return true;
case "abort":
return false;
case "canplay":
return false;
case "canplaythrough":
return false;
case "durationchange":
return false;
case "emptied":
return false;
case "encrypted":
return true;
case "ended":
return false;
case "error":
return false;
case "loadeddata":
case "loadedmetadata":
case "loadstart":
case "load":
return false;
case "pause":
return false;
case "play":
return false;
case "playing":
return false;
case "progress":
return false;
case "ratechange":
return false;
case "seeked":
return false;
case "seeking":
return false;
case "stalled":
return false;
case "suspend":
return false;
case "timeupdate":
return false;
case "volumechange":
return false;
case "waiting":
return false;
case "animationstart":
return true;
case "animationend":
return true;
case "animationiteration":
return true;
case "transitionend":
return true;
case "toggle":
return true;
case "mounted":
return false;
}
return true;
}
return {
setters: [],
execute: function () {
+38 -373
View File
@@ -7,8 +7,21 @@ export type SerializedEvent = {
};
export function serializeEvent(event: Event): SerializedEvent {
if (event instanceof InputEvent) {
if (event.target instanceof HTMLInputElement) {
let target = event.target;
let value = target.value ?? target.textContent;
if (target.type === "checkbox") {
value = target.checked ? "true" : "false";
}
return {
value: value,
values: {},
};
}
return {};
}
// copy, cut, paste
if (event instanceof KeyboardEvent) {
return {
char_code: event.charCode,
@@ -26,9 +39,25 @@ export function serializeEvent(event: Event): SerializedEvent {
};
}
if (event instanceof MouseEvent) {
return {
alt_key: event.altKey,
button: event.button,
buttons: event.buttons,
client_x: event.clientX,
client_y: event.clientY,
ctrl_key: event.ctrlKey,
meta_key: event.metaKey,
offset_x: event.offsetX,
offset_y: event.offsetY,
page_x: event.pageX,
page_y: event.pageY,
screen_x: event.screenX,
screen_y: event.screenY,
shift_key: event.shiftKey,
};
}
// "pointerdown" "pointermove" "pointerup" "pointercancel" "gotpointercapture" "lostpointercapture" "pointerenter"
// "pointerleave" "pointerover" "pointerout"
if (event instanceof PointerEvent) {
return {
alt_key: event.altKey,
@@ -56,24 +85,6 @@ export function serializeEvent(event: Event): SerializedEvent {
};
}
if (event instanceof MouseEvent) {
return {
alt_key: event.altKey,
button: event.button,
buttons: event.buttons,
client_x: event.clientX,
client_y: event.clientY,
ctrl_key: event.ctrlKey,
meta_key: event.metaKey,
offset_x: event.offsetX,
offset_y: event.offsetY,
page_x: event.pageX,
page_y: event.pageY,
screen_x: event.screenX,
screen_y: event.screenY,
shift_key: event.shiftKey,
};
}
if (event instanceof TouchEvent) {
return {
@@ -123,6 +134,12 @@ export function serializeEvent(event: Event): SerializedEvent {
}
if (event instanceof DragEvent) {
// let files = [];
// if (event.dataTransfer && event.dataTransfer.files) {
// files = ["a", "b", "c"];
// // files = await serializeFileList(event.dataTransfer.files);
// }
// return { mouse: get_mouse_data(event), files };
return {
mouse: {
alt_key: event.altKey,
@@ -140,355 +157,3 @@ export function serializeEvent(event: Event): SerializedEvent {
return {};
}
function isElementNode(node: Node) {
return node.nodeType == 1;
}
function eventBubbles(eventName: string) {
switch (eventName) {
case "copy":
return true;
case "cut":
return true;
case "paste":
return true;
case "compositionend":
return true;
case "compositionstart":
return true;
case "compositionupdate":
return true;
case "keydown":
return true;
case "keypress":
return true;
case "keyup":
return true;
case "focus":
return false;
case "focusout":
return true;
case "focusin":
return true;
case "blur":
return false;
case "change":
return true;
case "input":
return true;
case "invalid":
return true;
case "reset":
return true;
case "submit":
return true;
case "click":
return true;
case "contextmenu":
return true;
case "doubleclick":
return true;
case "dblclick":
return true;
case "drag":
return true;
case "dragend":
return true;
case "dragenter":
return false;
case "dragexit":
return false;
case "dragleave":
return true;
case "dragover":
return true;
case "dragstart":
return true;
case "drop":
return true;
case "mousedown":
return true;
case "mouseenter":
return false;
case "mouseleave":
return false;
case "mousemove":
return true;
case "mouseout":
return true;
case "scroll":
return false;
case "mouseover":
return true;
case "mouseup":
return true;
case "pointerdown":
return true;
case "pointermove":
return true;
case "pointerup":
return true;
case "pointercancel":
return true;
case "gotpointercapture":
return true;
case "lostpointercapture":
return true;
case "pointerenter":
return false;
case "pointerleave":
return false;
case "pointerover":
return true;
case "pointerout":
return true;
case "select":
return true;
case "touchcancel":
return true;
case "touchend":
return true;
case "touchmove":
return true;
case "touchstart":
return true;
case "wheel":
return true;
case "abort":
return false;
case "canplay":
return false;
case "canplaythrough":
return false;
case "durationchange":
return false;
case "emptied":
return false;
case "encrypted":
return true;
case "ended":
return false;
case "error":
return false;
case "loadeddata":
case "loadedmetadata":
case "loadstart":
case "load":
return false;
case "pause":
return false;
case "play":
return false;
case "playing":
return false;
case "progress":
return false;
case "ratechange":
return false;
case "seeked":
return false;
case "seeking":
return false;
case "stalled":
return false;
case "suspend":
return false;
case "timeupdate":
return false;
case "volumechange":
return false;
case "waiting":
return false;
case "animationstart":
return true;
case "animationend":
return true;
case "animationiteration":
return true;
case "transitionend":
return true;
case "toggle":
return true;
case "mounted":
return false;
}
return true;
}
// switch (event.type) {
// case "copy": case "cut": case "paste": {
// return {};
// }
// case "compositionend":
// case "compositionstart":
// case "compositionupdate": {
// let { data } = event;
// return {
// data,
// };
// }
// case "keydown": case "keypress": case "keyup": {
// if (event instanceof KeyboardEvent) {
// return {
// char_code: event.charCode,
// is_composing: event.isComposing,
// key: event.key,
// alt_key: event.altKey,
// ctrl_key: event.ctrlKey,
// meta_key: event.metaKey,
// key_code: event.keyCode,
// shift_key: event.shiftKey,
// location: event.location,
// repeat: event.repeat,
// which: event.which,
// code: event.code,
// };
// };
// }
// case "focus":
// case "blur": {
// return {};
// }
// case "change": {
// let target = event.target;
// let value;
// if (target.type === "checkbox" || target.type === "radio") {
// value = target.checked ? "true" : "false";
// } else {
// value = target.value ?? target.textContent;
// }
// return {
// value: value,
// values: {},
// };
// }
// case "input":
// case "invalid":
// case "reset":
// case "submit": {
// let target = event.target;
// let value = target.value ?? target.textContent;
// if (target.type === "checkbox") {
// value = target.checked ? "true" : "false";
// }
// return {
// value: value,
// values: {},
// };
// }
// case "drag":
// case "dragend":
// case "dragenter":
// case "dragexit":
// case "dragleave":
// case "dragover":
// case "dragstart":
// case "drop": {
// let files = [];
// if (event.dataTransfer && event.dataTransfer.files) {
// files = ["a", "b", "c"];
// // files = await serializeFileList(event.dataTransfer.files);
// }
// return { mouse: get_mouse_data(event), files };
// }
// case "click":
// case "contextmenu":
// case "doubleclick":
// case "dblclick":
// case "mousedown":
// case "mouseenter":
// case "mouseleave":
// case "mousemove":
// case "mouseout":
// case "mouseover":
// case "mouseup": {
// return get_mouse_data(event);
// }
// case "select": {
// return {};
// }
// case "touchcancel":
// case "touchend":
// case "touchmove":
// case "touchstart": {
// const { altKey, ctrlKey, metaKey, shiftKey } = event;
// return {
// // changed_touches: event.changedTouches,
// // target_touches: event.targetTouches,
// // touches: event.touches,
// alt_key: altKey,
// ctrl_key: ctrlKey,
// meta_key: metaKey,
// shift_key: shiftKey,
// };
// }
// case "scroll": {
// return {};
// }
// case "wheel": {
// const { deltaX, deltaY, deltaZ, deltaMode } = event;
// return {
// delta_x: deltaX,
// delta_y: deltaY,
// delta_z: deltaZ,
// delta_mode: deltaMode,
// };
// }
// case "animationstart":
// case "animationend":
// case "animationiteration": {
// const { animationName, elapsedTime, pseudoElement } = event;
// return {
// animation_name: animationName,
// elapsed_time: elapsedTime,
// pseudo_element: pseudoElement,
// };
// }
// case "transitionend": {
// const { propertyName, elapsedTime, pseudoElement } = event;
// return {
// property_name: propertyName,
// elapsed_time: elapsedTime,
// pseudo_element: pseudoElement,
// };
// }
// case "abort":
// case "canplay":
// case "canplaythrough":
// case "durationchange":
// case "emptied":
// case "encrypted":
// case "ended":
// case "error":
// case "loadeddata":
// case "loadedmetadata":
// case "loadstart":
// case "pause":
// case "play":
// case "playing":
// case "progress":
// case "ratechange":
// case "seeked":
// case "seeking":
// case "stalled":
// case "suspend":
// case "timeupdate":
// case "volumechange":
// case "waiting": {
// return {};
// }
// case "toggle": {
// return {};
// }
// default: {
// return {};
// }
// }