fix: update desktop intrepreter with browser open
This commit is contained in:
1 parent
b287a4cab3
commit
997684a390
1 file changed
+119
-27
@@ -17,7 +17,17 @@ function serialize_event(event) {
|
|||||||
case "keydown":
|
case "keydown":
|
||||||
case "keypress":
|
case "keypress":
|
||||||
case "keyup": {
|
case "keyup": {
|
||||||
var _c = event, charCode = _c.charCode, key = _c.key, altKey = _c.altKey, ctrlKey = _c.ctrlKey, metaKey = _c.metaKey, keyCode = _c.keyCode, shiftKey = _c.shiftKey, location_1 = _c.location, repeat = _c.repeat, which = _c.which;
|
var _c = event,
|
||||||
|
charCode = _c.charCode,
|
||||||
|
key = _c.key,
|
||||||
|
altKey = _c.altKey,
|
||||||
|
ctrlKey = _c.ctrlKey,
|
||||||
|
metaKey = _c.metaKey,
|
||||||
|
keyCode = _c.keyCode,
|
||||||
|
shiftKey = _c.shiftKey,
|
||||||
|
location_1 = _c.location,
|
||||||
|
repeat = _c.repeat,
|
||||||
|
which = _c.which;
|
||||||
return {
|
return {
|
||||||
char_code: charCode,
|
char_code: charCode,
|
||||||
key: key,
|
key: key,
|
||||||
@@ -41,9 +51,11 @@ function serialize_event(event) {
|
|||||||
var value = void 0;
|
var value = void 0;
|
||||||
if (target.type === "checkbox" || target.type === "radio") {
|
if (target.type === "checkbox" || target.type === "radio") {
|
||||||
value = target.checked ? "true" : "false";
|
value = target.checked ? "true" : "false";
|
||||||
}
|
} else {
|
||||||
else {
|
value =
|
||||||
value = (_a = target.value) !== null && _a !== void 0 ? _a : target.textContent;
|
(_a = target.value) !== null && _a !== void 0
|
||||||
|
? _a
|
||||||
|
: target.textContent;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
value: value,
|
value: value,
|
||||||
@@ -54,7 +66,8 @@ function serialize_event(event) {
|
|||||||
case "reset":
|
case "reset":
|
||||||
case "submit": {
|
case "submit": {
|
||||||
var target = event.target;
|
var target = event.target;
|
||||||
var value = (_b = target.value) !== null && _b !== void 0 ? _b : target.textContent;
|
var value =
|
||||||
|
(_b = target.value) !== null && _b !== void 0 ? _b : target.textContent;
|
||||||
if (target.type == "checkbox") {
|
if (target.type == "checkbox") {
|
||||||
value = target.checked ? "true" : "false";
|
value = target.checked ? "true" : "false";
|
||||||
}
|
}
|
||||||
@@ -80,7 +93,19 @@ function serialize_event(event) {
|
|||||||
case "mouseout":
|
case "mouseout":
|
||||||
case "mouseover":
|
case "mouseover":
|
||||||
case "mouseup": {
|
case "mouseup": {
|
||||||
var _d = event, altKey = _d.altKey, button = _d.button, buttons = _d.buttons, clientX = _d.clientX, clientY = _d.clientY, ctrlKey = _d.ctrlKey, metaKey = _d.metaKey, pageX = _d.pageX, pageY = _d.pageY, screenX_1 = _d.screenX, screenY_1 = _d.screenY, shiftKey = _d.shiftKey;
|
var _d = event,
|
||||||
|
altKey = _d.altKey,
|
||||||
|
button = _d.button,
|
||||||
|
buttons = _d.buttons,
|
||||||
|
clientX = _d.clientX,
|
||||||
|
clientY = _d.clientY,
|
||||||
|
ctrlKey = _d.ctrlKey,
|
||||||
|
metaKey = _d.metaKey,
|
||||||
|
pageX = _d.pageX,
|
||||||
|
pageY = _d.pageY,
|
||||||
|
screenX_1 = _d.screenX,
|
||||||
|
screenY_1 = _d.screenY,
|
||||||
|
shiftKey = _d.shiftKey;
|
||||||
return {
|
return {
|
||||||
alt_key: altKey,
|
alt_key: altKey,
|
||||||
button: button,
|
button: button,
|
||||||
@@ -106,7 +131,29 @@ function serialize_event(event) {
|
|||||||
case "pointerleave":
|
case "pointerleave":
|
||||||
case "pointerover":
|
case "pointerover":
|
||||||
case "pointerout": {
|
case "pointerout": {
|
||||||
var _e = event, altKey = _e.altKey, button = _e.button, buttons = _e.buttons, clientX = _e.clientX, clientY = _e.clientY, ctrlKey = _e.ctrlKey, metaKey = _e.metaKey, pageX = _e.pageX, pageY = _e.pageY, screenX_2 = _e.screenX, screenY_2 = _e.screenY, shiftKey = _e.shiftKey, pointerId = _e.pointerId, width = _e.width, height = _e.height, pressure = _e.pressure, tangentialPressure = _e.tangentialPressure, tiltX = _e.tiltX, tiltY = _e.tiltY, twist = _e.twist, pointerType = _e.pointerType, isPrimary = _e.isPrimary;
|
var _e = event,
|
||||||
|
altKey = _e.altKey,
|
||||||
|
button = _e.button,
|
||||||
|
buttons = _e.buttons,
|
||||||
|
clientX = _e.clientX,
|
||||||
|
clientY = _e.clientY,
|
||||||
|
ctrlKey = _e.ctrlKey,
|
||||||
|
metaKey = _e.metaKey,
|
||||||
|
pageX = _e.pageX,
|
||||||
|
pageY = _e.pageY,
|
||||||
|
screenX_2 = _e.screenX,
|
||||||
|
screenY_2 = _e.screenY,
|
||||||
|
shiftKey = _e.shiftKey,
|
||||||
|
pointerId = _e.pointerId,
|
||||||
|
width = _e.width,
|
||||||
|
height = _e.height,
|
||||||
|
pressure = _e.pressure,
|
||||||
|
tangentialPressure = _e.tangentialPressure,
|
||||||
|
tiltX = _e.tiltX,
|
||||||
|
tiltY = _e.tiltY,
|
||||||
|
twist = _e.twist,
|
||||||
|
pointerType = _e.pointerType,
|
||||||
|
isPrimary = _e.isPrimary;
|
||||||
return {
|
return {
|
||||||
alt_key: altKey,
|
alt_key: altKey,
|
||||||
button: button,
|
button: button,
|
||||||
@@ -139,7 +186,11 @@ function serialize_event(event) {
|
|||||||
case "touchend":
|
case "touchend":
|
||||||
case "touchmove":
|
case "touchmove":
|
||||||
case "touchstart": {
|
case "touchstart": {
|
||||||
var _f = event, altKey = _f.altKey, ctrlKey = _f.ctrlKey, metaKey = _f.metaKey, shiftKey = _f.shiftKey;
|
var _f = event,
|
||||||
|
altKey = _f.altKey,
|
||||||
|
ctrlKey = _f.ctrlKey,
|
||||||
|
metaKey = _f.metaKey,
|
||||||
|
shiftKey = _f.shiftKey;
|
||||||
return {
|
return {
|
||||||
// changed_touches: event.changedTouches,
|
// changed_touches: event.changedTouches,
|
||||||
// target_touches: event.targetTouches,
|
// target_touches: event.targetTouches,
|
||||||
@@ -154,7 +205,11 @@ function serialize_event(event) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
case "wheel": {
|
case "wheel": {
|
||||||
var _g = event, deltaX = _g.deltaX, deltaY = _g.deltaY, deltaZ = _g.deltaZ, deltaMode = _g.deltaMode;
|
var _g = event,
|
||||||
|
deltaX = _g.deltaX,
|
||||||
|
deltaY = _g.deltaY,
|
||||||
|
deltaZ = _g.deltaZ,
|
||||||
|
deltaMode = _g.deltaMode;
|
||||||
return {
|
return {
|
||||||
delta_x: deltaX,
|
delta_x: deltaX,
|
||||||
delta_y: deltaY,
|
delta_y: deltaY,
|
||||||
@@ -165,7 +220,10 @@ function serialize_event(event) {
|
|||||||
case "animationstart":
|
case "animationstart":
|
||||||
case "animationend":
|
case "animationend":
|
||||||
case "animationiteration": {
|
case "animationiteration": {
|
||||||
var _h = event, animationName = _h.animationName, elapsedTime = _h.elapsedTime, pseudoElement = _h.pseudoElement;
|
var _h = event,
|
||||||
|
animationName = _h.animationName,
|
||||||
|
elapsedTime = _h.elapsedTime,
|
||||||
|
pseudoElement = _h.pseudoElement;
|
||||||
return {
|
return {
|
||||||
animation_name: animationName,
|
animation_name: animationName,
|
||||||
elapsed_time: elapsedTime,
|
elapsed_time: elapsedTime,
|
||||||
@@ -173,7 +231,10 @@ function serialize_event(event) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
case "transitionend": {
|
case "transitionend": {
|
||||||
var _j = event, propertyName = _j.propertyName, elapsedTime = _j.elapsedTime, pseudoElement = _j.pseudoElement;
|
var _j = event,
|
||||||
|
propertyName = _j.propertyName,
|
||||||
|
elapsedTime = _j.elapsedTime,
|
||||||
|
pseudoElement = _j.pseudoElement;
|
||||||
return {
|
return {
|
||||||
property_name: propertyName,
|
property_name: propertyName,
|
||||||
elapsed_time: elapsedTime,
|
elapsed_time: elapsedTime,
|
||||||
@@ -311,16 +372,23 @@ var Interpreter = /** @class */ (function () {
|
|||||||
this.stack.push(el);
|
this.stack.push(el);
|
||||||
this.nodes[root] = el;
|
this.nodes[root] = el;
|
||||||
};
|
};
|
||||||
Interpreter.prototype.NewEventListener = function (event_name, scope, root, handler) {
|
Interpreter.prototype.NewEventListener = function (
|
||||||
|
event_name,
|
||||||
|
scope,
|
||||||
|
root,
|
||||||
|
handler
|
||||||
|
) {
|
||||||
// console.log('new event listener', event_name, root, scope);
|
// console.log('new event listener', event_name, root, scope);
|
||||||
var element = this.nodes[root];
|
var element = this.nodes[root];
|
||||||
element.setAttribute("dioxus-event-".concat(event_name), "".concat(scope, ".").concat(root));
|
element.setAttribute(
|
||||||
|
"dioxus-event-".concat(event_name),
|
||||||
|
"".concat(scope, ".").concat(root)
|
||||||
|
);
|
||||||
if (this.listeners[event_name] === undefined) {
|
if (this.listeners[event_name] === undefined) {
|
||||||
this.listeners[event_name] = 0;
|
this.listeners[event_name] = 0;
|
||||||
this.handlers[event_name] = handler;
|
this.handlers[event_name] = handler;
|
||||||
this.root.addEventListener(event_name, handler);
|
this.root.addEventListener(event_name, handler);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.listeners[event_name]++;
|
this.listeners[event_name]++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -343,11 +411,9 @@ var Interpreter = /** @class */ (function () {
|
|||||||
if (ns == "style") {
|
if (ns == "style") {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
node.style[name] = value;
|
node.style[name] = value;
|
||||||
}
|
} else if (ns != null || ns != undefined) {
|
||||||
else if (ns != null || ns != undefined) {
|
|
||||||
node.setAttributeNS(ns, name, value);
|
node.setAttributeNS(ns, name, value);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "value":
|
case "value":
|
||||||
if (value != node.value) {
|
if (value != node.value) {
|
||||||
@@ -367,8 +433,7 @@ var Interpreter = /** @class */ (function () {
|
|||||||
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
|
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
|
||||||
if (value == "false" && bool_attrs.hasOwnProperty(name)) {
|
if (value == "false" && bool_attrs.hasOwnProperty(name)) {
|
||||||
node.removeAttribute(name);
|
node.removeAttribute(name);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
node.setAttribute(name, value);
|
node.setAttribute(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -435,18 +500,45 @@ var Interpreter = /** @class */ (function () {
|
|||||||
var target = event.target;
|
var target = event.target;
|
||||||
// console.log("event", event);
|
// console.log("event", event);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
var real_id = target.getAttribute("dioxus-id");
|
var realId = target.getAttribute("dioxus-id");
|
||||||
var should_prevent_default = target.getAttribute("dioxus-prevent-default");
|
var shouldPreventDefault = target.getAttribute(
|
||||||
|
"dioxus-prevent-default"
|
||||||
|
);
|
||||||
var contents = serialize_event(event);
|
var contents = serialize_event(event);
|
||||||
if (should_prevent_default === "on".concat(event.type)) {
|
if (shouldPreventDefault === "on".concat(event.type)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
if (real_id == null) {
|
|
||||||
|
if (event.type == "submit") {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == "click") {
|
||||||
|
event.preventDefault();
|
||||||
|
if (shouldPreventDefault !== `onclick`) {
|
||||||
|
if (target.tagName == "A") {
|
||||||
|
var href = target.getAttribute("href");
|
||||||
|
if (
|
||||||
|
href !== "" &&
|
||||||
|
href !== null &&
|
||||||
|
href !== undefined &&
|
||||||
|
realId != null
|
||||||
|
) {
|
||||||
|
window.rpc.call("browser_open", {
|
||||||
|
mounted_dom_id: parseInt(realId),
|
||||||
|
href: href,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (realId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.rpc.call("user_event", {
|
window.rpc.call("user_event", {
|
||||||
event: edit.event_name,
|
event: edit.event_name,
|
||||||
mounted_dom_id: parseInt(real_id),
|
mounted_dom_id: parseInt(realId),
|
||||||
contents: contents,
|
contents: contents,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -465,7 +557,7 @@ var Interpreter = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Interpreter;
|
return Interpreter;
|
||||||
}());
|
})();
|
||||||
export { Interpreter };
|
export { Interpreter };
|
||||||
function main() {
|
function main() {
|
||||||
var root = window.document.getElementById("main");
|
var root = window.document.getElementById("main");
|
||||||
|
|||||||
Reference in new issue
Block a user