-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
GlobalExports.ts
117 lines (107 loc) · 5.95 KB
/
GlobalExports.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import { navigateTo, internalFunctions as navigationManagerInternalFunctions, NavigationOptions } from './Services/NavigationManager';
import { domFunctions } from './DomWrapper';
import { Virtualize } from './Virtualize';
import { PageTitle } from './PageTitle';
import { registerCustomEventType, EventTypeOptions } from './Rendering/Events/EventTypes';
import { HubConnection } from '@microsoft/signalr';
import { InputFile } from './InputFile';
import { NavigationLock } from './NavigationLock';
import { DefaultReconnectionHandler } from './Platform/Circuits/DefaultReconnectionHandler';
import { CircuitStartOptions } from './Platform/Circuits/CircuitStartOptions';
import { WebAssemblyStartOptions } from './Platform/WebAssemblyStartOptions';
import { Platform, Pointer } from './Platform/Platform';
import { getNextChunk } from './StreamingInterop';
import { RootComponentsFunctions } from './Rendering/JSRootComponents';
import { attachWebRendererInterop } from './Rendering/WebRendererInteropMethods';
import { WebStartOptions } from './Platform/WebStartOptions';
import { RuntimeAPI } from 'dotnet-runtime';
import { JSEventRegistry } from './Services/JSEventRegistry';
// TODO: It's kind of hard to tell which .NET platform(s) some of these APIs are relevant to.
// It's important to know this information when dealing with the possibility of mulitple .NET platforms being available.
// e.g., which of these APIs need to account for there being multiple .NET runtimes, and which don't?
// We should consider separating it all out so that we can easily identify the platform requirements of each API.
// For example:
// * Blazor.{foo}: public Blazor APIs
// * Blazor._internal.{foo}: internal, platform-agnostic Blazor APIs
// * Blazor.platform.{somePlatformName}.{foo}: public, platform-specific Blazor APIs (would be empty at first, so no initial breaking changes)
// * Blazor.platform.{somePlatformName}.{_internal}.{foo}: internal, platform-specific Blazor APIs
export interface IBlazor {
navigateTo: (uri: string, options: NavigationOptions) => void;
registerCustomEventType: (eventName: string, options: EventTypeOptions) => void;
addEventListener?: typeof JSEventRegistry.prototype.addEventListener;
removeEventListener?: typeof JSEventRegistry.prototype.removeEventListener;
disconnect?: () => void;
reconnect?: (existingConnection?: HubConnection) => Promise<boolean>;
defaultReconnectionHandler?: DefaultReconnectionHandler;
start?: ((userOptions?: Partial<CircuitStartOptions>) => Promise<void>) | ((options?: Partial<WebAssemblyStartOptions>) => Promise<void>) | ((options?: Partial<WebStartOptions>) => Promise<void>);
platform?: Platform;
rootComponents: typeof RootComponentsFunctions;
runtime: RuntimeAPI,
_internal: {
navigationManager: typeof navigationManagerInternalFunctions | any;
domWrapper: typeof domFunctions;
Virtualize: typeof Virtualize;
PageTitle: typeof PageTitle;
forceCloseConnection?: () => Promise<void>;
InputFile?: typeof InputFile;
NavigationLock: typeof NavigationLock;
invokeJSJson?: (identifier: string, targetInstanceId: number, resultType: number, argsJson: string, asyncHandle: number) => string | null;
endInvokeDotNetFromJS?: (callId: string, success: boolean, resultJsonOrErrorMessage: string) => void;
receiveByteArray?: (id: number, data: Uint8Array) => void;
getPersistedState?: () => string;
getInitialComponentsUpdate?: () => Promise<string>;
updateRootComponents?: (operations: string) => void;
endUpdateRootComponents?: (batchId: number) => void;
attachRootComponentToElement?: (arg0: any, arg1: any, arg2: any, arg3: any) => void;
registeredComponents?: {
getRegisteredComponentsCount: () => number;
getAssembly: (id) => string;
getTypeName: (id) => string;
getParameterDefinitions: (id) => string;
getParameterValues: (id) => any;
};
renderBatch?: (browserRendererId: number, batchAddress: Pointer) => void;
getConfig?: (fileName: string) => Uint8Array | undefined;
getApplicationEnvironment?: () => string;
dotNetCriticalError?: any;
loadLazyAssembly?: any;
loadSatelliteAssemblies?: any;
sendJSDataStream?: (data: any, streamId: number, chunkSize: number) => void;
getJSDataStreamChunk?: (data: any, position: number, chunkSize: number) => Promise<Uint8Array>;
receiveWebAssemblyDotNetDataStream?: (streamId: number, data: any, bytesRead: number, errorMessage: string) => void;
receiveWebViewDotNetDataStream?: (streamId: number, data: any, bytesRead: number, errorMessage: string) => void;
attachWebRendererInterop?: typeof attachWebRendererInterop;
// JSExport APIs
dotNetExports?: {
InvokeDotNet: (assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number, argsJson: string) => string | null;
EndInvokeJS: (argsJson: string) => void;
BeginInvokeDotNet: (callId: string | null, assemblyNameOrDotNetObjectId: string, methodIdentifier: string, argsJson: string) => void;
ReceiveByteArrayFromJS: (id: number, data: Uint8Array) => void;
UpdateRootComponentsCore: (operationsJson: string) => void;
}
// APIs invoked by hot reload
applyHotReload?: (id: string, metadataDelta: string, ilDelta: string, pdbDelta: string | undefined, updatedTypes?: number[]) => void;
getApplyUpdateCapabilities?: () => string;
hotReloadApplied?: () => void;
}
}
export const Blazor: IBlazor = {
navigateTo,
registerCustomEventType,
rootComponents: RootComponentsFunctions,
runtime: {} as RuntimeAPI,
_internal: {
navigationManager: navigationManagerInternalFunctions,
domWrapper: domFunctions,
Virtualize,
PageTitle,
InputFile,
NavigationLock,
getJSDataStreamChunk: getNextChunk,
attachWebRendererInterop,
},
};
// Make the following APIs available in global scope for invocation from JS
window['Blazor'] = Blazor;