[Blazor] Add more eslint rules and apply auto fixes (#9004)
This commit is contained in:
parent
facb0018eb
commit
237b19b2b9
|
|
@ -33,7 +33,37 @@ module.exports = {
|
||||||
}],
|
}],
|
||||||
"comma-style": ["error", "last"],
|
"comma-style": ["error", "last"],
|
||||||
"comma-spacing": ["error", { "after": true }],
|
"comma-spacing": ["error", { "after": true }],
|
||||||
"no-trailing-spaces": ["error"]
|
"no-trailing-spaces": ["error"],
|
||||||
|
"curly": ["error"],
|
||||||
|
"dot-location": ["error", "property"],
|
||||||
|
"eqeqeq": ["error", "always"],
|
||||||
|
"no-eq-null": ["error"],
|
||||||
|
"no-multi-spaces": ["error"],
|
||||||
|
"no-unused-labels": ["error"],
|
||||||
|
"require-await": ["error"],
|
||||||
|
"array-bracket-newline": ["error", { "multiline": true, "minItems": 4 }],
|
||||||
|
"array-bracket-spacing": ["error", "never"],
|
||||||
|
"array-element-newline": ["error", { "minItems": 3 }],
|
||||||
|
"block-spacing": ["error"],
|
||||||
|
"func-call-spacing": ["error", "never"],
|
||||||
|
"function-paren-newline": ["error", "multiline"],
|
||||||
|
"key-spacing": ["error", { "mode": "strict" }],
|
||||||
|
"keyword-spacing": ["error", { "before": true }],
|
||||||
|
"lines-between-class-members": ["error", "always"],
|
||||||
|
"new-parens": ["error"],
|
||||||
|
"no-multi-assign": ["error"],
|
||||||
|
"no-multiple-empty-lines": ["error"],
|
||||||
|
"no-unneeded-ternary": ["error"],
|
||||||
|
"no-whitespace-before-property": ["error"],
|
||||||
|
"one-var": ["error", "never"],
|
||||||
|
"space-before-function-paren": ["error", {
|
||||||
|
"anonymous": "never",
|
||||||
|
"named": "never",
|
||||||
|
"asyncArrow": "always"
|
||||||
|
}],
|
||||||
|
"space-in-parens": ["error", "never"],
|
||||||
|
"space-infix-ops": ["error"]
|
||||||
|
|
||||||
},
|
},
|
||||||
globals: {
|
globals: {
|
||||||
DotNet: "readonly"
|
DotNet: "readonly"
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ window['Blazor'] = {
|
||||||
_internal: {
|
_internal: {
|
||||||
attachRootComponentToElement,
|
attachRootComponentToElement,
|
||||||
http: httpInternalFunctions,
|
http: httpInternalFunctions,
|
||||||
uriHelper: uriHelperInternalFunctions
|
uriHelper: uriHelperInternalFunctions,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,13 @@ import { ReconnectDisplay } from './ReconnectDisplay';
|
||||||
import { ILogger, LogLevel } from '../Logging/ILogger';
|
import { ILogger, LogLevel } from '../Logging/ILogger';
|
||||||
export class AutoReconnectCircuitHandler implements CircuitHandler {
|
export class AutoReconnectCircuitHandler implements CircuitHandler {
|
||||||
public static readonly MaxRetries = 5;
|
public static readonly MaxRetries = 5;
|
||||||
|
|
||||||
public static readonly RetryInterval = 3000;
|
public static readonly RetryInterval = 3000;
|
||||||
|
|
||||||
public static readonly DialogId = 'components-reconnect-modal';
|
public static readonly DialogId = 'components-reconnect-modal';
|
||||||
|
|
||||||
public reconnectDisplay: ReconnectDisplay;
|
public reconnectDisplay: ReconnectDisplay;
|
||||||
|
|
||||||
public logger: ILogger;
|
public logger: ILogger;
|
||||||
|
|
||||||
public constructor(logger: ILogger) {
|
public constructor(logger: ILogger) {
|
||||||
|
|
@ -20,6 +24,7 @@ export class AutoReconnectCircuitHandler implements CircuitHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public onConnectionUp(): void {
|
public onConnectionUp(): void {
|
||||||
this.reconnectDisplay.hide();
|
this.reconnectDisplay.hide();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { ComponentDescriptor, MarkupRegistrationTags, StartComponentComment, End
|
||||||
|
|
||||||
export class CircuitDescriptor {
|
export class CircuitDescriptor {
|
||||||
public circuitId: string;
|
public circuitId: string;
|
||||||
|
|
||||||
public components: ComponentDescriptor[];
|
public components: ComponentDescriptor[];
|
||||||
|
|
||||||
public constructor(circuitId: string, components: ComponentDescriptor[]) {
|
public constructor(circuitId: string, components: ComponentDescriptor[]) {
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,11 @@ export interface MarkupRegistrationTags {
|
||||||
|
|
||||||
export class ComponentDescriptor {
|
export class ComponentDescriptor {
|
||||||
public registrationTags: MarkupRegistrationTags;
|
public registrationTags: MarkupRegistrationTags;
|
||||||
|
|
||||||
public componentId: number;
|
public componentId: number;
|
||||||
|
|
||||||
public circuitId: string;
|
public circuitId: string;
|
||||||
|
|
||||||
public rendererId: number;
|
public rendererId: number;
|
||||||
|
|
||||||
public constructor(componentId: number, circuitId: string, rendererId: number, descriptor: MarkupRegistrationTags) {
|
public constructor(componentId: number, circuitId: string, rendererId: number, descriptor: MarkupRegistrationTags) {
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@ import { ReconnectDisplay } from './ReconnectDisplay';
|
||||||
import { AutoReconnectCircuitHandler } from './AutoReconnectCircuitHandler';
|
import { AutoReconnectCircuitHandler } from './AutoReconnectCircuitHandler';
|
||||||
export class DefaultReconnectDisplay implements ReconnectDisplay {
|
export class DefaultReconnectDisplay implements ReconnectDisplay {
|
||||||
modal: HTMLDivElement;
|
modal: HTMLDivElement;
|
||||||
|
|
||||||
message: HTMLHeadingElement;
|
message: HTMLHeadingElement;
|
||||||
|
|
||||||
button: HTMLButtonElement;
|
button: HTMLButtonElement;
|
||||||
|
|
||||||
addedToDom: boolean = false;
|
addedToDom: boolean = false;
|
||||||
|
|
||||||
constructor(private document: Document) {
|
constructor(private document: Document) {
|
||||||
this.modal = this.document.createElement('div');
|
this.modal = this.document.createElement('div');
|
||||||
this.modal.id = AutoReconnectCircuitHandler.DialogId;
|
this.modal.id = AutoReconnectCircuitHandler.DialogId;
|
||||||
|
|
@ -21,7 +25,7 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
|
||||||
'background-color: #fff',
|
'background-color: #fff',
|
||||||
'opacity: 0.8',
|
'opacity: 0.8',
|
||||||
'text-align: center',
|
'text-align: center',
|
||||||
'font-weight: bold'
|
'font-weight: bold',
|
||||||
];
|
];
|
||||||
|
|
||||||
this.modal.style.cssText = modalStyles.join(';');
|
this.modal.style.cssText = modalStyles.join(';');
|
||||||
|
|
@ -31,6 +35,7 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
|
||||||
|
|
||||||
this.button.addEventListener('click', () => window['Blazor'].reconnect());
|
this.button.addEventListener('click', () => window['Blazor'].reconnect());
|
||||||
}
|
}
|
||||||
|
|
||||||
show(): void {
|
show(): void {
|
||||||
if (!this.addedToDom) {
|
if (!this.addedToDom) {
|
||||||
this.addedToDom = true;
|
this.addedToDom = true;
|
||||||
|
|
@ -40,9 +45,11 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
|
||||||
this.button.style.display = 'none';
|
this.button.style.display = 'none';
|
||||||
this.message.textContent = 'Attempting to reconnect to the server...';
|
this.message.textContent = 'Attempting to reconnect to the server...';
|
||||||
}
|
}
|
||||||
|
|
||||||
hide(): void {
|
hide(): void {
|
||||||
this.modal.style.display = 'none';
|
this.modal.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
failed(): void {
|
failed(): void {
|
||||||
this.button.style.display = 'block';
|
this.button.style.display = 'block';
|
||||||
this.message.textContent = 'Failed to reconnect to the server.';
|
this.message.textContent = 'Failed to reconnect to the server.';
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ export default class RenderQueue {
|
||||||
private static renderQueues = new Map<number, RenderQueue>();
|
private static renderQueues = new Map<number, RenderQueue>();
|
||||||
|
|
||||||
private nextBatchId = 2;
|
private nextBatchId = 2;
|
||||||
|
|
||||||
public browserRendererId: number;
|
public browserRendererId: number;
|
||||||
|
|
||||||
public logger: ILogger;
|
public logger: ILogger;
|
||||||
|
|
||||||
public constructor(browserRendererId: number, logger: ILogger) {
|
public constructor(browserRendererId: number, logger: ILogger) {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,29 @@
|
||||||
import { ReconnectDisplay } from "./ReconnectDisplay";
|
import { ReconnectDisplay } from './ReconnectDisplay';
|
||||||
export class UserSpecifiedDisplay implements ReconnectDisplay {
|
export class UserSpecifiedDisplay implements ReconnectDisplay {
|
||||||
static readonly ShowClassName = 'components-reconnect-show';
|
static readonly ShowClassName = 'components-reconnect-show';
|
||||||
|
|
||||||
static readonly HideClassName = 'components-reconnect-hide';
|
static readonly HideClassName = 'components-reconnect-hide';
|
||||||
|
|
||||||
static readonly FailedClassName = 'components-reconnect-failed';
|
static readonly FailedClassName = 'components-reconnect-failed';
|
||||||
|
|
||||||
constructor(private dialog: HTMLElement) {
|
constructor(private dialog: HTMLElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
show(): void {
|
show(): void {
|
||||||
this.removeClasses();
|
this.removeClasses();
|
||||||
this.dialog.classList.add(UserSpecifiedDisplay.ShowClassName);
|
this.dialog.classList.add(UserSpecifiedDisplay.ShowClassName);
|
||||||
}
|
}
|
||||||
|
|
||||||
hide(): void {
|
hide(): void {
|
||||||
this.removeClasses();
|
this.removeClasses();
|
||||||
this.dialog.classList.add(UserSpecifiedDisplay.HideClassName);
|
this.dialog.classList.add(UserSpecifiedDisplay.HideClassName);
|
||||||
}
|
}
|
||||||
|
|
||||||
failed(): void {
|
failed(): void {
|
||||||
this.removeClasses();
|
this.removeClasses();
|
||||||
this.dialog.classList.add(UserSpecifiedDisplay.FailedClassName);
|
this.dialog.classList.add(UserSpecifiedDisplay.FailedClassName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeClasses() {
|
private removeClasses() {
|
||||||
this.dialog.classList.remove(UserSpecifiedDisplay.ShowClassName, UserSpecifiedDisplay.HideClassName, UserSpecifiedDisplay.FailedClassName);
|
this.dialog.classList.remove(UserSpecifiedDisplay.ShowClassName, UserSpecifiedDisplay.HideClassName, UserSpecifiedDisplay.FailedClassName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ export const monoPlatform: Platform = {
|
||||||
|
|
||||||
// mono.js assumes the existence of this
|
// mono.js assumes the existence of this
|
||||||
window['Browser'] = {
|
window['Browser'] = {
|
||||||
init: () => { }
|
init: () => { },
|
||||||
};
|
};
|
||||||
// Emscripten works by expecting the module config to be a global
|
// Emscripten works by expecting the module config to be a global
|
||||||
window['Module'] = createEmscriptenModuleInstance(loadAssemblyUrls, resolve, reject);
|
window['Module'] = createEmscriptenModuleInstance(loadAssemblyUrls, resolve, reject);
|
||||||
|
|
@ -60,7 +60,7 @@ export const monoPlatform: Platform = {
|
||||||
try {
|
try {
|
||||||
const argsBuffer = Module.stackAlloc(args.length);
|
const argsBuffer = Module.stackAlloc(args.length);
|
||||||
const exceptionFlagManagedInt = Module.stackAlloc(4);
|
const exceptionFlagManagedInt = Module.stackAlloc(4);
|
||||||
for (var i = 0; i < args.length; ++i) {
|
for (let i = 0; i < args.length; ++i) {
|
||||||
Module.setValue(argsBuffer + i * 4, args[i], 'i32');
|
Module.setValue(argsBuffer + i * 4, args[i], 'i32');
|
||||||
}
|
}
|
||||||
Module.setValue(exceptionFlagManagedInt, 0, 'i32');
|
Module.setValue(exceptionFlagManagedInt, 0, 'i32');
|
||||||
|
|
@ -80,8 +80,8 @@ export const monoPlatform: Platform = {
|
||||||
|
|
||||||
toJavaScriptString: function toJavaScriptString(managedString: System_String) {
|
toJavaScriptString: function toJavaScriptString(managedString: System_String) {
|
||||||
// Comments from original Mono sample:
|
// Comments from original Mono sample:
|
||||||
//FIXME this is wastefull, we could remove the temp malloc by going the UTF16 route
|
// FIXME this is wastefull, we could remove the temp malloc by going the UTF16 route
|
||||||
//FIXME this is unsafe, cuz raw objects could be GC'd.
|
// FIXME this is unsafe, cuz raw objects could be GC'd.
|
||||||
|
|
||||||
const utf8 = mono_string_get_utf8(managedString);
|
const utf8 = mono_string_get_utf8(managedString);
|
||||||
const res = Module.UTF8ToString(utf8);
|
const res = Module.UTF8ToString(utf8);
|
||||||
|
|
@ -206,11 +206,27 @@ function createEmscriptenModuleInstance(loadAssemblyUrls: string[], onReady: ()
|
||||||
|
|
||||||
module.preRun.push(() => {
|
module.preRun.push(() => {
|
||||||
// By now, emscripten should be initialised enough that we can capture these methods for later use
|
// By now, emscripten should be initialised enough that we can capture these methods for later use
|
||||||
const mono_wasm_add_assembly = Module.cwrap('mono_wasm_add_assembly', null, ['string', 'number', 'number']);
|
const mono_wasm_add_assembly = Module.cwrap('mono_wasm_add_assembly', null, [
|
||||||
|
'string',
|
||||||
|
'number',
|
||||||
|
'number',
|
||||||
|
]);
|
||||||
assembly_load = Module.cwrap('mono_wasm_assembly_load', 'number', ['string']);
|
assembly_load = Module.cwrap('mono_wasm_assembly_load', 'number', ['string']);
|
||||||
find_class = Module.cwrap('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string']);
|
find_class = Module.cwrap('mono_wasm_assembly_find_class', 'number', [
|
||||||
find_method = Module.cwrap('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number']);
|
'number',
|
||||||
invoke_method = Module.cwrap('mono_wasm_invoke_method', 'number', ['number', 'number', 'number']);
|
'string',
|
||||||
|
'string',
|
||||||
|
]);
|
||||||
|
find_method = Module.cwrap('mono_wasm_assembly_find_method', 'number', [
|
||||||
|
'number',
|
||||||
|
'string',
|
||||||
|
'number',
|
||||||
|
]);
|
||||||
|
invoke_method = Module.cwrap('mono_wasm_invoke_method', 'number', [
|
||||||
|
'number',
|
||||||
|
'number',
|
||||||
|
'number',
|
||||||
|
]);
|
||||||
mono_string_get_utf8 = Module.cwrap('mono_wasm_string_get_utf8', 'number', ['number']);
|
mono_string_get_utf8 = Module.cwrap('mono_wasm_string_get_utf8', 'number', ['number']);
|
||||||
mono_string = Module.cwrap('mono_wasm_string_from_js', 'number', ['string']);
|
mono_string = Module.cwrap('mono_wasm_string_from_js', 'number', ['string']);
|
||||||
|
|
||||||
|
|
@ -264,12 +280,12 @@ function toAbsoluteUrl(possiblyRelativeUrl: string) {
|
||||||
|
|
||||||
function asyncLoad(url) {
|
function asyncLoad(url) {
|
||||||
return new Promise<Uint8Array>((resolve, reject) => {
|
return new Promise<Uint8Array>((resolve, reject) => {
|
||||||
var xhr = new XMLHttpRequest;
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url, /* async: */ true);
|
xhr.open('GET', url, /* async: */ true);
|
||||||
xhr.responseType = 'arraybuffer';
|
xhr.responseType = 'arraybuffer';
|
||||||
xhr.onload = function xhr_onload() {
|
xhr.onload = function xhr_onload() {
|
||||||
if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
|
if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
|
||||||
var asm = new Uint8Array(xhr.response);
|
const asm = new Uint8Array(xhr.response);
|
||||||
resolve(asm);
|
resolve(asm);
|
||||||
} else {
|
} else {
|
||||||
reject(xhr);
|
reject(xhr);
|
||||||
|
|
@ -295,12 +311,12 @@ function attachInteropInvoker() {
|
||||||
const assemblyNameOrDotNetObjectId = dotNetObjectId
|
const assemblyNameOrDotNetObjectId = dotNetObjectId
|
||||||
? dotNetObjectId.toString()
|
? dotNetObjectId.toString()
|
||||||
: assemblyName;
|
: assemblyName;
|
||||||
|
|
||||||
monoPlatform.callMethod(dotNetDispatcherBeginInvokeMethodHandle, null, [
|
monoPlatform.callMethod(dotNetDispatcherBeginInvokeMethodHandle, null, [
|
||||||
callId ? monoPlatform.toDotNetString(callId.toString()) : null,
|
callId ? monoPlatform.toDotNetString(callId.toString()) : null,
|
||||||
monoPlatform.toDotNetString(assemblyNameOrDotNetObjectId!),
|
monoPlatform.toDotNetString(assemblyNameOrDotNetObjectId!),
|
||||||
monoPlatform.toDotNetString(methodIdentifier),
|
monoPlatform.toDotNetString(methodIdentifier),
|
||||||
monoPlatform.toDotNetString(argsJson)
|
monoPlatform.toDotNetString(argsJson),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -309,7 +325,7 @@ function attachInteropInvoker() {
|
||||||
assemblyName ? monoPlatform.toDotNetString(assemblyName) : null,
|
assemblyName ? monoPlatform.toDotNetString(assemblyName) : null,
|
||||||
monoPlatform.toDotNetString(methodIdentifier),
|
monoPlatform.toDotNetString(methodIdentifier),
|
||||||
dotNetObjectId ? monoPlatform.toDotNetString(dotNetObjectId.toString()) : null,
|
dotNetObjectId ? monoPlatform.toDotNetString(dotNetObjectId.toString()) : null,
|
||||||
monoPlatform.toDotNetString(argsJson)
|
monoPlatform.toDotNetString(argsJson),
|
||||||
]) as System_String;
|
]) as System_String;
|
||||||
return resultJsonStringPtr
|
return resultJsonStringPtr
|
||||||
? monoPlatform.toJavaScriptString(resultJsonStringPtr)
|
? monoPlatform.toJavaScriptString(resultJsonStringPtr)
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ export interface Platform {
|
||||||
// We don't actually instantiate any of these at runtime. For perf it's preferable to
|
// We don't actually instantiate any of these at runtime. For perf it's preferable to
|
||||||
// use the original 'number' instances without any boxing. The definitions are just
|
// use the original 'number' instances without any boxing. The definitions are just
|
||||||
// for compile-time checking, since TypeScript doesn't support nominal types.
|
// for compile-time checking, since TypeScript doesn't support nominal types.
|
||||||
export interface MethodHandle { MethodHandle__DO_NOT_IMPLEMENT: any };
|
export interface MethodHandle { MethodHandle__DO_NOT_IMPLEMENT: any }
|
||||||
export interface System_Object { System_Object__DO_NOT_IMPLEMENT: any };
|
export interface System_Object { System_Object__DO_NOT_IMPLEMENT: any }
|
||||||
export interface System_String extends System_Object { System_String__DO_NOT_IMPLEMENT: any }
|
export interface System_String extends System_Object { System_String__DO_NOT_IMPLEMENT: any }
|
||||||
export interface System_Array<T> extends System_Object { System_Array__DO_NOT_IMPLEMENT: any }
|
export interface System_Array<T> extends System_Object { System_Array__DO_NOT_IMPLEMENT: any }
|
||||||
export interface Pointer { Pointer__DO_NOT_IMPLEMENT: any }
|
export interface Pointer { Pointer__DO_NOT_IMPLEMENT: any }
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ const rootComponentsPendingFirstRender: { [componentId: number]: LogicalElement
|
||||||
|
|
||||||
export class BrowserRenderer {
|
export class BrowserRenderer {
|
||||||
private eventDelegator: EventDelegator;
|
private eventDelegator: EventDelegator;
|
||||||
|
|
||||||
private childComponentLocations: { [componentId: number]: LogicalElement } = {};
|
private childComponentLocations: { [componentId: number]: LogicalElement } = {};
|
||||||
|
|
||||||
private browserRendererId: number;
|
private browserRendererId: number;
|
||||||
|
|
||||||
public constructor(browserRendererId: number) {
|
public constructor(browserRendererId: number) {
|
||||||
|
|
@ -388,7 +390,8 @@ function raiseEvent(event: Event, browserRendererId: number, eventHandlerId: num
|
||||||
'Microsoft.AspNetCore.Components.Browser',
|
'Microsoft.AspNetCore.Components.Browser',
|
||||||
'DispatchEvent',
|
'DispatchEvent',
|
||||||
eventDescriptor,
|
eventDescriptor,
|
||||||
JSON.stringify(eventArgs.data));
|
JSON.stringify(eventArgs.data)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearElement(element: Element) {
|
function clearElement(element: Element) {
|
||||||
|
|
@ -400,7 +403,7 @@ function clearElement(element: Element) {
|
||||||
|
|
||||||
function clearBetween(start: Node, end: Node): void {
|
function clearBetween(start: Node, end: Node): void {
|
||||||
const logicalParent = getLogicalParent(start as unknown as LogicalElement);
|
const logicalParent = getLogicalParent(start as unknown as LogicalElement);
|
||||||
if(!logicalParent){
|
if (!logicalParent){
|
||||||
throw new Error("Can't clear between nodes. The start node does not have a logical parent.");
|
throw new Error("Can't clear between nodes. The start node does not have a logical parent.");
|
||||||
}
|
}
|
||||||
const children = getLogicalChildrenArray(logicalParent);
|
const children = getLogicalChildrenArray(logicalParent);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,23 @@
|
||||||
import { EventForDotNet, UIEventArgs } from './EventForDotNet';
|
import { EventForDotNet, UIEventArgs } from './EventForDotNet';
|
||||||
|
|
||||||
const nonBubblingEvents = toLookup([
|
const nonBubblingEvents = toLookup([
|
||||||
'abort', 'blur', 'change', 'error', 'focus', 'load', 'loadend', 'loadstart', 'mouseenter', 'mouseleave',
|
'abort',
|
||||||
'progress', 'reset', 'scroll', 'submit', 'unload', 'DOMNodeInsertedIntoDocument', 'DOMNodeRemovedFromDocument'
|
'blur',
|
||||||
|
'change',
|
||||||
|
'error',
|
||||||
|
'focus',
|
||||||
|
'load',
|
||||||
|
'loadend',
|
||||||
|
'loadstart',
|
||||||
|
'mouseenter',
|
||||||
|
'mouseleave',
|
||||||
|
'progress',
|
||||||
|
'reset',
|
||||||
|
'scroll',
|
||||||
|
'submit',
|
||||||
|
'unload',
|
||||||
|
'DOMNodeInsertedIntoDocument',
|
||||||
|
'DOMNodeRemovedFromDocument',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export interface OnEventCallback {
|
export interface OnEventCallback {
|
||||||
|
|
@ -14,7 +29,9 @@ export interface OnEventCallback {
|
||||||
// event listeners as required (and also maps actual events back to the given callback).
|
// event listeners as required (and also maps actual events back to the given callback).
|
||||||
export class EventDelegator {
|
export class EventDelegator {
|
||||||
private static nextEventDelegatorId = 0;
|
private static nextEventDelegatorId = 0;
|
||||||
|
|
||||||
private eventsCollectionKey: string;
|
private eventsCollectionKey: string;
|
||||||
|
|
||||||
private eventInfoStore: EventInfoStore;
|
private eventInfoStore: EventInfoStore;
|
||||||
|
|
||||||
constructor(private onEvent: OnEventCallback) {
|
constructor(private onEvent: OnEventCallback) {
|
||||||
|
|
@ -93,6 +110,7 @@ export class EventDelegator {
|
||||||
// for a given event name changes between zero and nonzero
|
// for a given event name changes between zero and nonzero
|
||||||
class EventInfoStore {
|
class EventInfoStore {
|
||||||
private infosByEventHandlerId: { [eventHandlerId: number]: EventHandlerInfo } = {};
|
private infosByEventHandlerId: { [eventHandlerId: number]: EventHandlerInfo } = {};
|
||||||
|
|
||||||
private countByEventName: { [eventName: string]: number } = {};
|
private countByEventName: { [eventName: string]: number } = {};
|
||||||
|
|
||||||
constructor(private globalListener: EventListener) {
|
constructor(private globalListener: EventListener) {
|
||||||
|
|
@ -155,7 +173,7 @@ interface EventHandlerInfosForElement {
|
||||||
// can only have one attribute with a given name, hence only one event handler with
|
// can only have one attribute with a given name, hence only one event handler with
|
||||||
// that name at any one time.
|
// that name at any one time.
|
||||||
// So to keep things simple, only track one EventHandlerInfo per (element, eventName)
|
// So to keep things simple, only track one EventHandlerInfo per (element, eventName)
|
||||||
[eventName: string]: EventHandlerInfo
|
[eventName: string]: EventHandlerInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventHandlerInfo {
|
interface EventHandlerInfo {
|
||||||
|
|
@ -166,6 +184,8 @@ interface EventHandlerInfo {
|
||||||
|
|
||||||
function toLookup(items: string[]): { [key: string]: boolean } {
|
function toLookup(items: string[]): { [key: string]: boolean } {
|
||||||
const result = {};
|
const result = {};
|
||||||
items.forEach(value => { result[value] = true; });
|
items.forEach(value => {
|
||||||
|
result[value] = true;
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ function parseDragEvent(event: any) {
|
||||||
ctrlKey: event.ctrlKey,
|
ctrlKey: event.ctrlKey,
|
||||||
shiftKey: event.shiftKey,
|
shiftKey: event.shiftKey,
|
||||||
altKey: event.altKey,
|
altKey: event.altKey,
|
||||||
metaKey: event.metaKey
|
metaKey: event.metaKey,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseWheelEvent(event: WheelEvent) {
|
function parseWheelEvent(event: WheelEvent) {
|
||||||
|
|
@ -113,7 +113,7 @@ function parseWheelEvent(event: WheelEvent) {
|
||||||
deltaX: event.deltaX,
|
deltaX: event.deltaX,
|
||||||
deltaY: event.deltaY,
|
deltaY: event.deltaY,
|
||||||
deltaZ: event.deltaZ,
|
deltaZ: event.deltaZ,
|
||||||
deltaMode: event.deltaMode
|
deltaMode: event.deltaMode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,8 +123,8 @@ function parseErrorEvent(event: ErrorEvent) {
|
||||||
message: event.message,
|
message: event.message,
|
||||||
filename: event.filename,
|
filename: event.filename,
|
||||||
lineno: event.lineno,
|
lineno: event.lineno,
|
||||||
colno: event.colno
|
colno: event.colno,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseProgressEvent(event: ProgressEvent) {
|
function parseProgressEvent(event: ProgressEvent) {
|
||||||
|
|
@ -132,7 +132,7 @@ function parseProgressEvent(event: ProgressEvent) {
|
||||||
type: event.type,
|
type: event.type,
|
||||||
lengthComputable: event.lengthComputable,
|
lengthComputable: event.lengthComputable,
|
||||||
loaded: event.loaded,
|
loaded: event.loaded,
|
||||||
total: event.total
|
total: event.total,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ function parseTouchEvent(event: TouchEvent) {
|
||||||
|
|
||||||
function parseTouch(touchList: TouchList) {
|
function parseTouch(touchList: TouchList) {
|
||||||
const touches: UITouchPoint[] = [];
|
const touches: UITouchPoint[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < touchList.length; i++) {
|
for (let i = 0; i < touchList.length; i++) {
|
||||||
const touch = touchList[i];
|
const touch = touchList[i];
|
||||||
touches.push({
|
touches.push({
|
||||||
|
|
@ -150,7 +150,7 @@ function parseTouchEvent(event: TouchEvent) {
|
||||||
screenX: touch.screenX,
|
screenX: touch.screenX,
|
||||||
screenY: touch.screenY,
|
screenY: touch.screenY,
|
||||||
pageX: touch.pageX,
|
pageX: touch.pageX,
|
||||||
pageY: touch.pageY
|
pageY: touch.pageY,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return touches;
|
return touches;
|
||||||
|
|
@ -165,7 +165,7 @@ function parseTouchEvent(event: TouchEvent) {
|
||||||
ctrlKey: event.ctrlKey,
|
ctrlKey: event.ctrlKey,
|
||||||
shiftKey: event.shiftKey,
|
shiftKey: event.shiftKey,
|
||||||
altKey: event.altKey,
|
altKey: event.altKey,
|
||||||
metaKey: event.metaKey
|
metaKey: event.metaKey,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +179,7 @@ function parseKeyboardEvent(event: KeyboardEvent) {
|
||||||
ctrlKey: event.ctrlKey,
|
ctrlKey: event.ctrlKey,
|
||||||
shiftKey: event.shiftKey,
|
shiftKey: event.shiftKey,
|
||||||
altKey: event.altKey,
|
altKey: event.altKey,
|
||||||
metaKey: event.metaKey
|
metaKey: event.metaKey,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,7 +193,7 @@ function parsePointerEvent(event: PointerEvent) {
|
||||||
tiltX: event.tiltX,
|
tiltX: event.tiltX,
|
||||||
tiltY: event.tiltY,
|
tiltY: event.tiltY,
|
||||||
pointerType: event.pointerType,
|
pointerType: event.pointerType,
|
||||||
isPrimary: event.isPrimary
|
isPrimary: event.isPrimary,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,7 +210,7 @@ function parseMouseEvent(event: MouseEvent) {
|
||||||
ctrlKey: event.ctrlKey,
|
ctrlKey: event.ctrlKey,
|
||||||
shiftKey: event.shiftKey,
|
shiftKey: event.shiftKey,
|
||||||
altKey: event.altKey,
|
altKey: event.altKey,
|
||||||
metaKey: event.metaKey
|
metaKey: event.metaKey,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,12 @@ export function toLogicalRootCommentElement(start: Comment, end: Comment): Logic
|
||||||
// |- *div
|
// |- *div
|
||||||
// |- *component
|
// |- *component
|
||||||
// |- *footer
|
// |- *footer
|
||||||
if(!start.parentNode){
|
if (!start.parentNode){
|
||||||
throw new Error(`Comment not connected to the DOM ${start.textContent}`);
|
throw new Error(`Comment not connected to the DOM ${start.textContent}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = start.parentNode;
|
const parent = start.parentNode;
|
||||||
const parentLogicalElement = toLogicalElement(parent, /* allow existing contents */ true);
|
const parentLogicalElement = toLogicalElement(parent, /* allow existing contents */ true);
|
||||||
const children = getLogicalChildrenArray(parentLogicalElement);
|
const children = getLogicalChildrenArray(parentLogicalElement);
|
||||||
Array.from(parent.childNodes).forEach(n => children.push(n as unknown as LogicalElement));
|
Array.from(parent.childNodes).forEach(n => children.push(n as unknown as LogicalElement));
|
||||||
start[logicalParentPropname] = parentLogicalElement;
|
start[logicalParentPropname] = parentLogicalElement;
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,13 @@ export class OutOfProcessRenderBatch implements RenderBatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
diffReader: RenderTreeDiffReader;
|
diffReader: RenderTreeDiffReader;
|
||||||
|
|
||||||
editReader: RenderTreeEditReader;
|
editReader: RenderTreeEditReader;
|
||||||
|
|
||||||
frameReader: RenderTreeFrameReader;
|
frameReader: RenderTreeFrameReader;
|
||||||
|
|
||||||
arrayRangeReader: ArrayRangeReader;
|
arrayRangeReader: ArrayRangeReader;
|
||||||
|
|
||||||
arraySegmentReader: ArraySegmentReader;
|
arraySegmentReader: ArraySegmentReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,30 +13,48 @@ export class SharedMemoryRenderBatch implements RenderBatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep in sync with memory layout in RenderBatch.cs
|
// Keep in sync with memory layout in RenderBatch.cs
|
||||||
updatedComponents() { return platform.readStructField<Pointer>(this.batchAddress, 0) as any as ArrayRange<RenderTreeDiff>; }
|
updatedComponents() {
|
||||||
referenceFrames() { return platform.readStructField<Pointer>(this.batchAddress, arrayRangeReader.structLength) as any as ArrayRange<RenderTreeDiff>; }
|
return platform.readStructField<Pointer>(this.batchAddress, 0) as any as ArrayRange<RenderTreeDiff>;
|
||||||
disposedComponentIds() { return platform.readStructField<Pointer>(this.batchAddress, arrayRangeReader.structLength * 2) as any as ArrayRange<number>; }
|
}
|
||||||
disposedEventHandlerIds() { return platform.readStructField<Pointer>(this.batchAddress, arrayRangeReader.structLength * 3) as any as ArrayRange<number>; }
|
|
||||||
|
referenceFrames() {
|
||||||
|
return platform.readStructField<Pointer>(this.batchAddress, arrayRangeReader.structLength) as any as ArrayRange<RenderTreeDiff>;
|
||||||
|
}
|
||||||
|
|
||||||
|
disposedComponentIds() {
|
||||||
|
return platform.readStructField<Pointer>(this.batchAddress, arrayRangeReader.structLength * 2) as any as ArrayRange<number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
disposedEventHandlerIds() {
|
||||||
|
return platform.readStructField<Pointer>(this.batchAddress, arrayRangeReader.structLength * 3) as any as ArrayRange<number>;
|
||||||
|
}
|
||||||
|
|
||||||
updatedComponentsEntry(values: ArrayValues<RenderTreeDiff>, index: number) {
|
updatedComponentsEntry(values: ArrayValues<RenderTreeDiff>, index: number) {
|
||||||
return arrayValuesEntry(values, index, diffReader.structLength);
|
return arrayValuesEntry(values, index, diffReader.structLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
referenceFramesEntry(values: ArrayValues<RenderTreeFrame>, index: number) {
|
referenceFramesEntry(values: ArrayValues<RenderTreeFrame>, index: number) {
|
||||||
return arrayValuesEntry(values, index, frameReader.structLength);
|
return arrayValuesEntry(values, index, frameReader.structLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
disposedComponentIdsEntry(values: ArrayValues<number>, index: number) {
|
disposedComponentIdsEntry(values: ArrayValues<number>, index: number) {
|
||||||
const pointer = arrayValuesEntry(values, index, /* int length */ 4);
|
const pointer = arrayValuesEntry(values, index, /* int length */ 4);
|
||||||
return platform.readInt32Field(pointer as any as Pointer);
|
return platform.readInt32Field(pointer as any as Pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
disposedEventHandlerIdsEntry(values: ArrayValues<number>, index: number) {
|
disposedEventHandlerIdsEntry(values: ArrayValues<number>, index: number) {
|
||||||
const pointer = arrayValuesEntry(values, index, /* int length */ 4);
|
const pointer = arrayValuesEntry(values, index, /* int length */ 4);
|
||||||
return platform.readInt32Field(pointer as any as Pointer);
|
return platform.readInt32Field(pointer as any as Pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
arrayRangeReader = arrayRangeReader;
|
arrayRangeReader = arrayRangeReader;
|
||||||
|
|
||||||
arraySegmentReader = arraySegmentReader;
|
arraySegmentReader = arraySegmentReader;
|
||||||
|
|
||||||
diffReader = diffReader;
|
diffReader = diffReader;
|
||||||
|
|
||||||
editReader = editReader;
|
editReader = editReader;
|
||||||
|
|
||||||
frameReader = frameReader;
|
frameReader = frameReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ const nativeDecoder = typeof TextDecoder === 'function'
|
||||||
export const decodeUtf8: (bytes: Uint8Array) => string
|
export const decodeUtf8: (bytes: Uint8Array) => string
|
||||||
= nativeDecoder ? nativeDecoder.decode.bind(nativeDecoder) : decodeImpl;
|
= nativeDecoder ? nativeDecoder.decode.bind(nativeDecoder) : decodeImpl;
|
||||||
|
|
||||||
/*!
|
/* !
|
||||||
Logic in decodeImpl is derived from fast-text-encoding
|
Logic in decodeImpl is derived from fast-text-encoding
|
||||||
https://github.com/samthor/fast-text-encoding
|
https://github.com/samthor/fast-text-encoding
|
||||||
|
|
||||||
|
|
@ -22,12 +22,12 @@ function decodeImpl(bytes: Uint8Array): string {
|
||||||
while (pos < len) {
|
while (pos < len) {
|
||||||
const byte1 = bytes[pos++];
|
const byte1 = bytes[pos++];
|
||||||
if (byte1 === 0) {
|
if (byte1 === 0) {
|
||||||
break; // NULL
|
break; // NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((byte1 & 0x80) === 0) { // 1-byte
|
if ((byte1 & 0x80) === 0) { // 1-byte
|
||||||
out.push(byte1);
|
out.push(byte1);
|
||||||
} else if ((byte1 & 0xe0) === 0xc0) { // 2-byte
|
} else if ((byte1 & 0xe0) === 0xc0) { // 2-byte
|
||||||
const byte2 = bytes[pos++] & 0x3f;
|
const byte2 = bytes[pos++] & 0x3f;
|
||||||
out.push(((byte1 & 0x1f) << 6) | byte2);
|
out.push(((byte1 & 0x1f) << 6) | byte2);
|
||||||
} else if ((byte1 & 0xf0) === 0xe0) {
|
} else if ((byte1 & 0xf0) === 0xe0) {
|
||||||
|
|
@ -44,7 +44,7 @@ function decodeImpl(bytes: Uint8Array): string {
|
||||||
if (codepoint > 0xffff) {
|
if (codepoint > 0xffff) {
|
||||||
// codepoint &= ~0x10000;
|
// codepoint &= ~0x10000;
|
||||||
codepoint -= 0x10000;
|
codepoint -= 0x10000;
|
||||||
out.push((codepoint >>> 10) & 0x3ff | 0xd800)
|
out.push((codepoint >>> 10) & 0x3ff | 0xd800);
|
||||||
codepoint = 0xdc00 | codepoint & 0x3ff;
|
codepoint = 0xdc00 | codepoint & 0x3ff;
|
||||||
}
|
}
|
||||||
out.push(codepoint);
|
out.push(codepoint);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ let allocateArrayMethod: MethodHandle;
|
||||||
|
|
||||||
// These are the functions we're making available for invocation from .NET
|
// These are the functions we're making available for invocation from .NET
|
||||||
export const internalFunctions = {
|
export const internalFunctions = {
|
||||||
sendAsync
|
sendAsync,
|
||||||
}
|
};
|
||||||
|
|
||||||
async function sendAsync(id: number, body: System_Array<any>, jsonFetchArgs: System_String) {
|
async function sendAsync(id: number, body: System_Array<any>, jsonFetchArgs: System_String) {
|
||||||
let response: Response;
|
let response: Response;
|
||||||
|
|
@ -37,7 +37,7 @@ function dispatchSuccessResponse(id: number, response: Response, responseData: A
|
||||||
const responseDescriptor: ResponseDescriptor = {
|
const responseDescriptor: ResponseDescriptor = {
|
||||||
statusCode: response.status,
|
statusCode: response.status,
|
||||||
statusText: response.statusText,
|
statusText: response.statusText,
|
||||||
headers: []
|
headers: [],
|
||||||
};
|
};
|
||||||
response.headers.forEach((value, name) => {
|
response.headers.forEach((value, name) => {
|
||||||
responseDescriptor.headers.push([name, value]);
|
responseDescriptor.headers.push([name, value]);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import '@dotnet/jsinterop';
|
||||||
let hasRegisteredEventListeners = false;
|
let hasRegisteredEventListeners = false;
|
||||||
|
|
||||||
// Will be initialized once someone registers
|
// Will be initialized once someone registers
|
||||||
let notifyLocationChangedCallback: { assemblyName: string, functionName: string } | null = null;
|
let notifyLocationChangedCallback: { assemblyName: string; functionName: string } | null = null;
|
||||||
|
|
||||||
// These are the functions we're making available for invocation from .NET
|
// These are the functions we're making available for invocation from .NET
|
||||||
export const internalFunctions = {
|
export const internalFunctions = {
|
||||||
|
|
@ -11,7 +11,7 @@ export const internalFunctions = {
|
||||||
navigateTo,
|
navigateTo,
|
||||||
getBaseURI: () => document.baseURI,
|
getBaseURI: () => document.baseURI,
|
||||||
getLocationHref: () => location.href,
|
getLocationHref: () => location.href,
|
||||||
}
|
};
|
||||||
|
|
||||||
function enableNavigationInterception(assemblyName: string, functionName: string) {
|
function enableNavigationInterception(assemblyName: string, functionName: string) {
|
||||||
if (hasRegisteredEventListeners || assemblyName === undefined || functionName === undefined) {
|
if (hasRegisteredEventListeners || assemblyName === undefined || functionName === undefined) {
|
||||||
|
|
@ -80,7 +80,7 @@ function findClosestAncestor(element: Element | null, tagName: string) {
|
||||||
? null
|
? null
|
||||||
: element.tagName === tagName
|
: element.tagName === tagName
|
||||||
? element
|
? element
|
||||||
: findClosestAncestor(element.parentElement, tagName)
|
: findClosestAncestor(element.parentElement, tagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isWithinBaseUriSpace(href: string) {
|
function isWithinBaseUriSpace(href: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue