piral-blazor 1.0.0-pre.2217 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +55 -12
  3. package/convert.d.ts +13 -10
  4. package/convert.js +17 -12
  5. package/esm/converter.d.ts +10 -6
  6. package/esm/converter.js +164 -48
  7. package/esm/converter.js.map +1 -1
  8. package/esm/create.d.ts +21 -1
  9. package/esm/create.js +29 -15
  10. package/esm/create.js.map +1 -1
  11. package/esm/dependencies.d.ts +6 -3
  12. package/esm/dependencies.js +104 -14
  13. package/esm/dependencies.js.map +1 -1
  14. package/esm/events.d.ts +6 -0
  15. package/esm/events.js +145 -0
  16. package/esm/events.js.map +1 -0
  17. package/esm/interop.d.ts +29 -0
  18. package/esm/interop.js +205 -0
  19. package/esm/interop.js.map +1 -0
  20. package/esm/navigation.d.ts +2 -0
  21. package/esm/navigation.js +30 -0
  22. package/esm/navigation.js.map +1 -0
  23. package/esm/types.d.ts +97 -4
  24. package/infra.codegen +53 -68
  25. package/lib/converter.d.ts +10 -6
  26. package/lib/converter.js +164 -48
  27. package/lib/converter.js.map +1 -1
  28. package/lib/create.d.ts +21 -1
  29. package/lib/create.js +31 -17
  30. package/lib/create.js.map +1 -1
  31. package/lib/dependencies.d.ts +6 -3
  32. package/lib/dependencies.js +104 -14
  33. package/lib/dependencies.js.map +1 -1
  34. package/lib/events.d.ts +6 -0
  35. package/lib/events.js +154 -0
  36. package/lib/events.js.map +1 -0
  37. package/lib/index.js +1 -1
  38. package/lib/interop.d.ts +29 -0
  39. package/lib/interop.js +226 -0
  40. package/lib/interop.js.map +1 -0
  41. package/lib/navigation.d.ts +2 -0
  42. package/lib/navigation.js +35 -0
  43. package/lib/navigation.js.map +1 -0
  44. package/lib/types.d.ts +97 -4
  45. package/package.json +26 -13
  46. package/src/converter.ts +237 -57
  47. package/src/create.ts +53 -9
  48. package/src/dependencies.ts +122 -14
  49. package/src/events.ts +174 -0
  50. package/src/interop.ts +273 -0
  51. package/src/navigation.ts +36 -0
  52. package/src/types.ts +115 -4
  53. package/convert.ts +0 -17
  54. package/esm/internal/Environment.d.ts +0 -3
  55. package/esm/internal/Environment.js +0 -6
  56. package/esm/internal/Environment.js.map +0 -1
  57. package/esm/internal/Platform/BootConfig.d.ts +0 -20
  58. package/esm/internal/Platform/BootConfig.js +0 -10
  59. package/esm/internal/Platform/BootConfig.js.map +0 -1
  60. package/esm/internal/Platform/Mono/MonoDebugger.d.ts +0 -3
  61. package/esm/internal/Platform/Mono/MonoDebugger.js +0 -43
  62. package/esm/internal/Platform/Mono/MonoDebugger.js.map +0 -1
  63. package/esm/internal/Platform/Mono/MonoPlatform.d.ts +0 -2
  64. package/esm/internal/Platform/Mono/MonoPlatform.js +0 -403
  65. package/esm/internal/Platform/Mono/MonoPlatform.js.map +0 -1
  66. package/esm/internal/Platform/Mono/TimezoneDataFile.d.ts +0 -1
  67. package/esm/internal/Platform/Mono/TimezoneDataFile.js +0 -51
  68. package/esm/internal/Platform/Mono/TimezoneDataFile.js.map +0 -1
  69. package/esm/internal/Platform/Platform.d.ts +0 -31
  70. package/esm/internal/Platform/Platform.js +0 -2
  71. package/esm/internal/Platform/Platform.js.map +0 -1
  72. package/esm/internal/Platform/Url.d.ts +0 -2
  73. package/esm/internal/Platform/Url.js +0 -11
  74. package/esm/internal/Platform/Url.js.map +0 -1
  75. package/esm/internal/Platform/WebAssemblyConfigLoader.d.ts +0 -4
  76. package/esm/internal/Platform/WebAssemblyConfigLoader.js +0 -64
  77. package/esm/internal/Platform/WebAssemblyConfigLoader.js.map +0 -1
  78. package/esm/internal/Platform/WebAssemblyResourceLoader.d.ts +0 -24
  79. package/esm/internal/Platform/WebAssemblyResourceLoader.js +0 -223
  80. package/esm/internal/Platform/WebAssemblyResourceLoader.js.map +0 -1
  81. package/esm/internal/Platform/WebAssemblyStartOptions.d.ts +0 -13
  82. package/esm/internal/Platform/WebAssemblyStartOptions.js +0 -2
  83. package/esm/internal/Platform/WebAssemblyStartOptions.js.map +0 -1
  84. package/esm/internal/Rendering/BrowserRenderer.d.ts +0 -38
  85. package/esm/internal/Rendering/BrowserRenderer.js +0 -458
  86. package/esm/internal/Rendering/BrowserRenderer.js.map +0 -1
  87. package/esm/internal/Rendering/ElementReferenceCapture.d.ts +0 -1
  88. package/esm/internal/Rendering/ElementReferenceCapture.js +0 -24
  89. package/esm/internal/Rendering/ElementReferenceCapture.js.map +0 -1
  90. package/esm/internal/Rendering/EventDelegator.d.ts +0 -20
  91. package/esm/internal/Rendering/EventDelegator.js +0 -236
  92. package/esm/internal/Rendering/EventDelegator.js.map +0 -1
  93. package/esm/internal/Rendering/EventFieldInfo.d.ts +0 -6
  94. package/esm/internal/Rendering/EventFieldInfo.js +0 -32
  95. package/esm/internal/Rendering/EventFieldInfo.js.map +0 -1
  96. package/esm/internal/Rendering/EventForDotNet.d.ts +0 -10
  97. package/esm/internal/Rendering/EventForDotNet.js +0 -194
  98. package/esm/internal/Rendering/EventForDotNet.js.map +0 -1
  99. package/esm/internal/Rendering/LogicalElements.d.ts +0 -19
  100. package/esm/internal/Rendering/LogicalElements.js +0 -250
  101. package/esm/internal/Rendering/LogicalElements.js.map +0 -1
  102. package/esm/internal/Rendering/RenderBatch/BinaryDecoder.d.ts +0 -5
  103. package/esm/internal/Rendering/RenderBatch/BinaryDecoder.js +0 -34
  104. package/esm/internal/Rendering/RenderBatch/BinaryDecoder.js.map +0 -1
  105. package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.d.ts +0 -18
  106. package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js +0 -190
  107. package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js.map +0 -1
  108. package/esm/internal/Rendering/RenderBatch/RenderBatch.d.ts +0 -87
  109. package/esm/internal/Rendering/RenderBatch/RenderBatch.js +0 -26
  110. package/esm/internal/Rendering/RenderBatch/RenderBatch.js.map +0 -1
  111. package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.d.ts +0 -52
  112. package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js +0 -103
  113. package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js.map +0 -1
  114. package/esm/internal/Rendering/RenderBatch/Utf8Decoder.d.ts +0 -1
  115. package/esm/internal/Rendering/RenderBatch/Utf8Decoder.js +0 -63
  116. package/esm/internal/Rendering/RenderBatch/Utf8Decoder.js.map +0 -1
  117. package/esm/internal/Rendering/Renderer.d.ts +0 -8
  118. package/esm/internal/Rendering/Renderer.js +0 -69
  119. package/esm/internal/Rendering/Renderer.js.map +0 -1
  120. package/esm/internal/Rendering/RendererEventDispatcher.d.ts +0 -4
  121. package/esm/internal/Rendering/RendererEventDispatcher.js +0 -11
  122. package/esm/internal/Rendering/RendererEventDispatcher.js.map +0 -1
  123. package/esm/internal/Services/NavigationManager.d.ts +0 -16
  124. package/esm/internal/Services/NavigationManager.js +0 -138
  125. package/esm/internal/Services/NavigationManager.js.map +0 -1
  126. package/esm/internal/globals.d.ts +0 -1
  127. package/esm/internal/globals.js +0 -5
  128. package/esm/internal/globals.js.map +0 -1
  129. package/esm/internal/index.d.ts +0 -15
  130. package/esm/internal/index.js +0 -152
  131. package/esm/internal/index.js.map +0 -1
  132. package/lib/internal/Environment.d.ts +0 -3
  133. package/lib/internal/Environment.js +0 -9
  134. package/lib/internal/Environment.js.map +0 -1
  135. package/lib/internal/Platform/BootConfig.d.ts +0 -20
  136. package/lib/internal/Platform/BootConfig.js +0 -13
  137. package/lib/internal/Platform/BootConfig.js.map +0 -1
  138. package/lib/internal/Platform/Mono/MonoDebugger.d.ts +0 -3
  139. package/lib/internal/Platform/Mono/MonoDebugger.js +0 -48
  140. package/lib/internal/Platform/Mono/MonoDebugger.js.map +0 -1
  141. package/lib/internal/Platform/Mono/MonoPlatform.d.ts +0 -2
  142. package/lib/internal/Platform/Mono/MonoPlatform.js +0 -406
  143. package/lib/internal/Platform/Mono/MonoPlatform.js.map +0 -1
  144. package/lib/internal/Platform/Mono/TimezoneDataFile.d.ts +0 -1
  145. package/lib/internal/Platform/Mono/TimezoneDataFile.js +0 -55
  146. package/lib/internal/Platform/Mono/TimezoneDataFile.js.map +0 -1
  147. package/lib/internal/Platform/Platform.d.ts +0 -31
  148. package/lib/internal/Platform/Platform.js +0 -3
  149. package/lib/internal/Platform/Platform.js.map +0 -1
  150. package/lib/internal/Platform/Url.d.ts +0 -2
  151. package/lib/internal/Platform/Url.js +0 -16
  152. package/lib/internal/Platform/Url.js.map +0 -1
  153. package/lib/internal/Platform/WebAssemblyConfigLoader.d.ts +0 -4
  154. package/lib/internal/Platform/WebAssemblyConfigLoader.js +0 -67
  155. package/lib/internal/Platform/WebAssemblyConfigLoader.js.map +0 -1
  156. package/lib/internal/Platform/WebAssemblyResourceLoader.d.ts +0 -24
  157. package/lib/internal/Platform/WebAssemblyResourceLoader.js +0 -226
  158. package/lib/internal/Platform/WebAssemblyResourceLoader.js.map +0 -1
  159. package/lib/internal/Platform/WebAssemblyStartOptions.d.ts +0 -13
  160. package/lib/internal/Platform/WebAssemblyStartOptions.js +0 -3
  161. package/lib/internal/Platform/WebAssemblyStartOptions.js.map +0 -1
  162. package/lib/internal/Rendering/BrowserRenderer.d.ts +0 -38
  163. package/lib/internal/Rendering/BrowserRenderer.js +0 -461
  164. package/lib/internal/Rendering/BrowserRenderer.js.map +0 -1
  165. package/lib/internal/Rendering/ElementReferenceCapture.d.ts +0 -1
  166. package/lib/internal/Rendering/ElementReferenceCapture.js +0 -28
  167. package/lib/internal/Rendering/ElementReferenceCapture.js.map +0 -1
  168. package/lib/internal/Rendering/EventDelegator.d.ts +0 -20
  169. package/lib/internal/Rendering/EventDelegator.js +0 -239
  170. package/lib/internal/Rendering/EventDelegator.js.map +0 -1
  171. package/lib/internal/Rendering/EventFieldInfo.d.ts +0 -6
  172. package/lib/internal/Rendering/EventFieldInfo.js +0 -35
  173. package/lib/internal/Rendering/EventFieldInfo.js.map +0 -1
  174. package/lib/internal/Rendering/EventForDotNet.d.ts +0 -10
  175. package/lib/internal/Rendering/EventForDotNet.js +0 -197
  176. package/lib/internal/Rendering/EventForDotNet.js.map +0 -1
  177. package/lib/internal/Rendering/LogicalElements.d.ts +0 -19
  178. package/lib/internal/Rendering/LogicalElements.js +0 -265
  179. package/lib/internal/Rendering/LogicalElements.js.map +0 -1
  180. package/lib/internal/Rendering/RenderBatch/BinaryDecoder.d.ts +0 -5
  181. package/lib/internal/Rendering/RenderBatch/BinaryDecoder.js +0 -42
  182. package/lib/internal/Rendering/RenderBatch/BinaryDecoder.js.map +0 -1
  183. package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.d.ts +0 -18
  184. package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js +0 -193
  185. package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js.map +0 -1
  186. package/lib/internal/Rendering/RenderBatch/RenderBatch.d.ts +0 -87
  187. package/lib/internal/Rendering/RenderBatch/RenderBatch.js +0 -29
  188. package/lib/internal/Rendering/RenderBatch/RenderBatch.js.map +0 -1
  189. package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.d.ts +0 -52
  190. package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js +0 -106
  191. package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js.map +0 -1
  192. package/lib/internal/Rendering/RenderBatch/Utf8Decoder.d.ts +0 -1
  193. package/lib/internal/Rendering/RenderBatch/Utf8Decoder.js +0 -66
  194. package/lib/internal/Rendering/RenderBatch/Utf8Decoder.js.map +0 -1
  195. package/lib/internal/Rendering/Renderer.d.ts +0 -8
  196. package/lib/internal/Rendering/Renderer.js +0 -76
  197. package/lib/internal/Rendering/Renderer.js.map +0 -1
  198. package/lib/internal/Rendering/RendererEventDispatcher.d.ts +0 -4
  199. package/lib/internal/Rendering/RendererEventDispatcher.js +0 -16
  200. package/lib/internal/Rendering/RendererEventDispatcher.js.map +0 -1
  201. package/lib/internal/Services/NavigationManager.d.ts +0 -16
  202. package/lib/internal/Services/NavigationManager.js +0 -144
  203. package/lib/internal/Services/NavigationManager.js.map +0 -1
  204. package/lib/internal/globals.d.ts +0 -1
  205. package/lib/internal/globals.js +0 -7
  206. package/lib/internal/globals.js.map +0 -1
  207. package/lib/internal/index.d.ts +0 -15
  208. package/lib/internal/index.js +0 -161
  209. package/lib/internal/index.js.map +0 -1
  210. package/src/internal/Environment.ts +0 -11
  211. package/src/internal/Platform/BootConfig.ts +0 -21
  212. package/src/internal/Platform/Mono/MonoDebugger.ts +0 -48
  213. package/src/internal/Platform/Mono/MonoPlatform.ts +0 -494
  214. package/src/internal/Platform/Mono/MonoTypes.d.ts +0 -27
  215. package/src/internal/Platform/Mono/TimezoneDataFile.ts +0 -46
  216. package/src/internal/Platform/Platform.ts +0 -40
  217. package/src/internal/Platform/Url.ts +0 -11
  218. package/src/internal/Platform/WebAssemblyConfigLoader.ts +0 -34
  219. package/src/internal/Platform/WebAssemblyResourceLoader.ts +0 -234
  220. package/src/internal/Platform/WebAssemblyStartOptions.ts +0 -22
  221. package/src/internal/Rendering/BrowserRenderer.ts +0 -616
  222. package/src/internal/Rendering/ElementReferenceCapture.ts +0 -27
  223. package/src/internal/Rendering/EventDelegator.ts +0 -293
  224. package/src/internal/Rendering/EventFieldInfo.ts +0 -31
  225. package/src/internal/Rendering/EventForDotNet.ts +0 -370
  226. package/src/internal/Rendering/LogicalElements.ts +0 -289
  227. package/src/internal/Rendering/RenderBatch/BinaryDecoder.ts +0 -43
  228. package/src/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.ts +0 -244
  229. package/src/internal/Rendering/RenderBatch/RenderBatch.ts +0 -100
  230. package/src/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.ts +0 -137
  231. package/src/internal/Rendering/RenderBatch/Utf8Decoder.ts +0 -66
  232. package/src/internal/Rendering/Renderer.ts +0 -98
  233. package/src/internal/Rendering/RendererEventDispatcher.ts +0 -20
  234. package/src/internal/Services/NavigationManager.ts +0 -157
  235. package/src/internal/globals.ts +0 -5
  236. package/src/internal/index.ts +0 -170
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 - 2021 smapiot
3
+ Copyright (c) 2019 - 2023 smapiot
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- [![Piral Logo](https://github.com/smapiot/piral/raw/master/docs/assets/logo.png)](https://piral.io)
1
+ [![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io)
2
2
 
3
- # [Piral Blazor](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-blazor.svg?style=flat)](https://www.npmjs.com/package/piral-blazor) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
3
+ # [Piral Blazor](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-blazor.svg?style=flat)](https://www.npmjs.com/package/piral-blazor) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
4
4
 
5
- This is a plugin that only has a peer dependency to `piral-core`. What `piral-blazor` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
5
+ This is a plugin that has a peer dependency to `blazor`. What `piral-blazor` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
6
6
 
7
7
  The set includes a Blazor (WASM) loader and converter for any component registration, as well as a `fromBlazor` shortcut together with some Blazor component coming in the `Piral.Blazor.Utils` NuGet package.
8
8
 
@@ -66,9 +66,9 @@ Blazor with Piral works from two sides. We have the app shell's side and the sid
66
66
 
67
67
  The diagram has the following pieces:
68
68
 
69
- 1. Your app shell using `piral`, which needs to reference the `piral-blazor` plugin. Effectively, this will download and use the `Piral.Blazor.Core` NuGet package at build-time to include the common libraries.
70
- 2. The TypeScript file in your Blazor pilets. That file will export the `setup` function to define which Blazor components to register / use in your app shell.
71
- 3. The Blazor code in your Blazor pilets using the shared library `Piral.Blazor.Utils` for some convenience functions. This code will define all the Blazor components that can be registered / used in the pilet.
69
+ 1. Your app shell using `piral`, which needs to reference the `piral-blazor` plugin. Effectively, this will use the `blazor` package at build-time to include the Blazor libraries. Additionally, it uses `Piral.Blazor.Core` to be able to reference the defined Blazor components.
70
+ 2. The TypeScript file in your Blazor pilets. That file will export the `setup` function to define which Blazor components to register/use in your app shell.
71
+ 3. The Blazor code in your Blazor pilets using the shared library `Piral.Blazor.Utils` for some convenience functions. This code will define all the Blazor components that can be registered/used in the pilet.
72
72
 
73
73
  Naturally, you can add other dependencies to your Blazor pilet, too. These can be other npm packages for extending the JS part. Usually, however, you will add more NuGet packages to enhance your Blazor code.
74
74
 
@@ -82,7 +82,7 @@ The following functions are brought to the Pilet API.
82
82
 
83
83
  Adds the URLs to additional DLLs that need to be referenced for obtaining the Blazor components. At best this uses `require.resolve` to get the URL from the bundler.
84
84
 
85
- When you use the `blazorpilet` template you don't need to fill / use this. It is automatically used and filled with generated code. Only touch this one if you know what you are doing.
85
+ When you use the `blazorpilet` template you don't need to fill/use this. It is automatically used and filled with generated code. Only touch this one if you know what you are doing.
86
86
 
87
87
  ### `fromBlazor()`
88
88
 
@@ -120,7 +120,7 @@ Alternatively, if `piral-blazor` has not been added to the Piral instance you ca
120
120
 
121
121
  ```ts
122
122
  import { PiletApi } from '<name-of-piral-instance>';
123
- import { defineBlazorReferences, fromBlazor } from 'piral-blazor';
123
+ import { defineBlazorReferences, fromBlazor } from 'piral-blazor/convert';
124
124
 
125
125
  export function setup(piral: PiletApi) {
126
126
  defineBlazorReferences([
@@ -131,11 +131,15 @@ export function setup(piral: PiletApi) {
131
131
  }
132
132
  ```
133
133
 
134
+ In this case, you'll also have to install the `blazor` package. `piral-blazor` will use this under the hood to access the Blazor libraries.
135
+
136
+ To maximize compatibility, the major and minor version of the `blazor` package should correspond to the major and minor version of .NET Blazor you want to use (e.g., `blazor@3.2.x` will resolve to the .NET Blazor `3.2` release train). It should be noted that the patch level is not aligned. If a specific patch level is desired, consult the `blazor` package documentation.
137
+
134
138
  :::
135
139
 
136
140
  ::: summary: For Piral instance developers
137
141
 
138
- Using Blazor with Piral is as simple as installing `piral-blazor`.
142
+ Using Blazor with Piral is as simple as installing the `piral-blazor` and `blazor` packages.
139
143
 
140
144
  ```ts
141
145
  import { createBlazorApi } from 'piral-blazor';
@@ -150,15 +154,54 @@ const instance = createInstance({
150
154
  // ...
151
155
  });
152
156
  ```
157
+ `piral-blazor` will use `blazor` under the hood to access the Blazor libraries.
158
+
159
+ To maximize compatibility, the major and minor version of the `blazor` package should correspond to the major and minor version of .NET Blazor you want to use (e.g., `blazor@3.2.x` will resolve to the .NET Blazor `3.2` release train). It should be noted that the patch level is not aligned. If a specific patch level is desired, consult the `blazor` package documentation.
153
160
 
154
- This will automatically download and include the necessary binary files for providing Blazor WASM support. The binary files will be taken from the `Piral.Blazor.Core` NuGet package.
161
+ For setting up localization you can supply options such as `initialLanguage` and `onLanguageChange` to the `createBlazorApi` call. While the former is used to set the initial language, the latter can be used to change the language later on. By default, `onLanguageChange` will be configured to listen to the `select-language` event emitted from Piral. This event is emitted (among others) by `piral-translate`, i.e., if you use this plugin it will just work.
155
162
 
156
- By default, the latest version of the `Piral.Blazor.Core` NuGet package is downloaded. To change this set the `PIRAL_BLAZOR_VERSION` environment variable to the desired version.
163
+ Otherwise, you can either emit the event yourself (transporting an object with `currentLanguage` set to the desired language), or use `onLanguageChange` to wire it to whatever event source / emitter you'd like.
164
+
165
+ Ultimately, you can also call the `SetLanguage` in Piral.Blazor.Core from JavaScript like this:
166
+
167
+ ```js
168
+ window.DotNet.invokeMethodAsync('Piral.Blazor.Core', 'SetLanguage', language);
169
+ ```
157
170
 
158
- Alternatively, you can also use a local version of the `Piral.Blazor.Core` NuGet package. For this, set the `PIRAL_BLAZOR_LOCAL_NUPKG` environment variable to the (absolute) path of the NuGet package.
171
+ Furthermore, it is possible to configure the (initial) log level via the `logLevel` option:
172
+
173
+ ```ts
174
+ const instance = createInstance({
175
+ // important part
176
+ plugins: [createBlazorApi({
177
+ logLevel: 1, // everything except trace
178
+ })],
179
+ // ...
180
+ });
181
+ ```
182
+
183
+ The levels range from 0 (incl. trace) to 6 (nothing will be logged).
159
184
 
160
185
  :::
161
186
 
187
+ ## Events
188
+
189
+ The `piral-blazor` integration emits some events at the global object (`window`):
190
+
191
+ - `loading-blazor-core` when the loading of (core) Blazor resources starts
192
+ - `loaded-blazor-core` when the loading of (core) Blazor resources ends
193
+ - `loading-blazor-pilet` when the loading of a Blazor pilet / its resources starts (`detail` contains the pilet's metadata)
194
+ - `loaded-blazor-pilet` when the loading of a Blazor pilet / its resources ends (`detail` contains the pilet's metadata)
195
+
196
+ You can receive these events using, e.g.:
197
+
198
+ ```js
199
+ window.addEventListener('loaded-blazor-pilet', (ev) => {
200
+ // your code here - could use:
201
+ // ev.detail.name --> name of the pilet
202
+ });
203
+ ```
204
+
162
205
  ## License
163
206
 
164
207
  Piral is released using the MIT license. For more information see the [license file](./LICENSE).
package/convert.d.ts CHANGED
@@ -1,13 +1,16 @@
1
- import type { HtmlComponent } from 'piral-core';
2
- declare const convert: {
3
- <TProps extends import("piral-core").BaseComponentProps>(moduleName: string, dependency: () => Promise<void>, args: Record<string, any>): import("piral-core").ForeignComponent<TProps>;
4
- loader: Promise<{
5
- platform: import("./lib/internal/Platform/Platform").Platform;
6
- }>;
7
- };
1
+ import type { BlazorOptions } from './esm/types';
2
+ export interface HtmlComponent<TProps> {
3
+ component: {
4
+ mount(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
5
+ update?(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
6
+ unmount?(element: HTMLElement, locals: any): void;
7
+ };
8
+ type: 'html';
9
+ }
8
10
  export interface BlazorConverter {
9
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (moduleName: string, args?: Record<string, any>): HtmlComponent<any>;
10
12
  }
13
+ export declare function defineBlazorOptions(options: BlazorOptions): void;
11
14
  export declare const fromBlazor: BlazorConverter;
12
- export declare const defineBlazorReferences: (references: any) => void;
13
- export {};
15
+ export declare const defineBlazorReferences: (references: string[], meta?: PiletMetadata, satellites?: {}, prio?: number) => void;
16
+ export declare const releaseBlazorReferences: () => Promise<void>;
package/convert.js CHANGED
@@ -1,12 +1,17 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.defineBlazorReferences = exports.fromBlazor = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var dependencies_1 = require("./lib/dependencies");
6
- var convert = converter_1.createConverter();
7
- var loader = dependencies_1.createDependencyLoader(convert);
8
- exports.fromBlazor = function (moduleName, dependency, args) { return ({
9
- type: 'html',
10
- component: convert(moduleName, dependency, args)
11
- }); };
12
- exports.defineBlazorReferences = loader.defineBlazorReferences;
1
+ import { createConverter } from './esm/converter';
2
+ import { createDependencyLoader } from './esm/dependencies';
3
+ var convert = createConverter(true);
4
+ var loader = createDependencyLoader(convert);
5
+ var blazorOptions = undefined;
6
+ export function defineBlazorOptions(options) {
7
+ blazorOptions = options;
8
+ }
9
+ export var fromBlazor = function (moduleName, args) {
10
+ if (args === void 0) { args = {}; }
11
+ return ({
12
+ type: 'html',
13
+ component: convert(moduleName, loader.getDependency(), args, blazorOptions),
14
+ });
15
+ };
16
+ export var defineBlazorReferences = loader.defineBlazorReferences;
17
+ export var releaseBlazorReferences = loader.releaseBlazorReferences;
@@ -1,7 +1,11 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- export declare function createConverter(lazy?: boolean): {
3
- <TProps extends BaseComponentProps>(moduleName: string, dependency: () => Promise<void>, args: Record<string, any>): ForeignComponent<TProps>;
4
- loader: Promise<{
5
- platform: import("./internal/Platform/Platform").Platform;
6
- }>;
1
+ import type { BaseComponentProps, ForeignComponent } from 'piral-core';
2
+ import { BlazorDependencyLoader, BlazorLogLevel, BlazorOptions, BlazorRootConfig, WebAssemblyStartOptions } from './types';
3
+ export interface LanguageOptions {
4
+ current: string | undefined;
5
+ onChange(inform: (language: string) => void): void;
6
+ }
7
+ export declare function createConverter(lazy: boolean, opts?: WebAssemblyStartOptions, language?: LanguageOptions, logLevel?: BlazorLogLevel): {
8
+ <TProps extends BaseComponentProps>(moduleName: string, dependency: BlazorDependencyLoader, args: Record<string, any>, options?: BlazorOptions): ForeignComponent<TProps>;
9
+ loader: Promise<BlazorRootConfig>;
10
+ lazy: boolean;
7
11
  };
package/esm/converter.js CHANGED
@@ -1,55 +1,171 @@
1
- import { __assign } from "tslib";
2
- import { initialize, activate, deactivate, attachEvents } from './internal';
3
- export function createConverter(lazy) {
4
- if (lazy === void 0) { lazy = true; }
5
- var bootConfig = require('../infra.codegen');
6
- var boot = function () { return initialize(bootConfig); };
7
- var root = document.body.appendChild(document.createElement('div'));
8
- var loader = !lazy && boot();
9
- root.style.display = 'none';
10
- root.id = 'blazor-root';
11
- var convert = function (moduleName, dependency, args) {
12
- var id;
13
- var referenceId;
14
- var node;
15
- var dispose = function () { };
16
- var state;
17
- return {
18
- mount: function (el, data, ctx) {
19
- var props = __assign(__assign({}, args), data);
20
- el.setAttribute('data-blazor-pilet-root', 'true');
21
- (loader || (loader = boot()))
22
- .then(dependency)
23
- .then(function () { return activate(moduleName, props); })
24
- .then(function (refId) {
25
- if (state === 'fresh') {
26
- id = moduleName + "-" + refId;
27
- node = el.appendChild(root.querySelector("#" + id + " > div"));
28
- state = 'mounted';
29
- referenceId = refId;
1
+ import { __awaiter } from "tslib";
2
+ import { addGlobalEventListeners, attachEvents, removeGlobalEventListeners } from './events';
3
+ import { activate, deactivate, createBootLoader, reactivate, callNotifyLocationChanged, setLanguage, createElement, destroyElement, updateElement, setLogLevel, processEvent, } from './interop';
4
+ import bootConfig from '../infra.codegen';
5
+ const noop = () => { };
6
+ const mediaRules = [
7
+ { attribute: 'src', selector: 'img, embed, video > source, video > track, audio > source' },
8
+ { attribute: 'srcset', selector: 'picture > source' },
9
+ ];
10
+ function prefixMediaSources(component, prefix) {
11
+ const prefixAttributeValue = (el, attr) => el.setAttribute(attr, prefix + el.getAttribute(attr));
12
+ for (const { attribute, selector } of mediaRules) {
13
+ Array.from(component.querySelectorAll(selector))
14
+ .filter((el) => el.hasAttribute(attribute) && !el.getAttribute(attribute).match(/^https?:/))
15
+ .forEach((el) => prefixAttributeValue(el, attribute));
16
+ }
17
+ }
18
+ function project(component, destination, options) {
19
+ if ((options === null || options === void 0 ? void 0 : options.resourcePathRoot) && !bootConfig.noMutation) {
20
+ prefixMediaSources(component, options.resourcePathRoot);
21
+ }
22
+ destination.appendChild(component);
23
+ }
24
+ function makeUrl(href) {
25
+ const origin = document.location.origin;
26
+ if (!href.startsWith(origin)) {
27
+ return `${origin}${href}`;
28
+ }
29
+ return href;
30
+ }
31
+ export function createConverter(lazy, opts, language, logLevel) {
32
+ const bootLoader = createBootLoader(bootConfig.url, bootConfig.satellites);
33
+ const boot = (opts) => bootLoader(opts).then((res) => __awaiter(this, void 0, void 0, function* () {
34
+ const [_, capabilities] = res;
35
+ if (capabilities.includes('logging')) {
36
+ if (typeof logLevel === 'number') {
37
+ yield setLogLevel(logLevel);
38
+ }
39
+ }
40
+ if (language && capabilities.includes('language')) {
41
+ if (typeof language.current === 'string') {
42
+ yield setLanguage(language.current);
43
+ }
44
+ if (capabilities.includes('events')) {
45
+ const eventDispatcher = document.body.dispatchEvent;
46
+ // listen to all events for forwarding them
47
+ document.body.dispatchEvent = function (ev) {
48
+ if (ev.type.startsWith('piral-')) {
49
+ const type = ev.type.replace('piral-', '');
50
+ const args = ev.detail.arg;
51
+ processEvent(type, args);
52
+ }
53
+ return eventDispatcher.call(this, ev);
54
+ };
55
+ }
56
+ if (typeof language.onChange === 'function') {
57
+ language.onChange(setLanguage);
58
+ }
59
+ }
60
+ window.dispatchEvent(new CustomEvent('loaded-blazor-core'));
61
+ return res;
62
+ }));
63
+ let loader = !lazy && boot(opts);
64
+ let listener = undefined;
65
+ const enqueueChange = (locals, update) => {
66
+ if (typeof update !== 'function') {
67
+ // nothing to do in this case
68
+ }
69
+ else if (locals.state === 'mounted') {
70
+ loader.then(update);
71
+ }
72
+ else {
73
+ locals.next = update;
74
+ }
75
+ };
76
+ const convert = (moduleName, dependency, args, options) => ({
77
+ mount(el, data, ctx, locals) {
78
+ const props = Object.assign(Object.assign({}, args), data);
79
+ const { piral } = data;
80
+ const nav = ctx.navigation;
81
+ el.setAttribute('data-blazor-pilet-root', 'true');
82
+ addGlobalEventListeners(el);
83
+ if (listener === undefined) {
84
+ listener = nav.listen(({ location, action }) => {
85
+ // POP is already handled by .NET
86
+ if (action !== 'POP') {
87
+ const url = makeUrl(location.href);
88
+ callNotifyLocationChanged(url, action === 'REPLACE', location.state);
30
89
  }
31
- })
32
- .catch(function (err) { return console.error(err); });
33
- dispose = attachEvents(el, function (ev) { return data.piral.renderHtmlExtension(ev.detail.target, ev.detail.props); }, function (ev) {
34
- return ev.detail.replace
35
- ? ctx.router.history.replace(ev.detail.to, ev.detail.store)
36
- : ctx.router.history.push(ev.detail.to, ev.detail.state);
37
90
  });
38
- state = 'fresh';
39
- },
40
- unmount: function (el) {
41
- el.removeAttribute('data-blazor-pilet-root');
42
- dispose();
43
- if (state === 'mounted') {
44
- root.querySelector("#" + id).appendChild(node);
45
- deactivate(moduleName, referenceId);
91
+ }
92
+ locals.state = 'fresh';
93
+ locals.next = noop;
94
+ locals.dispose = attachEvents(el, (ev) => {
95
+ ev.stopPropagation();
96
+ const { target, props } = ev.detail;
97
+ piral.renderHtmlExtension(target, props);
98
+ }, (ev) => {
99
+ ev.stopPropagation();
100
+ const { to, state, replace } = ev.detail;
101
+ replace ? nav.replace(to, state) : nav.push(to, state);
102
+ }, (ev) => {
103
+ ev.stopPropagation();
104
+ const { type, args } = ev.detail;
105
+ piral.emit(type, args);
106
+ });
107
+ function mountClassic(config) {
108
+ return activate(moduleName, props).then((refId) => {
109
+ const [root] = config;
110
+ const node = root.querySelector(`#${refId} > div`);
111
+ locals.unmount = () => {
112
+ var _a;
113
+ (_a = root.querySelector(`#${refId}`)) === null || _a === void 0 ? void 0 : _a.appendChild(node);
114
+ deactivate(moduleName, refId);
115
+ el.innerHTML = '';
116
+ };
117
+ locals.update = (props) => {
118
+ reactivate(moduleName, refId, props);
119
+ };
120
+ project(node, el, options);
121
+ });
122
+ }
123
+ function mountModern(_) {
124
+ return createElement(moduleName, props).then((refId) => {
125
+ const child = document.createElement('piral-blazor-component');
126
+ child.setAttribute('rid', refId);
127
+ el.appendChild(child);
128
+ locals.unmount = () => {
129
+ destroyElement(refId);
130
+ child.remove();
131
+ el.innerHTML = '';
132
+ };
133
+ locals.update = (props) => {
134
+ updateElement(refId, props);
135
+ };
136
+ });
137
+ }
138
+ (loader || (convert.loader = loader = boot(opts)))
139
+ .then((config) => dependency(config).then(() => {
140
+ if (locals.state === 'fresh') {
141
+ const [_, capabilities, applyChanges] = config;
142
+ const fn = capabilities.includes('custom-element') ? mountModern : mountClassic;
143
+ applyChanges(piral);
144
+ return fn(config).then(() => {
145
+ locals.state = 'mounted';
146
+ locals.next(config);
147
+ locals.next = noop;
148
+ });
46
149
  }
47
- el.innerHTML = '';
48
- state = 'removed';
49
- },
50
- };
51
- };
150
+ }))
151
+ .catch((err) => console.error(err));
152
+ },
153
+ update(el, data, ctx, locals) {
154
+ enqueueChange(locals, () => {
155
+ var _a;
156
+ (_a = locals.update) === null || _a === void 0 ? void 0 : _a.call(locals, Object.assign(Object.assign({}, args), data));
157
+ });
158
+ },
159
+ unmount(el, locals) {
160
+ removeGlobalEventListeners(el);
161
+ el.removeAttribute('data-blazor-pilet-root');
162
+ locals.dispose();
163
+ enqueueChange(locals, locals.unmount);
164
+ locals.state = 'removed';
165
+ },
166
+ });
52
167
  convert.loader = loader;
168
+ convert.lazy = lazy;
53
169
  return convert;
54
170
  }
55
171
  //# sourceMappingURL=converter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,UAAU,eAAe,CAAC,IAAW;IAAX,qBAAA,EAAA,WAAW;IACzC,IAAM,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/C,IAAM,IAAI,GAAG,cAAM,OAAA,UAAU,CAAC,UAAU,CAAC,EAAtB,CAAsB,CAAC;IAC1C,IAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,IAAI,MAAM,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;IAE7B,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,GAAG,aAAa,CAAC;IAExB,IAAM,OAAO,GAAG,UACd,UAAkB,EAClB,UAA+B,EAC/B,IAAyB;QAEzB,IAAI,EAAU,CAAC;QACf,IAAI,WAAmB,CAAC;QACxB,IAAI,IAAiB,CAAC;QACtB,IAAI,OAAO,GAAG,cAAO,CAAC,CAAC;QACvB,IAAI,KAAsC,CAAC;QAE3C,OAAO;YACL,KAAK,YAAC,EAAE,EAAE,IAAI,EAAE,GAAG;gBACjB,IAAM,KAAK,yBAAQ,IAAI,GAAK,IAAI,CAAE,CAAC;gBACnC,EAAE,CAAC,YAAY,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;gBAElD,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O,OAAO,CAAC;AACjB,CAAC"}
package/esm/create.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
- import type { PiletBlazorApi } from './types';
2
+ import type { BlazorLogLevel, PiletBlazorApi, WebAssemblyStartOptions } from './types';
3
3
  /**
4
4
  * Available configuration options for the Blazor plugin.
5
5
  */
@@ -9,6 +9,26 @@ export interface BlazorConfig {
9
9
  * @default true
10
10
  */
11
11
  lazy?: boolean;
12
+ /**
13
+ * Determines the used log level, if any. Otherwise, will use
14
+ * the default log level (info).
15
+ */
16
+ logLevel?: BlazorLogLevel;
17
+ /**
18
+ * Determines the initial language to use, if any.
19
+ * Otherwise, falls back to Blazor's default language.
20
+ */
21
+ initialLanguage?: string;
22
+ /**
23
+ * Installs a function to handle language change. By default,
24
+ * this will hook on to the `select-language` event from Piral.
25
+ * @param inform The callback to use for passing in a new locale.
26
+ */
27
+ onLanguageChange?: ((inform: (language: string) => void) => void) | false;
28
+ /**
29
+ * Determines the start options to use for booting Blazor.
30
+ */
31
+ options?: WebAssemblyStartOptions;
12
32
  }
13
33
  /**
14
34
  * Creates new Pilet API extensions for integration of Blazor.
package/esm/create.js CHANGED
@@ -1,27 +1,41 @@
1
1
  import { createConverter } from './converter';
2
2
  import { createDependencyLoader } from './dependencies';
3
+ function createDefaultHandler(context) {
4
+ return (inform) => {
5
+ context.on('select-language', (ev) => {
6
+ inform(ev.currentLanguage);
7
+ });
8
+ };
9
+ }
3
10
  /**
4
11
  * Creates new Pilet API extensions for integration of Blazor.
5
12
  */
6
- export function createBlazorApi(config) {
7
- if (config === void 0) { config = {}; }
8
- var lazy = config.lazy;
9
- return function (context) {
10
- var convert = createConverter(lazy);
11
- context.converters.blazor = function (_a) {
12
- var moduleName = _a.moduleName, args = _a.args, dependency = _a.dependency;
13
- return convert(moduleName, dependency, args);
14
- };
15
- return function () {
16
- var loader = createDependencyLoader(convert, lazy);
13
+ export function createBlazorApi(config = {}) {
14
+ return (context) => {
15
+ const { lazy = true, initialLanguage, onLanguageChange = createDefaultHandler(context), logLevel } = config;
16
+ const convert = createConverter(lazy, config.options, {
17
+ current: initialLanguage,
18
+ onChange: onLanguageChange || (() => { }),
19
+ }, logLevel);
20
+ context.converters.blazor = ({ moduleName, args, dependency, options }) => convert(moduleName, dependency, args, options);
21
+ return (_, meta) => {
22
+ const loader = createDependencyLoader(convert);
23
+ let options;
17
24
  return {
18
- defineBlazorReferences: loader.defineBlazorReferences,
19
- fromBlazor: function (moduleName, args) {
25
+ defineBlazorReferences(references, satellites, prio) {
26
+ return loader.defineBlazorReferences(references, meta, satellites, prio);
27
+ },
28
+ defineBlazorOptions(blazorOptions) {
29
+ options = blazorOptions;
30
+ },
31
+ releaseBlazorReferences: loader.releaseBlazorReferences,
32
+ fromBlazor(moduleName, args) {
20
33
  return {
21
34
  type: 'blazor',
22
35
  dependency: loader.getDependency(),
23
- moduleName: moduleName,
24
- args: args,
36
+ moduleName,
37
+ args,
38
+ options,
25
39
  };
26
40
  },
27
41
  };
package/esm/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAcxD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAyB;IAAzB,uBAAA,EAAA,WAAyB;IAC/C,IAAA,IAAI,GAAK,MAAM,KAAX,CAAY;IAExB,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACtC,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,UAAC,EAAgC;gBAA9B,UAAU,gBAAA,EAAE,IAAI,UAAA,EAAE,UAAU,gBAAA;YAAO,OAAA,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC;QAArC,CAAqC,CAAC;QAExG,OAA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AAC,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,CACxE,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAEjD,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;YACjB,MAAM,MAAM,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;YAC/C,IAAI,OAAsB,CAAC;YAE3B,OAAO;gBACL,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI;oBACjD,OAAO,MAAM,CAAC,sBAAsB,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;gBAC3E,CAAC;gBACD,mBAAmB,CAAC,aAA4B;oBAC9C,OAAO,GAAG,aAAa,CAAC;gBAC1B,CAAC;gBACD,uBAAuB,EAAE,MAAM,CAAC,uBAAuB;gBACvD,UAAU,CAAC,UAAU,EAAE,IAAI;oBACzB,OAAO;wBACL,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE;wBAClC,UAAU;wBACV,IAAI;wBACJ,OAAO;qBACR,CAAC;gBACJ,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,5 +1,8 @@
1
+ import type { PiletMetadata } from 'piral-core';
1
2
  import type { createConverter } from './converter';
2
- export declare function createDependencyLoader(convert: ReturnType<typeof createConverter>, lazy?: boolean): {
3
- getDependency(): () => Promise<any>;
4
- defineBlazorReferences(references: any): void;
3
+ import type { BlazorDependencyLoader } from './types';
4
+ export declare function createDependencyLoader(convert: ReturnType<typeof createConverter>): {
5
+ getDependency(): BlazorDependencyLoader;
6
+ defineBlazorReferences(references: Array<string>, meta?: Partial<PiletMetadata>, satellites?: {}, prio?: number): void;
7
+ releaseBlazorReferences(): Promise<void>;
5
8
  };