piral-core 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 (672) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -4
  3. package/app.codegen +36 -0
  4. package/app.codegen.d.ts +29 -0
  5. package/dist/codegen.js +5308 -0
  6. package/esm/Piral.d.ts +4 -4
  7. package/esm/Piral.js +8 -11
  8. package/esm/Piral.js.map +1 -1
  9. package/esm/PiralContext.d.ts +21 -0
  10. package/esm/PiralContext.js +34 -0
  11. package/esm/PiralContext.js.map +1 -0
  12. package/esm/RootListener.d.ts +2 -0
  13. package/esm/RootListener.js +23 -0
  14. package/esm/RootListener.js.map +1 -0
  15. package/esm/actions/app.d.ts +7 -4
  16. package/esm/actions/app.js +24 -14
  17. package/esm/actions/app.js.map +1 -1
  18. package/esm/actions/components.js +5 -6
  19. package/esm/actions/components.js.map +1 -1
  20. package/esm/actions/data.js +16 -17
  21. package/esm/actions/data.js.map +1 -1
  22. package/esm/actions/define.js +2 -3
  23. package/esm/actions/define.js.map +1 -1
  24. package/esm/actions/portal.d.ts +2 -0
  25. package/esm/actions/portal.js +9 -4
  26. package/esm/actions/portal.js.map +1 -1
  27. package/esm/actions/state.js +7 -4
  28. package/esm/actions/state.js.map +1 -1
  29. package/esm/components/ErrorBoundary.d.ts +14 -31
  30. package/esm/components/ErrorBoundary.js +22 -28
  31. package/esm/components/ErrorBoundary.js.map +1 -1
  32. package/esm/components/ExtensionSlot.d.ts +1 -0
  33. package/esm/components/ExtensionSlot.js +34 -11
  34. package/esm/components/ExtensionSlot.js.map +1 -1
  35. package/esm/components/ForeignComponentContainer.d.ts +19 -0
  36. package/esm/components/ForeignComponentContainer.js +46 -0
  37. package/esm/components/ForeignComponentContainer.js.map +1 -0
  38. package/esm/components/Mediator.js +15 -12
  39. package/esm/components/Mediator.js.map +1 -1
  40. package/esm/components/PiralGlobals.d.ts +6 -0
  41. package/esm/components/PiralGlobals.js +13 -0
  42. package/esm/components/PiralGlobals.js.map +1 -0
  43. package/esm/components/PiralRoutes.d.ts +5 -0
  44. package/esm/components/PiralRoutes.js +6 -11
  45. package/esm/components/PiralRoutes.js.map +1 -1
  46. package/esm/components/PiralSuspense.d.ts +5 -0
  47. package/esm/components/PiralSuspense.js +8 -0
  48. package/esm/components/PiralSuspense.js.map +1 -0
  49. package/esm/components/PiralView.d.ts +10 -1
  50. package/esm/components/PiralView.js +12 -25
  51. package/esm/components/PiralView.js.map +1 -1
  52. package/esm/components/PortalRenderer.d.ts +5 -0
  53. package/esm/components/PortalRenderer.js +7 -0
  54. package/esm/components/PortalRenderer.js.map +1 -0
  55. package/esm/components/ResponsiveLayout.d.ts +9 -1
  56. package/esm/components/ResponsiveLayout.js +5 -13
  57. package/esm/components/ResponsiveLayout.js.map +1 -1
  58. package/esm/components/SwitchErrorInfo.js +12 -10
  59. package/esm/components/SwitchErrorInfo.js.map +1 -1
  60. package/esm/components/components.d.ts +18 -6
  61. package/esm/components/components.js +21 -9
  62. package/esm/components/components.js.map +1 -1
  63. package/esm/components/index.d.ts +4 -10
  64. package/esm/components/index.js +4 -10
  65. package/esm/components/index.js.map +1 -1
  66. package/esm/components/wrapComponent.d.ts +7 -0
  67. package/esm/components/wrapComponent.js +42 -0
  68. package/esm/components/wrapComponent.js.map +1 -0
  69. package/esm/createInstance.d.ts +2 -2
  70. package/esm/createInstance.js +34 -30
  71. package/esm/createInstance.js.map +1 -1
  72. package/esm/defaults/DefaultErrorInfo.js +10 -0
  73. package/esm/defaults/DefaultErrorInfo.js.map +1 -0
  74. package/esm/{components → defaults}/DefaultLayout.js +1 -4
  75. package/esm/defaults/DefaultLayout.js.map +1 -0
  76. package/esm/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +2 -2
  77. package/esm/defaults/DefaultLoadingIndicator.js.map +1 -0
  78. package/esm/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
  79. package/esm/defaults/DefaultRouteSwitch_v5.js +11 -0
  80. package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
  81. package/esm/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
  82. package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
  83. package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
  84. package/esm/defaults/DefaultRouter_v5.d.ts +3 -0
  85. package/esm/defaults/DefaultRouter_v5.js +7 -0
  86. package/esm/defaults/DefaultRouter_v5.js.map +1 -0
  87. package/esm/defaults/DefaultRouter_v6.d.ts +3 -0
  88. package/esm/defaults/DefaultRouter_v6.js +7 -0
  89. package/esm/defaults/DefaultRouter_v6.js.map +1 -0
  90. package/esm/defaults/navigator_none.d.ts +5 -0
  91. package/esm/defaults/navigator_none.js +30 -0
  92. package/esm/defaults/navigator_none.js.map +1 -0
  93. package/esm/defaults/navigator_v5.d.ts +6 -0
  94. package/esm/defaults/navigator_v5.js +81 -0
  95. package/esm/defaults/navigator_v5.js.map +1 -0
  96. package/esm/defaults/navigator_v6.d.ts +6 -0
  97. package/esm/defaults/navigator_v6.js +77 -0
  98. package/esm/defaults/navigator_v6.js.map +1 -0
  99. package/esm/helpers.d.ts +12 -26
  100. package/esm/helpers.js +14 -72
  101. package/esm/helpers.js.map +1 -1
  102. package/esm/hooks/action.js +2 -3
  103. package/esm/hooks/action.js.map +1 -1
  104. package/esm/hooks/actions.js +1 -1
  105. package/esm/hooks/actions.js.map +1 -1
  106. package/esm/hooks/globalState.d.ts +7 -0
  107. package/esm/hooks/globalState.js +10 -8
  108. package/esm/hooks/globalState.js.map +1 -1
  109. package/esm/hooks/index.d.ts +2 -5
  110. package/esm/hooks/index.js +2 -5
  111. package/esm/hooks/index.js.map +1 -1
  112. package/esm/hooks/media.js +8 -7
  113. package/esm/hooks/media.js.map +1 -1
  114. package/esm/hooks/piletApi.d.ts +7 -0
  115. package/esm/hooks/piletApi.js +14 -0
  116. package/esm/hooks/piletApi.js.map +1 -0
  117. package/esm/hooks/routes.d.ts +2 -0
  118. package/esm/hooks/routes.js +11 -0
  119. package/esm/hooks/routes.js.map +1 -0
  120. package/esm/hooks/setter.js +3 -2
  121. package/esm/hooks/setter.js.map +1 -1
  122. package/esm/hooks/sharedData.js +2 -2
  123. package/esm/hooks/sharedData.js.map +1 -1
  124. package/esm/index.d.ts +3 -1
  125. package/esm/index.js +3 -1
  126. package/esm/index.js.map +1 -1
  127. package/esm/modules/api.d.ts +2 -5
  128. package/esm/modules/api.js +9 -68
  129. package/esm/modules/api.js.map +1 -1
  130. package/esm/modules/core.d.ts +3 -0
  131. package/esm/modules/core.js +50 -0
  132. package/esm/modules/core.js.map +1 -0
  133. package/esm/modules/dependencies.d.ts +5 -6
  134. package/esm/modules/dependencies.js +9 -24
  135. package/esm/modules/dependencies.js.map +1 -1
  136. package/esm/modules/element.d.ts +5 -0
  137. package/esm/modules/element.js +169 -0
  138. package/esm/modules/element.js.map +1 -0
  139. package/esm/modules/index.d.ts +1 -0
  140. package/esm/modules/index.js +1 -0
  141. package/esm/modules/index.js.map +1 -1
  142. package/esm/setters/SetComponent.js +11 -0
  143. package/esm/setters/SetComponent.js.map +1 -0
  144. package/esm/setters/SetError.js +11 -0
  145. package/esm/setters/SetError.js.map +1 -0
  146. package/esm/setters/SetErrors.js +9 -0
  147. package/esm/setters/SetErrors.js.map +1 -0
  148. package/esm/setters/SetLayout.js +9 -0
  149. package/esm/setters/SetLayout.js.map +1 -0
  150. package/esm/setters/SetProvider.js +11 -0
  151. package/esm/setters/SetProvider.js.map +1 -0
  152. package/esm/setters/SetRedirect.js +12 -0
  153. package/esm/setters/SetRedirect.js.map +1 -0
  154. package/{lib/components → esm/setters}/SetRoute.d.ts +6 -2
  155. package/esm/setters/SetRoute.js +11 -0
  156. package/esm/setters/SetRoute.js.map +1 -0
  157. package/esm/setters/index.d.ts +7 -0
  158. package/esm/setters/index.js +8 -0
  159. package/esm/setters/index.js.map +1 -0
  160. package/esm/state/createActions.d.ts +2 -2
  161. package/esm/state/createActions.js +8 -12
  162. package/esm/state/createActions.js.map +1 -1
  163. package/esm/state/createGlobalState.d.ts +1 -2
  164. package/esm/state/createGlobalState.js +9 -34
  165. package/esm/state/createGlobalState.js.map +1 -1
  166. package/esm/state/stateContext.js +1 -1
  167. package/esm/state/stateContext.js.map +1 -1
  168. package/esm/state/withApi.d.ts +1 -1
  169. package/esm/state/withApi.js +19 -104
  170. package/esm/state/withApi.js.map +1 -1
  171. package/esm/tools/codegen.d.ts +21 -0
  172. package/esm/tools/codegen.js +145 -0
  173. package/esm/tools/codegen.js.map +1 -0
  174. package/esm/tools/debugger.d.ts +4 -0
  175. package/esm/tools/debugger.js +54 -0
  176. package/esm/tools/debugger.js.map +1 -0
  177. package/esm/tools/emulator.d.ts +3 -0
  178. package/esm/tools/emulator.js +11 -0
  179. package/esm/tools/emulator.js.map +1 -0
  180. package/esm/types/api.d.ts +37 -10
  181. package/esm/types/common.d.ts +11 -11
  182. package/esm/types/components.d.ts +74 -8
  183. package/esm/types/config.d.ts +24 -17
  184. package/esm/types/data.d.ts +2 -2
  185. package/esm/types/extension.d.ts +31 -4
  186. package/esm/types/index.d.ts +1 -0
  187. package/esm/types/index.js +1 -0
  188. package/esm/types/index.js.map +1 -1
  189. package/esm/types/instance.d.ts +26 -4
  190. package/esm/types/layout.d.ts +3 -3
  191. package/esm/types/navigation.d.ts +94 -0
  192. package/esm/types/navigation.js +2 -0
  193. package/esm/types/navigation.js.map +1 -0
  194. package/esm/types/plugin.d.ts +1 -14
  195. package/esm/types/state.d.ts +66 -27
  196. package/esm/types/utils.d.ts +1 -1
  197. package/esm/utils/compare.d.ts +1 -1
  198. package/esm/utils/compare.js +24 -7
  199. package/esm/utils/compare.js.map +1 -1
  200. package/esm/utils/data.js +6 -7
  201. package/esm/utils/data.js.map +1 -1
  202. package/esm/utils/extension.d.ts +16 -0
  203. package/esm/utils/extension.js +37 -0
  204. package/esm/utils/extension.js.map +1 -0
  205. package/esm/utils/foreign.d.ts +7 -2
  206. package/esm/utils/foreign.js +20 -9
  207. package/esm/utils/foreign.js.map +1 -1
  208. package/esm/utils/guid.js +3 -3
  209. package/esm/utils/guid.js.map +1 -1
  210. package/esm/utils/helpers.d.ts +11 -8
  211. package/esm/utils/helpers.js +29 -18
  212. package/esm/utils/helpers.js.map +1 -1
  213. package/esm/utils/index.d.ts +3 -1
  214. package/esm/utils/index.js +3 -1
  215. package/esm/utils/index.js.map +1 -1
  216. package/esm/utils/media.js +8 -8
  217. package/esm/utils/media.js.map +1 -1
  218. package/esm/utils/state.d.ts +57 -0
  219. package/esm/utils/state.js +83 -0
  220. package/esm/utils/state.js.map +1 -0
  221. package/esm/utils/storage.js +13 -14
  222. package/esm/utils/storage.js.map +1 -1
  223. package/lib/Piral.d.ts +4 -4
  224. package/lib/Piral.js +11 -13
  225. package/lib/Piral.js.map +1 -1
  226. package/lib/PiralContext.d.ts +21 -0
  227. package/lib/PiralContext.js +38 -0
  228. package/lib/PiralContext.js.map +1 -0
  229. package/lib/RootListener.d.ts +2 -0
  230. package/lib/RootListener.js +27 -0
  231. package/lib/RootListener.js.map +1 -0
  232. package/lib/actions/app.d.ts +7 -4
  233. package/lib/actions/app.js +27 -16
  234. package/lib/actions/app.js.map +1 -1
  235. package/lib/actions/components.js +5 -6
  236. package/lib/actions/components.js.map +1 -1
  237. package/lib/actions/data.js +17 -18
  238. package/lib/actions/data.js.map +1 -1
  239. package/lib/actions/define.js +2 -3
  240. package/lib/actions/define.js.map +1 -1
  241. package/lib/actions/index.js +1 -1
  242. package/lib/actions/portal.d.ts +2 -0
  243. package/lib/actions/portal.js +12 -5
  244. package/lib/actions/portal.js.map +1 -1
  245. package/lib/actions/state.js +7 -4
  246. package/lib/actions/state.js.map +1 -1
  247. package/lib/components/ErrorBoundary.d.ts +14 -31
  248. package/lib/components/ErrorBoundary.js +23 -28
  249. package/lib/components/ErrorBoundary.js.map +1 -1
  250. package/lib/components/ExtensionSlot.d.ts +1 -0
  251. package/lib/components/ExtensionSlot.js +37 -14
  252. package/lib/components/ExtensionSlot.js.map +1 -1
  253. package/lib/components/ForeignComponentContainer.d.ts +19 -0
  254. package/lib/components/ForeignComponentContainer.js +50 -0
  255. package/lib/components/ForeignComponentContainer.js.map +1 -0
  256. package/lib/components/Mediator.js +18 -14
  257. package/lib/components/Mediator.js.map +1 -1
  258. package/lib/components/PiralGlobals.d.ts +6 -0
  259. package/lib/components/PiralGlobals.js +17 -0
  260. package/lib/components/PiralGlobals.js.map +1 -0
  261. package/lib/components/PiralRoutes.d.ts +5 -0
  262. package/lib/components/PiralRoutes.js +8 -12
  263. package/lib/components/PiralRoutes.js.map +1 -1
  264. package/lib/components/PiralSuspense.d.ts +5 -0
  265. package/lib/components/PiralSuspense.js +12 -0
  266. package/lib/components/PiralSuspense.js.map +1 -0
  267. package/lib/components/PiralView.d.ts +10 -1
  268. package/lib/components/PiralView.js +15 -27
  269. package/lib/components/PiralView.js.map +1 -1
  270. package/lib/components/PortalRenderer.d.ts +5 -0
  271. package/lib/components/PortalRenderer.js +11 -0
  272. package/lib/components/PortalRenderer.js.map +1 -0
  273. package/lib/components/ResponsiveLayout.d.ts +9 -1
  274. package/lib/components/ResponsiveLayout.js +7 -14
  275. package/lib/components/ResponsiveLayout.js.map +1 -1
  276. package/lib/components/SwitchErrorInfo.js +15 -12
  277. package/lib/components/SwitchErrorInfo.js.map +1 -1
  278. package/lib/components/components.d.ts +18 -6
  279. package/lib/components/components.js +24 -12
  280. package/lib/components/components.js.map +1 -1
  281. package/lib/components/index.d.ts +4 -10
  282. package/lib/components/index.js +5 -11
  283. package/lib/components/index.js.map +1 -1
  284. package/lib/components/wrapComponent.d.ts +7 -0
  285. package/lib/components/wrapComponent.js +46 -0
  286. package/lib/components/wrapComponent.js.map +1 -0
  287. package/lib/createInstance.d.ts +2 -2
  288. package/lib/createInstance.js +40 -36
  289. package/lib/createInstance.js.map +1 -1
  290. package/lib/defaults/DefaultErrorInfo.js +14 -0
  291. package/lib/defaults/DefaultErrorInfo.js.map +1 -0
  292. package/lib/{components → defaults}/DefaultLayout.js +3 -5
  293. package/lib/defaults/DefaultLayout.js.map +1 -0
  294. package/lib/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +4 -3
  295. package/lib/defaults/DefaultLoadingIndicator.js.map +1 -0
  296. package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
  297. package/lib/defaults/DefaultRouteSwitch_v5.js +15 -0
  298. package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
  299. package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
  300. package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
  301. package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
  302. package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
  303. package/lib/defaults/DefaultRouter_v5.js +11 -0
  304. package/lib/defaults/DefaultRouter_v5.js.map +1 -0
  305. package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
  306. package/lib/defaults/DefaultRouter_v6.js +11 -0
  307. package/lib/defaults/DefaultRouter_v6.js.map +1 -0
  308. package/lib/defaults/navigator_none.d.ts +5 -0
  309. package/lib/defaults/navigator_none.js +37 -0
  310. package/lib/defaults/navigator_none.js.map +1 -0
  311. package/lib/defaults/navigator_v5.d.ts +6 -0
  312. package/lib/defaults/navigator_v5.js +88 -0
  313. package/lib/defaults/navigator_v5.js.map +1 -0
  314. package/lib/defaults/navigator_v6.d.ts +6 -0
  315. package/lib/defaults/navigator_v6.js +84 -0
  316. package/lib/defaults/navigator_v6.js.map +1 -0
  317. package/lib/helpers.d.ts +12 -26
  318. package/lib/helpers.js +15 -75
  319. package/lib/helpers.js.map +1 -1
  320. package/lib/hooks/action.js +2 -3
  321. package/lib/hooks/action.js.map +1 -1
  322. package/lib/hooks/actions.js +4 -4
  323. package/lib/hooks/actions.js.map +1 -1
  324. package/lib/hooks/globalState.d.ts +7 -0
  325. package/lib/hooks/globalState.js +14 -11
  326. package/lib/hooks/globalState.js.map +1 -1
  327. package/lib/hooks/index.d.ts +2 -5
  328. package/lib/hooks/index.js +3 -6
  329. package/lib/hooks/index.js.map +1 -1
  330. package/lib/hooks/media.js +10 -9
  331. package/lib/hooks/media.js.map +1 -1
  332. package/lib/hooks/piletApi.d.ts +7 -0
  333. package/lib/hooks/piletApi.js +18 -0
  334. package/lib/hooks/piletApi.js.map +1 -0
  335. package/lib/hooks/routes.d.ts +2 -0
  336. package/lib/hooks/routes.js +15 -0
  337. package/lib/hooks/routes.js.map +1 -0
  338. package/lib/hooks/setter.js +4 -3
  339. package/lib/hooks/setter.js.map +1 -1
  340. package/lib/hooks/sharedData.js +3 -3
  341. package/lib/hooks/sharedData.js.map +1 -1
  342. package/lib/index.d.ts +3 -1
  343. package/lib/index.js +4 -2
  344. package/lib/index.js.map +1 -1
  345. package/lib/modules/api.d.ts +2 -5
  346. package/lib/modules/api.js +12 -74
  347. package/lib/modules/api.js.map +1 -1
  348. package/lib/modules/core.d.ts +3 -0
  349. package/lib/modules/core.js +54 -0
  350. package/lib/modules/core.js.map +1 -0
  351. package/lib/modules/dependencies.d.ts +5 -6
  352. package/lib/modules/dependencies.js +12 -27
  353. package/lib/modules/dependencies.js.map +1 -1
  354. package/lib/modules/element.d.ts +5 -0
  355. package/lib/modules/element.js +173 -0
  356. package/lib/modules/element.js.map +1 -0
  357. package/lib/modules/index.d.ts +1 -0
  358. package/lib/modules/index.js +2 -1
  359. package/lib/modules/index.js.map +1 -1
  360. package/lib/setters/SetComponent.js +15 -0
  361. package/lib/setters/SetComponent.js.map +1 -0
  362. package/lib/setters/SetError.js +15 -0
  363. package/lib/setters/SetError.js.map +1 -0
  364. package/lib/setters/SetErrors.js +13 -0
  365. package/lib/setters/SetErrors.js.map +1 -0
  366. package/lib/setters/SetLayout.js +13 -0
  367. package/lib/setters/SetLayout.js.map +1 -0
  368. package/lib/{components → setters}/SetProvider.js +4 -5
  369. package/lib/setters/SetProvider.js.map +1 -0
  370. package/lib/setters/SetRedirect.js +16 -0
  371. package/lib/setters/SetRedirect.js.map +1 -0
  372. package/{esm/components → lib/setters}/SetRoute.d.ts +6 -2
  373. package/lib/setters/SetRoute.js +15 -0
  374. package/lib/setters/SetRoute.js.map +1 -0
  375. package/lib/setters/index.d.ts +7 -0
  376. package/lib/setters/index.js +11 -0
  377. package/lib/setters/index.js.map +1 -0
  378. package/lib/state/createActions.d.ts +2 -2
  379. package/lib/state/createActions.js +9 -13
  380. package/lib/state/createActions.js.map +1 -1
  381. package/lib/state/createGlobalState.d.ts +1 -2
  382. package/lib/state/createGlobalState.js +9 -34
  383. package/lib/state/createGlobalState.js.map +1 -1
  384. package/lib/state/index.js +1 -1
  385. package/lib/state/stateContext.js +1 -1
  386. package/lib/state/stateContext.js.map +1 -1
  387. package/lib/state/withApi.d.ts +1 -1
  388. package/lib/state/withApi.js +20 -105
  389. package/lib/state/withApi.js.map +1 -1
  390. package/lib/tools/codegen.d.ts +21 -0
  391. package/lib/tools/codegen.js +152 -0
  392. package/lib/tools/codegen.js.map +1 -0
  393. package/lib/tools/debugger.d.ts +4 -0
  394. package/lib/tools/debugger.js +58 -0
  395. package/lib/tools/debugger.js.map +1 -0
  396. package/lib/tools/emulator.d.ts +3 -0
  397. package/lib/tools/emulator.js +15 -0
  398. package/lib/tools/emulator.js.map +1 -0
  399. package/lib/types/api.d.ts +37 -10
  400. package/lib/types/common.d.ts +11 -11
  401. package/lib/types/components.d.ts +74 -8
  402. package/lib/types/config.d.ts +24 -17
  403. package/lib/types/data.d.ts +2 -2
  404. package/lib/types/extension.d.ts +31 -4
  405. package/lib/types/index.d.ts +1 -0
  406. package/lib/types/index.js +2 -1
  407. package/lib/types/index.js.map +1 -1
  408. package/lib/types/instance.d.ts +26 -4
  409. package/lib/types/layout.d.ts +3 -3
  410. package/lib/types/navigation.d.ts +94 -0
  411. package/lib/types/navigation.js +3 -0
  412. package/lib/types/navigation.js.map +1 -0
  413. package/lib/types/plugin.d.ts +1 -14
  414. package/lib/types/state.d.ts +66 -27
  415. package/lib/types/utils.d.ts +1 -1
  416. package/lib/utils/compare.d.ts +1 -1
  417. package/lib/utils/compare.js +26 -9
  418. package/lib/utils/compare.js.map +1 -1
  419. package/lib/utils/data.js +6 -7
  420. package/lib/utils/data.js.map +1 -1
  421. package/lib/utils/extension.d.ts +16 -0
  422. package/lib/utils/extension.js +42 -0
  423. package/lib/utils/extension.js.map +1 -0
  424. package/lib/utils/foreign.d.ts +7 -2
  425. package/lib/utils/foreign.js +25 -12
  426. package/lib/utils/foreign.js.map +1 -1
  427. package/lib/utils/guid.js +3 -3
  428. package/lib/utils/guid.js.map +1 -1
  429. package/lib/utils/helpers.d.ts +11 -8
  430. package/lib/utils/helpers.js +31 -18
  431. package/lib/utils/helpers.js.map +1 -1
  432. package/lib/utils/index.d.ts +3 -1
  433. package/lib/utils/index.js +7 -2
  434. package/lib/utils/index.js.map +1 -1
  435. package/lib/utils/media.js +7 -7
  436. package/lib/utils/media.js.map +1 -1
  437. package/lib/utils/react.js +1 -1
  438. package/lib/utils/react.js.map +1 -1
  439. package/lib/utils/state.d.ts +57 -0
  440. package/lib/utils/state.js +94 -0
  441. package/lib/utils/state.js.map +1 -0
  442. package/lib/utils/storage.js +11 -12
  443. package/lib/utils/storage.js.map +1 -1
  444. package/package.json +55 -18
  445. package/src/Piral.test.tsx +7 -16
  446. package/src/Piral.tsx +12 -11
  447. package/src/PiralContext.tsx +43 -0
  448. package/src/RootListener.test.tsx +46 -0
  449. package/src/RootListener.tsx +26 -0
  450. package/src/actions/app.test.ts +114 -44
  451. package/src/actions/app.ts +33 -23
  452. package/src/actions/components.test.ts +11 -11
  453. package/src/actions/components.ts +5 -33
  454. package/src/actions/data.test.ts +50 -50
  455. package/src/actions/define.test.ts +2 -2
  456. package/src/actions/portal.test.ts +62 -17
  457. package/src/actions/portal.ts +19 -1
  458. package/src/actions/state.test.ts +3 -3
  459. package/src/actions/state.ts +8 -4
  460. package/src/components/ErrorBoundary.tsx +22 -49
  461. package/src/components/ExtensionSlot.test.tsx +115 -30
  462. package/src/components/ExtensionSlot.tsx +57 -18
  463. package/src/components/ForeignComponentContainer.test.tsx +100 -0
  464. package/src/components/ForeignComponentContainer.tsx +63 -0
  465. package/src/components/Mediator.test.tsx +16 -14
  466. package/src/components/Mediator.tsx +17 -9
  467. package/src/components/PiralGlobals.tsx +16 -0
  468. package/src/components/PiralRoutes.test.tsx +65 -57
  469. package/src/components/PiralRoutes.tsx +10 -17
  470. package/src/components/PiralSuspense.tsx +19 -0
  471. package/src/components/PiralView-server.test.tsx +61 -0
  472. package/src/components/PiralView.test.tsx +27 -26
  473. package/src/components/PiralView.tsx +28 -35
  474. package/src/components/PortalRenderer.tsx +12 -0
  475. package/src/components/ResponsiveLayout.test.tsx +18 -37
  476. package/src/components/ResponsiveLayout.tsx +18 -15
  477. package/src/components/SwitchErrorInfo.test.tsx +36 -0
  478. package/src/components/SwitchErrorInfo.tsx +5 -1
  479. package/src/components/components.tsx +20 -6
  480. package/src/components/index.ts +4 -10
  481. package/src/components/wrapComponent.tsx +74 -0
  482. package/src/createInstance.test.tsx +10 -0
  483. package/src/createInstance.tsx +19 -14
  484. package/src/{components → defaults}/DefaultErrorInfo.test.tsx +15 -18
  485. package/src/{components → defaults}/DefaultErrorInfo.tsx +2 -3
  486. package/src/defaults/DefaultLayout.test.tsx +23 -0
  487. package/src/defaults/DefaultLoadingIndicator.test.tsx +10 -0
  488. package/src/defaults/DefaultRouteSwitch_v5.tsx +15 -0
  489. package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
  490. package/src/defaults/DefaultRouter_v5.tsx +8 -0
  491. package/src/defaults/DefaultRouter_v6.tsx +8 -0
  492. package/src/defaults/navigator_none.tsx +35 -0
  493. package/src/defaults/navigator_v5.tsx +99 -0
  494. package/src/defaults/navigator_v6.tsx +96 -0
  495. package/src/helpers.test.tsx +30 -49
  496. package/src/helpers.tsx +31 -108
  497. package/src/hooks/action.ts +2 -3
  498. package/src/hooks/globalState.ts +10 -9
  499. package/src/hooks/index.ts +2 -5
  500. package/src/hooks/media.ts +2 -1
  501. package/src/hooks/piletApi.ts +14 -0
  502. package/src/hooks/routes.ts +14 -0
  503. package/src/hooks/setter-server.test.ts +22 -0
  504. package/src/hooks/setter.test.ts +18 -0
  505. package/src/hooks/setter.ts +2 -1
  506. package/src/index.tsx +3 -1
  507. package/src/modules/api.test.ts +15 -26
  508. package/src/modules/api.ts +3 -65
  509. package/src/modules/core.test.ts +148 -0
  510. package/src/modules/core.ts +52 -0
  511. package/src/modules/dependencies.test.ts +16 -5
  512. package/src/modules/dependencies.ts +13 -31
  513. package/src/modules/element-server.test.ts +29 -0
  514. package/src/modules/element.test.ts +67 -0
  515. package/src/modules/element.ts +212 -0
  516. package/src/modules/index.ts +1 -0
  517. package/src/{components → setters}/SetComponent.test.tsx +9 -8
  518. package/src/{components → setters}/SetComponent.tsx +2 -2
  519. package/src/{components → setters}/SetError.test.tsx +9 -8
  520. package/src/{components → setters}/SetError.tsx +2 -2
  521. package/src/{components → setters}/SetErrors.test.tsx +9 -8
  522. package/src/{components → setters}/SetLayout.test.tsx +9 -8
  523. package/src/{components → setters}/SetProvider.test.tsx +9 -8
  524. package/src/{components → setters}/SetProvider.tsx +2 -2
  525. package/src/{components → setters}/SetRedirect.test.tsx +9 -8
  526. package/src/{components → setters}/SetRedirect.tsx +4 -4
  527. package/src/{components → setters}/SetRoute.test.tsx +9 -8
  528. package/src/{components → setters}/SetRoute.tsx +7 -4
  529. package/src/setters/index.ts +7 -0
  530. package/src/state/createActions.test.ts +2 -2
  531. package/src/state/createActions.ts +5 -3
  532. package/src/state/createGlobalState.test.ts +55 -54
  533. package/src/state/createGlobalState.ts +4 -28
  534. package/src/state/withApi.test.tsx +87 -40
  535. package/src/state/withApi.tsx +31 -165
  536. package/src/tools/codegen.ts +193 -0
  537. package/src/tools/debugger.ts +84 -0
  538. package/src/tools/emulator.ts +13 -0
  539. package/src/types/api.ts +50 -11
  540. package/src/types/components.ts +76 -7
  541. package/src/types/config.ts +23 -17
  542. package/src/types/extension.ts +38 -5
  543. package/src/types/index.ts +1 -0
  544. package/src/types/instance.ts +28 -4
  545. package/src/types/navigation.ts +101 -0
  546. package/src/types/plugin.ts +1 -15
  547. package/src/types/state.ts +65 -25
  548. package/src/types/utils.ts +1 -1
  549. package/src/utils/compare.test.ts +15 -15
  550. package/src/utils/compare.ts +23 -3
  551. package/src/utils/extension.test.tsx +21 -0
  552. package/src/utils/extension.tsx +48 -0
  553. package/src/utils/foreign.test.ts +29 -11
  554. package/src/utils/foreign.ts +34 -7
  555. package/src/utils/guid.test.ts +6 -1
  556. package/src/utils/helpers.test.ts +52 -0
  557. package/src/utils/helpers.ts +22 -8
  558. package/src/utils/index.ts +4 -1
  559. package/src/utils/media-server.test.ts +13 -0
  560. package/src/utils/media.ts +2 -2
  561. package/src/utils/state.test.ts +37 -0
  562. package/src/utils/state.ts +131 -0
  563. package/dependencies.codegen +0 -9
  564. package/dependencies.codegen.native.js +0 -2
  565. package/esm/components/DefaultErrorInfo.js +0 -12
  566. package/esm/components/DefaultErrorInfo.js.map +0 -1
  567. package/esm/components/DefaultLayout.js.map +0 -1
  568. package/esm/components/DefaultLoader.js.map +0 -1
  569. package/esm/components/SetComponent.js +0 -12
  570. package/esm/components/SetComponent.js.map +0 -1
  571. package/esm/components/SetError.js +0 -12
  572. package/esm/components/SetError.js.map +0 -1
  573. package/esm/components/SetErrors.js +0 -10
  574. package/esm/components/SetErrors.js.map +0 -1
  575. package/esm/components/SetLayout.js +0 -10
  576. package/esm/components/SetLayout.js.map +0 -1
  577. package/esm/components/SetProvider.js +0 -12
  578. package/esm/components/SetProvider.js.map +0 -1
  579. package/esm/components/SetRedirect.js +0 -14
  580. package/esm/components/SetRedirect.js.map +0 -1
  581. package/esm/components/SetRoute.js +0 -12
  582. package/esm/components/SetRoute.js.map +0 -1
  583. package/esm/hooks/debounce.d.ts +0 -8
  584. package/esm/hooks/debounce.js +0 -18
  585. package/esm/hooks/debounce.js.map +0 -1
  586. package/esm/hooks/lockBodyScroll.d.ts +0 -6
  587. package/esm/hooks/lockBodyScroll.js +0 -13
  588. package/esm/hooks/lockBodyScroll.js.map +0 -1
  589. package/esm/hooks/onClickOutside.d.ts +0 -8
  590. package/esm/hooks/onClickOutside.js +0 -23
  591. package/esm/hooks/onClickOutside.js.map +0 -1
  592. package/esm/hooks/onScreenVisible.d.ts +0 -11
  593. package/esm/hooks/onScreenVisible.js +0 -28
  594. package/esm/hooks/onScreenVisible.js.map +0 -1
  595. package/esm/hooks/promise.d.ts +0 -13
  596. package/esm/hooks/promise.js +0 -21
  597. package/esm/hooks/promise.js.map +0 -1
  598. package/esm/utils/events.d.ts +0 -3
  599. package/esm/utils/events.js +0 -35
  600. package/esm/utils/events.js.map +0 -1
  601. package/lib/components/DefaultErrorInfo.js +0 -15
  602. package/lib/components/DefaultErrorInfo.js.map +0 -1
  603. package/lib/components/DefaultLayout.js.map +0 -1
  604. package/lib/components/DefaultLoader.js.map +0 -1
  605. package/lib/components/SetComponent.js +0 -16
  606. package/lib/components/SetComponent.js.map +0 -1
  607. package/lib/components/SetError.js +0 -16
  608. package/lib/components/SetError.js.map +0 -1
  609. package/lib/components/SetErrors.js +0 -14
  610. package/lib/components/SetErrors.js.map +0 -1
  611. package/lib/components/SetLayout.js +0 -14
  612. package/lib/components/SetLayout.js.map +0 -1
  613. package/lib/components/SetProvider.js.map +0 -1
  614. package/lib/components/SetRedirect.js +0 -18
  615. package/lib/components/SetRedirect.js.map +0 -1
  616. package/lib/components/SetRoute.js +0 -16
  617. package/lib/components/SetRoute.js.map +0 -1
  618. package/lib/hooks/debounce.d.ts +0 -8
  619. package/lib/hooks/debounce.js +0 -22
  620. package/lib/hooks/debounce.js.map +0 -1
  621. package/lib/hooks/lockBodyScroll.d.ts +0 -6
  622. package/lib/hooks/lockBodyScroll.js +0 -17
  623. package/lib/hooks/lockBodyScroll.js.map +0 -1
  624. package/lib/hooks/onClickOutside.d.ts +0 -8
  625. package/lib/hooks/onClickOutside.js +0 -27
  626. package/lib/hooks/onClickOutside.js.map +0 -1
  627. package/lib/hooks/onScreenVisible.d.ts +0 -11
  628. package/lib/hooks/onScreenVisible.js +0 -32
  629. package/lib/hooks/onScreenVisible.js.map +0 -1
  630. package/lib/hooks/promise.d.ts +0 -13
  631. package/lib/hooks/promise.js +0 -25
  632. package/lib/hooks/promise.js.map +0 -1
  633. package/lib/utils/events.d.ts +0 -3
  634. package/lib/utils/events.js +0 -39
  635. package/lib/utils/events.js.map +0 -1
  636. package/src/components/DefaultLayout.test.tsx +0 -23
  637. package/src/components/DefaultLoader.test.tsx +0 -10
  638. package/src/hooks/debounce.test.ts +0 -67
  639. package/src/hooks/debounce.ts +0 -19
  640. package/src/hooks/globalState.test.ts +0 -47
  641. package/src/hooks/lockBodyScroll.test.ts +0 -24
  642. package/src/hooks/lockBodyScroll.ts +0 -13
  643. package/src/hooks/onClickOutside.test.ts +0 -113
  644. package/src/hooks/onClickOutside.ts +0 -25
  645. package/src/hooks/onScreenVisible.test.ts +0 -68
  646. package/src/hooks/onScreenVisible.ts +0 -28
  647. package/src/hooks/promise.test.ts +0 -76
  648. package/src/hooks/promise.ts +0 -35
  649. package/src/utils/events.test.ts +0 -65
  650. package/src/utils/events.ts +0 -39
  651. package/esm/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
  652. package/esm/{components → defaults}/DefaultLayout.d.ts +0 -0
  653. package/esm/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
  654. package/esm/{components → setters}/SetComponent.d.ts +0 -0
  655. package/esm/{components → setters}/SetError.d.ts +0 -0
  656. package/esm/{components → setters}/SetErrors.d.ts +0 -0
  657. package/esm/{components → setters}/SetLayout.d.ts +0 -0
  658. package/esm/{components → setters}/SetProvider.d.ts +0 -0
  659. package/esm/{components → setters}/SetRedirect.d.ts +0 -0
  660. package/lib/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
  661. package/lib/{components → defaults}/DefaultLayout.d.ts +0 -0
  662. package/lib/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
  663. package/lib/{components → setters}/SetComponent.d.ts +0 -0
  664. package/lib/{components → setters}/SetError.d.ts +0 -0
  665. package/lib/{components → setters}/SetErrors.d.ts +0 -0
  666. package/lib/{components → setters}/SetLayout.d.ts +0 -0
  667. package/lib/{components → setters}/SetProvider.d.ts +0 -0
  668. package/lib/{components → setters}/SetRedirect.d.ts +0 -0
  669. package/src/{components → defaults}/DefaultLayout.tsx +1 -1
  670. /package/src/{components/DefaultLoader.tsx → defaults/DefaultLoadingIndicator.tsx} +0 -0
  671. /package/src/{components → setters}/SetErrors.tsx +0 -0
  672. /package/src/{components → setters}/SetLayout.tsx +0 -0
@@ -0,0 +1,84 @@
1
+ import { LoadPiletsOptions } from 'piral-base';
2
+ import { installPiralDebug, DebuggerExtensionOptions } from 'piral-debug-utils';
3
+ import { GlobalStateContext } from '../types';
4
+
5
+ export function integrateDebugger(
6
+ context: GlobalStateContext,
7
+ options: LoadPiletsOptions,
8
+ debug: DebuggerExtensionOptions = {},
9
+ ) {
10
+ installPiralDebug({
11
+ ...debug,
12
+ addPilet: context.addPilet,
13
+ removePilet: context.removePilet,
14
+ updatePilet(pilet) {
15
+ if (!pilet.disabled) {
16
+ const { createApi } = options;
17
+ const newApi = createApi(pilet);
18
+
19
+ try {
20
+ context.injectPilet(pilet);
21
+ pilet.setup(newApi);
22
+ } catch (error) {
23
+ console.error(error);
24
+ }
25
+ } else {
26
+ context.injectPilet(pilet);
27
+ }
28
+ },
29
+ fireEvent: context.emit,
30
+ getDependencies() {
31
+ return Object.keys(options.dependencies);
32
+ },
33
+ getExtensions() {
34
+ return context.readState((s) => Object.keys(s.registry.extensions));
35
+ },
36
+ getRoutes() {
37
+ const registeredRoutes = context.readState((state) => Object.keys(state.registry.pages));
38
+ const componentRoutes = context.readState((state) => Object.keys(state.routes));
39
+ return [...componentRoutes, ...registeredRoutes];
40
+ },
41
+ getGlobalState() {
42
+ return context.readState((s) => s);
43
+ },
44
+ navigate(path, state) {
45
+ return context.navigation.push(path, state);
46
+ },
47
+ getPilets() {
48
+ return context.readState((s) => s.modules);
49
+ },
50
+ integrate(dbg) {
51
+ context.dispatch((s) => ({
52
+ ...s,
53
+ components: {
54
+ ...s.components,
55
+ ...dbg.components,
56
+ },
57
+ routes: {
58
+ ...s.routes,
59
+ ...dbg.routes,
60
+ },
61
+ registry: {
62
+ ...s.registry,
63
+ wrappers: {
64
+ ...s.registry.wrappers,
65
+ ...dbg.wrappers,
66
+ },
67
+ },
68
+ }));
69
+
70
+ context.state.subscribe((current, previous) => {
71
+ const pilets = current.modules !== previous.modules;
72
+ const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
73
+ const extensions = current.registry.extensions !== previous.registry.extensions;
74
+ const state = current !== previous;
75
+ dbg.onChange(previous, current, {
76
+ pilets,
77
+ pages,
78
+ extensions,
79
+ state,
80
+ });
81
+ });
82
+ },
83
+ });
84
+ }
@@ -0,0 +1,13 @@
1
+ import { LoadPiletsOptions } from 'piral-base';
2
+ import { installPiletEmulator } from 'piral-debug-utils';
3
+ import { GlobalStateContext } from '../types';
4
+
5
+ export function integrateEmulator(context: GlobalStateContext, options: LoadPiletsOptions) {
6
+ installPiletEmulator(options.fetchPilets, {
7
+ addPilet: context.addPilet,
8
+ removePilet: context.removePilet,
9
+ integrate(requester) {
10
+ options.fetchPilets = requester;
11
+ },
12
+ });
13
+ }
package/src/types/api.ts CHANGED
@@ -1,12 +1,23 @@
1
- import type { ReactElement } from 'react';
1
+ import type { ReactElement, ReactNode } from 'react';
2
2
  import type { RouteComponentProps } from 'react-router';
3
- import type { PiletApi, Pilet, PiletMetadata, EventEmitter, SinglePilet, MultiPilet } from 'piral-base';
3
+ import type {
4
+ PiletApi,
5
+ Pilet,
6
+ PiletEntry,
7
+ PiletEntries,
8
+ PiletMetadata,
9
+ EventEmitter,
10
+ PiletLoader,
11
+ PiletLoadingStrategy,
12
+ } from 'piral-base';
13
+ import type {} from 'piral-debug-utils';
4
14
  import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
5
15
  import type { AnyComponent } from './components';
6
- import type { ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
16
+ import type { ExtensionParams, ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
7
17
  import type { SharedData, DataStoreOptions } from './data';
18
+ import type { Disposable } from './utils';
8
19
 
9
- export { PiletApi, Pilet, PiletMetadata, EventEmitter, SinglePilet, MultiPilet };
20
+ export { PiletApi, Pilet, PiletMetadata, EventEmitter, PiletEntry, PiletEntries, PiletLoader, PiletLoadingStrategy };
10
21
 
11
22
  /**
12
23
  * The props that every registered component obtains.
@@ -36,25 +47,52 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
36
47
  * The provided parameters for showing the extension.
37
48
  */
38
49
  params: T extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[T] : T extends string ? any : T;
50
+ /**
51
+ * The optional children to receive, if any.
52
+ */
53
+ children?: ReactNode;
39
54
  }
40
55
 
56
+ /**
57
+ * The meta data registered for a page.
58
+ */
59
+ export interface PiralPageMeta extends PiralCustomPageMeta {}
60
+
41
61
  /**
42
62
  * The props that every registered page component obtains.
43
63
  */
44
- export interface RouteBaseProps<UrlParams = any, UrlState = any>
64
+ export interface RouteBaseProps<UrlParams extends { [K in keyof UrlParams]?: string } = {}, UrlState = any>
45
65
  extends RouteComponentProps<UrlParams, {}, UrlState>,
46
66
  BaseComponentProps {}
47
67
 
48
68
  /**
49
69
  * The props used by a page component.
50
70
  */
51
- export interface PageComponentProps<T = any, S = any> extends RouteBaseProps<T, S> {}
71
+ export interface PageComponentProps<T extends { [K in keyof T]?: string } = {}, S = any> extends RouteBaseProps<T, S> {
72
+ /**
73
+ * The meta data registered with the page.
74
+ */
75
+ meta: PiralPageMeta;
76
+ /**
77
+ * The children of the page.
78
+ */
79
+ children: ReactNode;
80
+ }
52
81
 
53
82
  /**
54
83
  * The meta data registered for a page.
55
84
  */
56
85
  export interface PiralPageMeta extends PiralCustomPageMeta {}
57
86
 
87
+ /**
88
+ * Shorthand for the definition of an extension component.
89
+ */
90
+ export type AnyExtensionComponent<TName> = TName extends keyof PiralExtensionSlotMap
91
+ ? AnyComponent<ExtensionComponentProps<TName>>
92
+ : TName extends string
93
+ ? AnyComponent<ExtensionComponentProps<any>>
94
+ : AnyComponent<ExtensionComponentProps<TName>>;
95
+
58
96
  /**
59
97
  * Defines the Pilet API from piral-core.
60
98
  * This interface will be consumed by pilet developers so that their pilet can interact with the piral instance.
@@ -97,8 +135,8 @@ export interface PiletCoreApi {
97
135
  */
98
136
  registerExtension<TName>(
99
137
  name: TName extends string ? TName : string,
100
- Component: AnyComponent<ExtensionComponentProps<TName>>,
101
- defaults?: TName,
138
+ Component: AnyExtensionComponent<TName>,
139
+ defaults?: Partial<ExtensionParams<TName>>,
102
140
  ): RegistrationDisposer;
103
141
  /**
104
142
  * Unregisters a global extension component.
@@ -108,7 +146,7 @@ export interface PiletCoreApi {
108
146
  */
109
147
  unregisterExtension<TName>(
110
148
  name: TName extends string ? TName : string,
111
- Component: AnyComponent<ExtensionComponentProps<TName>>,
149
+ Component: AnyExtensionComponent<TName>,
112
150
  ): void;
113
151
  /**
114
152
  * React component for displaying extensions for a given name.
@@ -120,11 +158,12 @@ export interface PiletCoreApi {
120
158
  * Renders an extension in a plain DOM component.
121
159
  * @param element The DOM element or shadow root as a container for rendering the extension.
122
160
  * @param props The extension's rendering props.
161
+ * @return The disposer to clear the extension.
123
162
  */
124
- renderHtmlExtension<TName>(element: HTMLElement | ShadowRoot, props: ExtensionSlotProps<TName>): void;
163
+ renderHtmlExtension<TName>(element: HTMLElement | ShadowRoot, props: ExtensionSlotProps<TName>): Disposable;
125
164
  }
126
165
 
127
- declare module 'piral-base/lib/types' {
166
+ declare module 'piral-base/lib/types/runtime' {
128
167
  interface PiletApi extends PiletCustomApi, PiletCoreApi {}
129
168
  }
130
169
 
@@ -1,7 +1,8 @@
1
- import type { ComponentType } from 'react';
2
- import type { RouteComponentProps } from 'react-router';
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { RouteComponentProps, SwitchProps } from 'react-router';
3
3
  import type { FirstParametersOf, UnionOf } from './common';
4
4
  import type { PiralCustomErrors, PiralCustomComponentConverters } from './custom';
5
+ import type { NavigationApi } from './navigation';
5
6
  import type { LayoutType } from './layout';
6
7
 
7
8
  /**
@@ -33,7 +34,19 @@ export interface HtmlComponent<TProps> {
33
34
  * The context to be transported into the generic components.
34
35
  */
35
36
  export interface ComponentContext {
36
- router: RouteComponentProps;
37
+ /**
38
+ * The router-independent navigation API.
39
+ */
40
+ navigation: NavigationApi;
41
+ /**
42
+ * The internal router object.
43
+ * @deprecated Exposes internals that can change at any time.
44
+ */
45
+ router: any;
46
+ /**
47
+ * The public path of the application.
48
+ */
49
+ publicPath: string;
37
50
  }
38
51
 
39
52
  /**
@@ -45,20 +58,23 @@ export interface ForeignComponent<TProps> {
45
58
  * @param element The container hosting the element.
46
59
  * @param props The props to transport.
47
60
  * @param ctx The associated context.
61
+ * @param locals The local state of this component instance.
48
62
  */
49
- mount(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
63
+ mount(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
50
64
  /**
51
65
  * Called when the component should be updated.
52
66
  * @param element The container hosting the element.
53
67
  * @param props The props to transport.
54
68
  * @param ctx The associated context.
69
+ * @param locals The local state of this component instance.
55
70
  */
56
- update?(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
71
+ update?(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
57
72
  /**
58
73
  * Called when a component is unmounted.
59
74
  * @param element The container that was hosting the element.
75
+ * @param locals The local state of this component instance.
60
76
  */
61
- unmount?(element: HTMLElement): void;
77
+ unmount?(element: HTMLElement, locals: Record<string, any>): void;
62
78
  }
63
79
 
64
80
  /**
@@ -88,6 +104,10 @@ export interface PageErrorInfoProps extends RouteComponentProps {
88
104
  * The provided error details.
89
105
  */
90
106
  error: any;
107
+ /**
108
+ * The name of the pilet emitting the error.
109
+ */
110
+ pilet?: string;
91
111
  }
92
112
 
93
113
  /**
@@ -116,6 +136,10 @@ export interface ExtensionErrorInfoProps {
116
136
  * The provided error details.
117
137
  */
118
138
  error: any;
139
+ /**
140
+ * The name of the pilet emitting the error.
141
+ */
142
+ pilet?: string;
119
143
  }
120
144
 
121
145
  /**
@@ -130,6 +154,10 @@ export interface UnknownErrorInfoProps {
130
154
  * The provided error details.
131
155
  */
132
156
  error: any;
157
+ /**
158
+ * The name of the pilet emitting the error.
159
+ */
160
+ pilet?: string;
133
161
  }
134
162
 
135
163
  /**
@@ -176,9 +204,50 @@ export interface LayoutProps {
176
204
  * The currently selected layout type.
177
205
  */
178
206
  currentLayout: LayoutType;
207
+ /**
208
+ * The page's content.
209
+ */
210
+ children: ReactNode;
179
211
  }
180
212
 
181
213
  /**
182
214
  * The props of a Router component.
183
215
  */
184
- export interface RouterProps {}
216
+ export interface RouterProps {
217
+ /**
218
+ * The content to be rendered inside the router.
219
+ */
220
+ children?: ReactNode;
221
+ /**
222
+ * The public path to use.
223
+ */
224
+ publicPath: string;
225
+ }
226
+
227
+ /**
228
+ * Represents a path in the app registration.
229
+ */
230
+ export interface AppPath {
231
+ /**
232
+ * The exact path to use.
233
+ */
234
+ path: string;
235
+ /**
236
+ * The component to register for this path.
237
+ */
238
+ Component: ComponentType<RouteComponentProps>;
239
+ }
240
+
241
+ /**
242
+ * The props of the RouteSwitch component.
243
+ */
244
+ export interface RouteSwitchProps extends SwitchProps {
245
+ /**
246
+ * The component that should be used in case nothing was found.
247
+ */
248
+ NotFound: ComponentType<RouteComponentProps>;
249
+ /**
250
+ * The component to register for the different paths.
251
+ */
252
+ paths: Array<AppPath>;
253
+ }
@@ -1,7 +1,5 @@
1
1
  import type {
2
2
  PiletRequester,
3
- PiletDependencyFetcher,
4
- PiletDependencyGetter,
5
3
  PiletLoadingStrategy,
6
4
  PiletLoader,
7
5
  Pilet,
@@ -10,24 +8,30 @@ import type {
10
8
  DefaultLoaderConfig,
11
9
  PiletApiCreator,
12
10
  } from 'piral-base';
11
+ import { DebuggerExtensionOptions } from 'piral-debug-utils';
13
12
  import type { NestedPartial } from './common';
14
13
  import type { PiralPlugin } from './plugin';
15
14
  import type { GlobalState, GlobalStateContext, PiralDefineActions } from './state';
16
15
 
17
- export { PiletLoadingStrategy, PiletDependencyFetcher, PiletDependencyGetter, PiletRequester, AvailableDependencies };
16
+ export { PiletLoadingStrategy, PiletRequester, AvailableDependencies };
18
17
 
19
18
  /**
20
- * The configuration for loading the pilets of the Piral instance.
19
+ * Definition for customizing the shared dependencies.
21
20
  */
22
- export interface PiralPiletConfiguration {
23
- /**
24
- * The callback for defining how a dependency will be fetched.
25
- */
26
- fetchDependency?: PiletDependencyFetcher;
21
+ export interface DependencySelector {
27
22
  /**
28
- * Function to get the dependencies for a given module.
23
+ * Selects the dependencies to share from the currently available dependencies.
24
+ * @param currentDependencies The currently available dependencies.
25
+ * @default currentDependencies All current dependencies are shared
26
+ * @returns The dependencies selected to be shared.
29
27
  */
30
- getDependencies?: PiletDependencyGetter;
28
+ (currentDependencies: AvailableDependencies): AvailableDependencies;
29
+ }
30
+
31
+ /**
32
+ * The configuration for loading the pilets of the Piral instance.
33
+ */
34
+ export interface PiralPiletConfiguration {
31
35
  /**
32
36
  * Function to load the modules asynchronously, e.g., from a server 🚚.
33
37
  */
@@ -44,6 +48,10 @@ export interface PiralPiletConfiguration {
44
48
  * Optionally, configures the default loader.
45
49
  */
46
50
  loaderConfig?: DefaultLoaderConfig;
51
+ /**
52
+ * Optionally, configures explicitly what dependencies are shared.
53
+ */
54
+ shareDependencies?: DependencySelector;
47
55
  /**
48
56
  * Determines that pilets are loaded asynchronously, essentially showing the
49
57
  * app right away without waiting for the pilets to load and evaluate.
@@ -55,12 +63,6 @@ export interface PiralPiletConfiguration {
55
63
  * This can be used for customization or for debugging purposes.
56
64
  */
57
65
  availablePilets?: Array<Pilet>;
58
- /**
59
- * Optionally provides a function to extend the API creator with some additional
60
- * functionality.
61
- * @deprecated Use plugins instead.
62
- */
63
- extendApi?: PiralPlugin | Array<PiralPlugin>;
64
66
  /**
65
67
  * Extends the Piral instance with additional capabilities.
66
68
  */
@@ -95,6 +97,10 @@ export interface PiralStateConfiguration {
95
97
  * Optionally, sets up some initial custom actions ⚡️.
96
98
  */
97
99
  actions?: PiralDefineActions;
100
+ /**
101
+ * Optionally, sets up additional configuration for the debug tooling 🤖.
102
+ */
103
+ debug?: DebuggerExtensionOptions;
98
104
  }
99
105
 
100
106
  /**
@@ -1,4 +1,6 @@
1
+ import type { ReactNode, ReactElement } from 'react';
1
2
  import type { PiralCustomExtensionSlotMap } from './custom';
3
+ import type { ExtensionRegistration } from './state';
2
4
 
3
5
  /**
4
6
  * The mapping of the existing (known) extension slots.
@@ -9,16 +11,38 @@ export interface PiralExtensionSlotMap extends PiralCustomExtensionSlotMap {}
9
11
  * The basic props for defining an extension slot.
10
12
  */
11
13
  export interface BaseExtensionSlotProps<TName, TParams> {
14
+ /**
15
+ * The children to transport, if any.
16
+ */
17
+ children?: ReactNode;
12
18
  /**
13
19
  * Defines what should be rendered when no components are available
14
20
  * for the specified extension.
15
21
  */
16
- empty?(): React.ReactNode;
22
+ empty?(): ReactNode;
23
+ /**
24
+ * Determines if the `render` function should be called in case no
25
+ * components are available for the specified extension.
26
+ *
27
+ * If true, `empty` will be called and returned from the slot.
28
+ * If false, `render` will be called with the result of calling `empty`.
29
+ * The result of calling `render` will then be returned from the slot.
30
+ */
31
+ emptySkipsRender?: boolean;
32
+ /**
33
+ * Defines the order of the components to render.
34
+ * May be more convient than using `render` w.r.t. ordering extensions
35
+ * by their supplied metadata.
36
+ * @param extensions The registered extensions.
37
+ * @returns The ordered extensions.
38
+ */
39
+ order?(extensions: Array<ExtensionRegistration>): Array<ExtensionRegistration>;
17
40
  /**
18
41
  * Defines how the provided nodes should be rendered.
19
42
  * @param nodes The rendered extension nodes.
43
+ * @returns The rendered nodes, i.e., an ReactElement.
20
44
  */
21
- render?(nodes: Array<React.ReactNode>): React.ReactElement<any, any> | null;
45
+ render?(nodes: Array<ReactNode>): ReactElement<any, any> | null;
22
46
  /**
23
47
  * The custom parameters for the given extension.
24
48
  */
@@ -29,10 +53,19 @@ export interface BaseExtensionSlotProps<TName, TParams> {
29
53
  name: TName;
30
54
  }
31
55
 
56
+ /**
57
+ * Gives the extension params shape for the given extension slot name.
58
+ */
59
+ export type ExtensionParams<TName> = TName extends keyof PiralExtensionSlotMap
60
+ ? PiralExtensionSlotMap[TName]
61
+ : TName extends string
62
+ ? any
63
+ : TName;
64
+
32
65
  /**
33
66
  * The props for defining an extension slot.
34
67
  */
35
- export type ExtensionSlotProps<K = string> = BaseExtensionSlotProps<
36
- K extends string ? K : string,
37
- K extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[K] : K extends string ? any : K
68
+ export type ExtensionSlotProps<TName = string> = BaseExtensionSlotProps<
69
+ TName extends string ? TName : string,
70
+ ExtensionParams<TName>
38
71
  >;
@@ -7,6 +7,7 @@ export * from './data';
7
7
  export * from './extension';
8
8
  export * from './instance';
9
9
  export * from './layout';
10
+ export * from './navigation';
10
11
  export * from './plugin';
11
12
  export * from './state';
12
13
  export * from './utils';
@@ -1,15 +1,24 @@
1
+ import type { ReactNode } from 'react';
1
2
  import type { PiletApi, PiletApiCreator, LoadPiletsOptions, EventEmitter } from 'piral-base';
2
3
  import type { GlobalStateContext } from './state';
3
4
  import type { LayoutBreakpoints } from './layout';
5
+ import type { PiralConfiguration } from './config';
4
6
 
5
7
  /**
6
- * The props of the Piral component.
8
+ * The props of the Piral context.
7
9
  */
8
- export interface PortalProps {
10
+ export interface PiralContextProps {
9
11
  /**
10
12
  * The specific Piral instance to be used.
11
13
  */
12
14
  instance?: PiralInstance;
15
+ children?: ReactNode;
16
+ }
17
+
18
+ /**
19
+ * The props of the Piral component.
20
+ */
21
+ export interface PiralProps extends PiralContextProps {
13
22
  /**
14
23
  * The custom breakpoints for the different layout modi.
15
24
  */
@@ -17,10 +26,25 @@ export interface PortalProps {
17
26
  }
18
27
 
19
28
  /**
20
- * The PiralInstance component, which is an event emitter containing the React
21
- * functional component as well as some other utilities and helpers.
29
+ * The options for creating a new PiralInstance object.
30
+ */
31
+ export interface PiralInstanceOptions extends PiralConfiguration {
32
+ /**
33
+ * Defines the id of this instance. Used in case of multiple instances.
34
+ */
35
+ id?: string;
36
+ }
37
+
38
+ /**
39
+ * The PiralInstance object, which is an event emitter with some other
40
+ * utilities and helper. This object is the source for the React
41
+ * functional component (`Piral`).
22
42
  */
23
43
  export interface PiralInstance extends EventEmitter {
44
+ /**
45
+ * The id of the Piral instance.
46
+ */
47
+ id: string;
24
48
  /**
25
49
  * The global state context instance.
26
50
  */
@@ -0,0 +1,101 @@
1
+ import type { Disposable } from './utils';
2
+
3
+ export type NavigationAction = 'POP' | 'PUSH' | 'REPLACE';
4
+
5
+ export interface NavigationLocation {
6
+ /**
7
+ * The fully qualified URL incl. the origin and base path.
8
+ */
9
+ href: string;
10
+ /**
11
+ * The location.pathname property is a string that contains an initial "/"
12
+ * followed by the remainder of the URL up to the ?.
13
+ */
14
+ pathname: string;
15
+ /**
16
+ * The location.search property is a string that contains an initial "?"
17
+ * followed by the key=value pairs in the query string. If there are no
18
+ * parameters, this value may be the empty string (i.e. '').
19
+ */
20
+ search: string;
21
+ /**
22
+ * The location.hash property is a string that contains an initial "#"
23
+ * followed by fragment identifier of the URL. If there is no fragment
24
+ * identifier, this value may be the empty string (i.e. '').
25
+ */
26
+ hash: string;
27
+ /**
28
+ * The location.state property is a user-supplied State object that is
29
+ * associated with this location. This can be a useful place to store
30
+ * any information you do not want to put in the URL, e.g. session-specific
31
+ * data.
32
+ */
33
+ state: unknown;
34
+ /**
35
+ * The location.key property is a unique string associated with this location.
36
+ * On the initial location, this will be the string default. On all subsequent
37
+ * locations, this string will be a unique identifier.
38
+ */
39
+ key?: string;
40
+ }
41
+
42
+ export interface NavigationListener {
43
+ (update: NavigationUpdate): void;
44
+ }
45
+
46
+ export interface NavigationBlocker {
47
+ (tx: NavigationTransition): void;
48
+ }
49
+
50
+ export interface NavigationUpdate {
51
+ action: NavigationAction;
52
+ location: NavigationLocation;
53
+ }
54
+
55
+ export interface NavigationTransition extends NavigationUpdate {
56
+ retry?(): void;
57
+ }
58
+
59
+ export interface NavigationApi {
60
+ /**
61
+ * Pushes a new location onto the history stack.
62
+ */
63
+ push(target: string, state?: any): void;
64
+ /**
65
+ * Replaces the current location with another.
66
+ */
67
+ replace(target: string, state?: any): void;
68
+ /**
69
+ * Changes the current index in the history stack by a given delta.
70
+ */
71
+ go(n: number): void;
72
+ /**
73
+ * Prevents changes to the history stack from happening.
74
+ * This is useful when you want to prevent the user navigating
75
+ * away from the current page, for example when they have some
76
+ * unsaved data on the current page.
77
+ * @param blocker The function being called with a transition request.
78
+ * @returns The disposable for stopping the block.
79
+ */
80
+ block(blocker: NavigationBlocker): Disposable;
81
+ /**
82
+ * Starts listening for location changes and calls the given
83
+ * callback with an Update when it does.
84
+ * @param listener The function being called when the route changes.
85
+ * @returns The disposable for stopping the block.
86
+ */
87
+ listen(listener: NavigationListener): Disposable;
88
+ /**
89
+ * Gets the current navigation / application path.
90
+ */
91
+ path: string;
92
+ /**
93
+ * Gets the current navigation path incl. search and hash parts.
94
+ */
95
+ url: string;
96
+ /**
97
+ * The original router behind the navigation. Don't depend on this
98
+ * as the implementation is router specific and may change over time.
99
+ */
100
+ router: any;
101
+ }