soseki 0.0.4 → 0.0.6

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 (352) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/components/browser-router.d.ts +19 -0
  3. package/dist/src/components/browser-router.d.ts.map +1 -0
  4. package/dist/src/components/browser-router.jsx +15 -0
  5. package/dist/src/components/outlet.d.ts +8 -0
  6. package/dist/src/components/outlet.d.ts.map +1 -0
  7. package/dist/src/components/outlet.jsx +15 -0
  8. package/dist/src/components/router.d.ts +21 -0
  9. package/dist/src/components/router.d.ts.map +1 -0
  10. package/dist/src/components/router.jsx +138 -0
  11. package/dist/src/contexts/route-context.d.ts +19 -0
  12. package/dist/src/contexts/route-context.d.ts.map +1 -0
  13. package/dist/src/contexts/route-context.js +6 -0
  14. package/dist/src/contexts/router-context.d.ts +55 -0
  15. package/dist/src/contexts/router-context.d.ts.map +1 -0
  16. package/dist/src/contexts/router-context.js +8 -0
  17. package/dist/src/core/_compare-route-paths.d.ts +11 -0
  18. package/dist/src/core/_compare-route-paths.d.ts.map +1 -0
  19. package/dist/src/core/_compare-route-paths.js +92 -0
  20. package/dist/src/core/_match-route-path.d.ts +22 -0
  21. package/dist/src/core/_match-route-path.d.ts.map +1 -0
  22. package/dist/src/core/_match-route-path.js +26 -0
  23. package/dist/src/core/_process-routes.d.ts +14 -0
  24. package/dist/src/core/_process-routes.d.ts.map +1 -0
  25. package/dist/src/core/_process-routes.js +45 -0
  26. package/dist/src/core/_singleton.d.ts +12 -0
  27. package/dist/src/core/_singleton.d.ts.map +1 -0
  28. package/dist/src/core/_singleton.js +18 -0
  29. package/dist/src/core/_unreachable.d.ts +16 -0
  30. package/dist/src/core/_unreachable.d.ts.map +1 -0
  31. package/dist/src/core/_unreachable.js +8 -0
  32. package/dist/src/core/_valibot.d.ts +25 -0
  33. package/dist/src/core/_valibot.d.ts.map +1 -0
  34. package/dist/src/core/_valibot.js +30 -0
  35. package/dist/src/core/errors.d.ts +182 -0
  36. package/dist/src/core/errors.d.ts.map +1 -0
  37. package/dist/src/core/errors.js +166 -0
  38. package/dist/src/core/expect-history-entry.d.ts +59 -0
  39. package/dist/src/core/expect-history-entry.d.ts.map +1 -0
  40. package/dist/src/core/expect-history-entry.js +42 -0
  41. package/dist/src/core/form-data-to-html-form-element.d.ts +11 -0
  42. package/dist/src/core/form-data-to-html-form-element.d.ts.map +1 -0
  43. package/dist/src/core/form-data-to-html-form-element.js +31 -0
  44. package/dist/src/core/history-entry-id-schema.d.ts +17 -0
  45. package/dist/src/core/history-entry-id-schema.d.ts.map +1 -0
  46. package/dist/src/core/history-entry-id-schema.js +9 -0
  47. package/dist/src/core/history-entry-url-schema.d.ts +18 -0
  48. package/dist/src/core/history-entry-url-schema.d.ts.map +1 -0
  49. package/dist/src/core/history-entry-url-schema.js +20 -0
  50. package/dist/src/core/init-loaders.d.ts +28 -0
  51. package/dist/src/core/init-loaders.d.ts.map +1 -0
  52. package/dist/src/core/init-loaders.js +30 -0
  53. package/dist/src/core/match-routes.d.ts +28 -0
  54. package/dist/src/core/match-routes.d.ts.map +1 -0
  55. package/dist/src/core/match-routes.js +31 -0
  56. package/dist/src/core/readonly-form-data.types.d.ts +74 -0
  57. package/dist/src/core/readonly-form-data.types.d.ts.map +1 -0
  58. package/dist/src/core/readonly-url.types.d.ts +164 -0
  59. package/dist/src/core/readonly-url.types.d.ts.map +1 -0
  60. package/dist/src/core/redirect-response.d.ts +37 -0
  61. package/dist/src/core/redirect-response.d.ts.map +1 -0
  62. package/dist/src/core/redirect-response.js +19 -0
  63. package/dist/src/core/route-path.d.ts +57 -0
  64. package/dist/src/core/route-path.d.ts.map +1 -0
  65. package/dist/src/core/route-path.js +93 -0
  66. package/dist/src/core/route-request.d.ts +149 -0
  67. package/dist/src/core/route-request.d.ts.map +1 -0
  68. package/dist/src/core/route-request.js +41 -0
  69. package/dist/src/core/route.types.d.ts +296 -0
  70. package/dist/src/core/route.types.d.ts.map +1 -0
  71. package/dist/src/core/start-action.d.ts +53 -0
  72. package/dist/src/core/start-action.d.ts.map +1 -0
  73. package/dist/src/core/start-action.js +95 -0
  74. package/dist/src/core/start-loaders.d.ts +63 -0
  75. package/dist/src/core/start-loaders.d.ts.map +1 -0
  76. package/dist/src/core/start-loaders.js +138 -0
  77. package/dist/{core.d.ts → src/core.d.ts} +7 -11
  78. package/dist/src/core.d.ts.map +1 -0
  79. package/dist/{core.js → src/core.js} +2 -4
  80. package/dist/src/engines/engine.types.d.ts +216 -0
  81. package/dist/src/engines/engine.types.d.ts.map +1 -0
  82. package/dist/src/engines/navigation-api-engine.d.ts +50 -0
  83. package/dist/src/engines/navigation-api-engine.d.ts.map +1 -0
  84. package/dist/src/engines/navigation-api-engine.js +411 -0
  85. package/dist/src/engines.d.ts +4 -0
  86. package/dist/src/engines.d.ts.map +1 -0
  87. package/dist/src/engines.js +1 -0
  88. package/dist/src/hooks/_use-singleton.d.ts +11 -0
  89. package/dist/src/hooks/_use-singleton.d.ts.map +1 -0
  90. package/dist/src/hooks/_use-singleton.js +26 -0
  91. package/dist/src/hooks/use-action-data.d.ts +17 -0
  92. package/dist/src/hooks/use-action-data.d.ts.map +1 -0
  93. package/dist/src/hooks/use-action-data.js +16 -0
  94. package/dist/src/hooks/use-form-action.d.ts +7 -0
  95. package/dist/src/hooks/use-form-action.d.ts.map +1 -0
  96. package/dist/src/hooks/use-form-action.js +9 -0
  97. package/dist/src/hooks/use-loader-data.d.ts +9 -0
  98. package/dist/src/hooks/use-loader-data.d.ts.map +1 -0
  99. package/dist/src/hooks/use-loader-data.js +20 -0
  100. package/dist/src/hooks/use-navigate.d.ts +53 -0
  101. package/dist/src/hooks/use-navigate.d.ts.map +1 -0
  102. package/dist/src/hooks/use-navigate.js +43 -0
  103. package/dist/{hooks → src/hooks}/use-params.d.ts +2 -2
  104. package/dist/src/hooks/use-params.d.ts.map +1 -0
  105. package/dist/{hooks → src/hooks}/use-params.js +1 -1
  106. package/dist/src/hooks/use-route-context.d.ts +10 -0
  107. package/dist/src/hooks/use-route-context.d.ts.map +1 -0
  108. package/dist/src/hooks/use-route-context.js +17 -0
  109. package/dist/src/hooks/use-router-context.d.ts +12 -0
  110. package/dist/src/hooks/use-router-context.d.ts.map +1 -0
  111. package/dist/src/hooks/use-router-context.js +20 -0
  112. package/dist/src/hooks/use-submit.d.ts +59 -0
  113. package/dist/src/hooks/use-submit.d.ts.map +1 -0
  114. package/dist/src/hooks/use-submit.js +38 -0
  115. package/dist/src/soseki.d.ts +31 -0
  116. package/dist/src/soseki.d.ts.map +1 -0
  117. package/dist/src/soseki.js +12 -0
  118. package/dist/src/utils/redirect.d.ts +11 -0
  119. package/dist/src/utils/redirect.d.ts.map +1 -0
  120. package/dist/src/utils/redirect.js +12 -0
  121. package/package.json +48 -30
  122. package/src/components/browser-router.tsx +8 -11
  123. package/src/components/outlet.tsx +3 -2
  124. package/src/components/router.tsx +139 -145
  125. package/src/contexts/route-context.ts +6 -5
  126. package/src/contexts/router-context.ts +36 -19
  127. package/src/core/_compare-route-paths.ts +48 -34
  128. package/src/core/_match-route-path.ts +21 -15
  129. package/src/core/_process-routes.ts +44 -46
  130. package/src/core/_singleton.ts +13 -38
  131. package/src/core/_unreachable.ts +12 -7
  132. package/src/core/_valibot.ts +19 -116
  133. package/src/core/errors.ts +150 -495
  134. package/src/core/expect-history-entry.ts +40 -41
  135. package/src/core/form-data-to-html-form-element.ts +37 -0
  136. package/src/core/history-entry-id-schema.ts +6 -11
  137. package/src/core/history-entry-url-schema.ts +25 -18
  138. package/src/core/init-loaders.ts +35 -57
  139. package/src/core/match-routes.ts +33 -65
  140. package/src/core/readonly-form-data.types.ts +48 -28
  141. package/src/core/readonly-url.types.ts +57 -28
  142. package/src/core/redirect-response.ts +26 -15
  143. package/src/core/route-path.ts +114 -0
  144. package/src/core/route-request.ts +144 -32
  145. package/src/core/route.types.ts +250 -226
  146. package/src/core/start-action.ts +164 -0
  147. package/src/core/start-loaders.ts +190 -212
  148. package/src/core.ts +8 -15
  149. package/src/engines/engine.types.ts +204 -166
  150. package/src/engines/navigation-api-engine.ts +332 -233
  151. package/src/engines.ts +4 -0
  152. package/src/hooks/_use-singleton.ts +30 -0
  153. package/src/hooks/use-action-data.ts +21 -26
  154. package/src/hooks/use-form-action.ts +4 -5
  155. package/src/hooks/use-loader-data.ts +16 -18
  156. package/src/hooks/use-navigate.ts +69 -28
  157. package/src/hooks/use-params.ts +4 -4
  158. package/src/hooks/use-route-context.ts +20 -0
  159. package/src/hooks/use-router-context.ts +25 -0
  160. package/src/hooks/use-submit.ts +48 -53
  161. package/src/soseki.ts +27 -34
  162. package/src/utils/redirect.ts +5 -5
  163. package/dist/components/action-id.d.ts +0 -19
  164. package/dist/components/action-id.d.ts.map +0 -1
  165. package/dist/components/action-id.jsx +0 -14
  166. package/dist/components/browser-router.d.ts +0 -17
  167. package/dist/components/browser-router.d.ts.map +0 -1
  168. package/dist/components/browser-router.jsx +0 -13
  169. package/dist/components/hidden-input.d.ts +0 -20
  170. package/dist/components/hidden-input.d.ts.map +0 -1
  171. package/dist/components/hidden-input.jsx +0 -8
  172. package/dist/components/outlet.d.ts +0 -8
  173. package/dist/components/outlet.d.ts.map +0 -1
  174. package/dist/components/outlet.jsx +0 -15
  175. package/dist/components/router.d.ts +0 -23
  176. package/dist/components/router.d.ts.map +0 -1
  177. package/dist/components/router.jsx +0 -128
  178. package/dist/contexts/route-context.d.ts +0 -19
  179. package/dist/contexts/route-context.d.ts.map +0 -1
  180. package/dist/contexts/route-context.js +0 -6
  181. package/dist/contexts/router-context.d.ts +0 -46
  182. package/dist/contexts/router-context.d.ts.map +0 -1
  183. package/dist/contexts/router-context.js +0 -8
  184. package/dist/core/_action-id-registry.d.ts +0 -10
  185. package/dist/core/_action-id-registry.d.ts.map +0 -1
  186. package/dist/core/_action-id-registry.js +0 -8
  187. package/dist/core/_capture-stack-trace.d.ts +0 -8
  188. package/dist/core/_capture-stack-trace.d.ts.map +0 -1
  189. package/dist/core/_capture-stack-trace.js +0 -12
  190. package/dist/core/_compare-route-paths.d.ts +0 -11
  191. package/dist/core/_compare-route-paths.d.ts.map +0 -1
  192. package/dist/core/_compare-route-paths.js +0 -80
  193. package/dist/core/_create-html-form-element-form-form-data.d.ts +0 -9
  194. package/dist/core/_create-html-form-element-form-form-data.d.ts.map +0 -1
  195. package/dist/core/_create-html-form-element-form-form-data.js +0 -27
  196. package/dist/core/_encode-pathname.d.ts +0 -10
  197. package/dist/core/_encode-pathname.d.ts.map +0 -1
  198. package/dist/core/_encode-pathname.js +0 -16
  199. package/dist/core/_is-error.d.ts +0 -3
  200. package/dist/core/_is-error.d.ts.map +0 -1
  201. package/dist/core/_is-error.js +0 -13
  202. package/dist/core/_is-promise-like.d.ts +0 -8
  203. package/dist/core/_is-promise-like.d.ts.map +0 -1
  204. package/dist/core/_is-promise-like.js +0 -12
  205. package/dist/core/_match-route-path.d.ts +0 -19
  206. package/dist/core/_match-route-path.d.ts.map +0 -1
  207. package/dist/core/_match-route-path.js +0 -22
  208. package/dist/core/_process-routes.d.ts +0 -9
  209. package/dist/core/_process-routes.d.ts.map +0 -1
  210. package/dist/core/_process-routes.js +0 -47
  211. package/dist/core/_singleton.d.ts +0 -18
  212. package/dist/core/_singleton.d.ts.map +0 -1
  213. package/dist/core/_singleton.js +0 -37
  214. package/dist/core/_unreachable.d.ts +0 -12
  215. package/dist/core/_unreachable.d.ts.map +0 -1
  216. package/dist/core/_unreachable.js +0 -8
  217. package/dist/core/_use-singleton.d.ts +0 -11
  218. package/dist/core/_use-singleton.d.ts.map +0 -1
  219. package/dist/core/_use-singleton.js +0 -21
  220. package/dist/core/_valibot.d.ts +0 -52
  221. package/dist/core/_valibot.d.ts.map +0 -1
  222. package/dist/core/_valibot.js +0 -107
  223. package/dist/core/_weak-id-registry.d.ts +0 -76
  224. package/dist/core/_weak-id-registry.d.ts.map +0 -1
  225. package/dist/core/_weak-id-registry.js +0 -67
  226. package/dist/core/constants.d.ts +0 -5
  227. package/dist/core/constants.d.ts.map +0 -1
  228. package/dist/core/constants.js +0 -4
  229. package/dist/core/data-map.types.d.ts +0 -23
  230. package/dist/core/data-map.types.d.ts.map +0 -1
  231. package/dist/core/data-map.types.js +0 -1
  232. package/dist/core/data-store.types.d.ts +0 -22
  233. package/dist/core/data-store.types.d.ts.map +0 -1
  234. package/dist/core/data-store.types.js +0 -1
  235. package/dist/core/deferred-promise.d.ts +0 -203
  236. package/dist/core/deferred-promise.d.ts.map +0 -1
  237. package/dist/core/deferred-promise.js +0 -200
  238. package/dist/core/errors.d.ts +0 -303
  239. package/dist/core/errors.d.ts.map +0 -1
  240. package/dist/core/errors.js +0 -400
  241. package/dist/core/expect-history-entry.d.ts +0 -52
  242. package/dist/core/expect-history-entry.d.ts.map +0 -1
  243. package/dist/core/expect-history-entry.js +0 -38
  244. package/dist/core/history-entry-id-schema.d.ts +0 -17
  245. package/dist/core/history-entry-id-schema.d.ts.map +0 -1
  246. package/dist/core/history-entry-id-schema.js +0 -9
  247. package/dist/core/history-entry-url-schema.d.ts +0 -20
  248. package/dist/core/history-entry-url-schema.d.ts.map +0 -1
  249. package/dist/core/history-entry-url-schema.js +0 -16
  250. package/dist/core/init-loaders.d.ts +0 -37
  251. package/dist/core/init-loaders.d.ts.map +0 -1
  252. package/dist/core/init-loaders.js +0 -38
  253. package/dist/core/match-routes.d.ts +0 -31
  254. package/dist/core/match-routes.d.ts.map +0 -1
  255. package/dist/core/match-routes.js +0 -54
  256. package/dist/core/readonly-form-data.types.d.ts +0 -32
  257. package/dist/core/readonly-form-data.types.d.ts.map +0 -1
  258. package/dist/core/readonly-url.types.d.ts +0 -135
  259. package/dist/core/readonly-url.types.d.ts.map +0 -1
  260. package/dist/core/redirect-response.d.ts +0 -29
  261. package/dist/core/redirect-response.d.ts.map +0 -1
  262. package/dist/core/redirect-response.js +0 -17
  263. package/dist/core/route-request.d.ts +0 -52
  264. package/dist/core/route-request.d.ts.map +0 -1
  265. package/dist/core/route-request.js +0 -26
  266. package/dist/core/route.types.d.ts +0 -309
  267. package/dist/core/route.types.d.ts.map +0 -1
  268. package/dist/core/start-actions.d.ts +0 -60
  269. package/dist/core/start-actions.d.ts.map +0 -1
  270. package/dist/core/start-actions.js +0 -186
  271. package/dist/core/start-loaders.d.ts +0 -69
  272. package/dist/core/start-loaders.d.ts.map +0 -1
  273. package/dist/core/start-loaders.js +0 -154
  274. package/dist/core.d.ts.map +0 -1
  275. package/dist/engines/engine.types.d.ts +0 -190
  276. package/dist/engines/engine.types.d.ts.map +0 -1
  277. package/dist/engines/navigation-api-engine.d.ts +0 -48
  278. package/dist/engines/navigation-api-engine.d.ts.map +0 -1
  279. package/dist/engines/navigation-api-engine.js +0 -332
  280. package/dist/hooks/_use-route-context.d.ts +0 -10
  281. package/dist/hooks/_use-route-context.d.ts.map +0 -1
  282. package/dist/hooks/_use-route-context.js +0 -17
  283. package/dist/hooks/_use-router-context.d.ts +0 -10
  284. package/dist/hooks/_use-router-context.d.ts.map +0 -1
  285. package/dist/hooks/_use-router-context.js +0 -18
  286. package/dist/hooks/use-action-data.d.ts +0 -23
  287. package/dist/hooks/use-action-data.d.ts.map +0 -1
  288. package/dist/hooks/use-action-data.js +0 -16
  289. package/dist/hooks/use-form-action.d.ts +0 -7
  290. package/dist/hooks/use-form-action.d.ts.map +0 -1
  291. package/dist/hooks/use-form-action.js +0 -10
  292. package/dist/hooks/use-loader-data.d.ts +0 -11
  293. package/dist/hooks/use-loader-data.d.ts.map +0 -1
  294. package/dist/hooks/use-loader-data.js +0 -19
  295. package/dist/hooks/use-navigate.d.ts +0 -39
  296. package/dist/hooks/use-navigate.d.ts.map +0 -1
  297. package/dist/hooks/use-navigate.js +0 -26
  298. package/dist/hooks/use-params.d.ts.map +0 -1
  299. package/dist/hooks/use-pathname.d.ts +0 -7
  300. package/dist/hooks/use-pathname.d.ts.map +0 -1
  301. package/dist/hooks/use-pathname.js +0 -9
  302. package/dist/hooks/use-submit.d.ts +0 -66
  303. package/dist/hooks/use-submit.d.ts.map +0 -1
  304. package/dist/hooks/use-submit.js +0 -35
  305. package/dist/soseki.d.ts +0 -42
  306. package/dist/soseki.d.ts.map +0 -1
  307. package/dist/soseki.js +0 -19
  308. package/dist/utils/get-action-id.d.ts +0 -8
  309. package/dist/utils/get-action-id.d.ts.map +0 -1
  310. package/dist/utils/get-action-id.js +0 -11
  311. package/dist/utils/href.d.ts +0 -11
  312. package/dist/utils/href.d.ts.map +0 -1
  313. package/dist/utils/href.js +0 -12
  314. package/dist/utils/redirect.d.ts +0 -11
  315. package/dist/utils/redirect.d.ts.map +0 -1
  316. package/dist/utils/redirect.js +0 -12
  317. package/dist/utils/route-index.d.ts +0 -41
  318. package/dist/utils/route-index.d.ts.map +0 -1
  319. package/dist/utils/route-index.js +0 -12
  320. package/dist/utils/route-route.d.ts +0 -62
  321. package/dist/utils/route-route.d.ts.map +0 -1
  322. package/dist/utils/route-route.js +0 -25
  323. package/dist/utils/set-action-id.d.ts +0 -9
  324. package/dist/utils/set-action-id.d.ts.map +0 -1
  325. package/dist/utils/set-action-id.js +0 -12
  326. package/src/components/action-id.tsx +0 -35
  327. package/src/components/hidden-input.tsx +0 -39
  328. package/src/core/_action-id-registry.ts +0 -11
  329. package/src/core/_capture-stack-trace.ts +0 -12
  330. package/src/core/_create-html-form-element-form-form-data.ts +0 -32
  331. package/src/core/_encode-pathname.ts +0 -17
  332. package/src/core/_is-error.ts +0 -16
  333. package/src/core/_is-promise-like.ts +0 -14
  334. package/src/core/_use-singleton.ts +0 -24
  335. package/src/core/_weak-id-registry.ts +0 -125
  336. package/src/core/constants.ts +0 -4
  337. package/src/core/data-map.types.ts +0 -28
  338. package/src/core/data-store.types.ts +0 -25
  339. package/src/core/deferred-promise.ts +0 -408
  340. package/src/core/start-actions.ts +0 -274
  341. package/src/hooks/_use-route-context.ts +0 -19
  342. package/src/hooks/_use-router-context.ts +0 -25
  343. package/src/hooks/use-pathname.ts +0 -10
  344. package/src/utils/get-action-id.ts +0 -12
  345. package/src/utils/href.ts +0 -17
  346. package/src/utils/route-index.ts +0 -70
  347. package/src/utils/route-route.ts +0 -111
  348. package/src/utils/set-action-id.ts +0 -14
  349. /package/dist/{core → src/core}/readonly-form-data.types.js +0 -0
  350. /package/dist/{core → src/core}/readonly-url.types.js +0 -0
  351. /package/dist/{core → src/core}/route.types.js +0 -0
  352. /package/dist/{engines → src/engines}/engine.types.js +0 -0
@@ -1,216 +1,254 @@
1
- import type { IDataStore } from "../core/data-store.types.js";
1
+ import type { NinjaPromise } from "ninja-promise";
2
+
2
3
  import type { HistoryEntry } from "../core/expect-history-entry.js";
4
+ import type { HistoryEntryId } from "../core/history-entry-id-schema.js";
3
5
  import type { MatchedRoute } from "../core/match-routes.js";
4
6
  import type { ReadonlyFormData } from "../core/readonly-form-data.types.js";
5
7
  import type { ReadonlyURLSearchParams } from "../core/readonly-url.types.js";
6
- import type { IAction, ILoader, Route } from "../core/route.types.js";
8
+ import type { Route, ActionFunction, LoaderFunction } from "../core/route.types.js";
7
9
 
8
10
  /**
9
- * ルーターの初期状態を生成する際に必要な引数の型定義です。
10
- */
11
- export type InitEngineArgs = {
12
- /**
13
- * 前処理済みのルート定義の配列です。
14
- */
15
- readonly routes: readonly Route[];
16
-
17
- /**
18
- * 現在の非同期処理を中断するためのシグナルを取得する関数です。
19
- */
20
- readonly getSignal: () => AbortSignal;
21
-
22
- /**
23
- * ロケーション ID ごとに管理されているローダーデータのマップです。
24
- */
25
- readonly loaderDataStore: IDataStore<ILoader>;
26
- };
27
-
28
- /**
29
- * ルーターの現在の状態を表す型定義です。
11
+ * ルーターが管理する現在の画面の状態を表す型定義です。
30
12
  */
31
13
  export type RouterState = {
32
14
  /**
33
- * 現在のロケーションエントリー情報です。
15
+ * 現在のアクティブな履歴エントリーです。
34
16
  */
35
- readonly entry: HistoryEntry;
17
+ entry: HistoryEntry;
36
18
 
37
19
  /**
38
- * 現在の URL にマッチしたルートの階層構造です。
39
- *
40
- * 最低でも 1 つのマッチしたルートが含まれるタプル形式となります。
20
+ * 現在の URL にマッチしている子から親までの階層的なルートの配列です。
41
21
  */
42
- readonly routes: readonly [MatchedRoute, ...MatchedRoute[]];
22
+ routes: readonly [MatchedRoute, ...MatchedRoute[]];
43
23
  };
44
24
 
45
25
  /**
46
- * ルーターの状態を更新するための関数インターフェースです。
47
- */
48
- export interface IUpdateRouter {
49
- /**
50
- * システムの状態を更新します。
51
- */
52
- (): void;
53
-
54
- /**
55
- * 新しいルーターの状態を受け取り、システムの状態を更新します。
56
- *
57
- * @param state 新しいルーターの状態オブジェクトです。
58
- */
59
- (state: RouterState | null): void;
60
- }
61
-
62
- /**
63
- * ルーターエンジンを開始する際に必要な引数の型定義です。
64
- */
65
- export type StartEngineArgs = {
66
- /**
67
- * 前処理済みのルート定義の配列です。
68
- */
69
- readonly routes: readonly Route[];
70
-
71
- /**
72
- * 状態を更新するためのセッター関数です。
73
- */
74
- readonly update: IUpdateRouter;
75
-
76
- /**
77
- * 現在の非同期処理を中断するためのシグナルを取得する関数です。
78
- */
79
- readonly getSignal: () => AbortSignal;
80
-
81
- /**
82
- * ロケーション ID ごとに管理されているアクションデータのマップです。
83
- */
84
- readonly actionDataStore: IDataStore<IAction>;
85
-
86
- /**
87
- * ロケーション ID ごとに管理されているローダーデータのマップです。
88
- */
89
- readonly loaderDataStore: IDataStore<ILoader>;
90
- };
91
-
92
- /**
93
- * エンジンの動作を停止するための関数インターフェースです。
26
+ * 実行中のルーティングエンジンを安全に停止させ、各種イベントリスナーや非同期処理をクリーンアップするための関数インターフェースです。
94
27
  */
95
28
  export interface IStopEngine {
96
- /**
97
- * 実行中のエンジンを停止し、イベントリスナーの解除などのクリーンアップを行います。
98
- */
99
29
  (): void;
100
30
  }
101
31
 
102
32
  /**
103
- * 送信処理に渡される引数の型定義です。
33
+ * ルーティングエンジンに関わる各種引数や戻り値の型をまとめた名前空間です。
104
34
  */
105
- export type SubmitArgs = {
35
+ export namespace IEngine {
106
36
  /**
107
- * 送信対象となるフォームデータです。
37
+ * ルーター初期化メソッド `init` に渡される引数の型定義です。
108
38
  */
109
- readonly target: ReadonlyFormData;
39
+ export type InitArgs = {
40
+ /**
41
+ * アプリケーションに登録されているすべての正規化済みルートの定義配列です。
42
+ */
43
+ routes: readonly Route[];
110
44
 
111
- /**
112
- * 送信先のパスです。
113
- */
114
- readonly action: string;
45
+ /**
46
+ * 各履歴エントリーに紐づくローダーの非同期状態を多重管理する、共有データストアへの参照です。
47
+ */
48
+ loaderDataStore: Map<HistoryEntryId, Map<LoaderFunction, NinjaPromise<unknown>>>;
115
49
 
116
- /**
117
- * 実行するアクションの定義です。
118
- */
119
- readonly actionId: IAction | undefined;
120
- } | {
121
- /**
122
- * 送信対象となる URL クエリーパラメーターです。
123
- */
124
- readonly target: ReadonlyURLSearchParams;
50
+ /**
51
+ * 中断シグナルを取得します。
52
+ */
53
+ getSignal: () => AbortSignal;
54
+ };
125
55
 
126
56
  /**
127
- * 送信先のパスです。
128
- */
129
- readonly action: string;
130
-
131
- /**
132
- * 履歴の追加方法を指定します。
57
+ * ルーター初期化メソッド `init` が返す初期状態の型定義です。
133
58
  *
134
- * "replace" は現在のエントリーを置き換え、"push" は新しいエントリーを追加します。
135
- */
136
- readonly history: "replace" | "push";
137
- };
138
-
139
- /**
140
- * ナビゲーションの移動先を示す型定義です。
141
- *
142
- * パス文字列または詳細なパス情報のオブジェクトを受け取ります。
143
- */
144
- export type NavigateTo = string | {
145
- /**
146
- * URL のパス名を表します。
147
- */
148
- readonly pathname?: string | undefined;
149
-
150
- /**
151
- * URL のクエリーパラメーターを表します。
59
+ * マッチするルートがあればその状態を返し、なければ `null` となります。
152
60
  */
153
- readonly search?: string | undefined;
61
+ export type InitReturn = RouterState | null;
154
62
 
155
63
  /**
156
- * URL のハッシュフラグメントを表します。
157
- */
158
- readonly hash?: string | undefined;
159
- };
160
-
161
- /**
162
- * エンジンの遷移関数に渡される引数の型定義です。
163
- */
164
- export type NavigateArgs = {
165
- /**
166
- * 遷移先です。
167
- */
168
- readonly to: NavigateTo;
169
-
170
- /**
171
- * 履歴の追加方法を指定します。
64
+ * エンジンの稼働開始メソッド `start` に渡される引数の型定義です。
172
65
  *
173
- * "replace" は現在のエントリーを置き換え、"push" は新しいエントリーを追加します。
174
- */
175
- readonly history: "replace" | "push";
176
- } | {
177
- /**
178
- * 履歴スタックの相対位置です。
179
- */
180
- readonly delta: number;
181
- };
66
+ * ナビゲーションイベントの監視や状態同期に必要な依存関係を集約します。
67
+ */
68
+ export type StartArgs = {
69
+ /**
70
+ * アプリケーションに登録されているすべての正規化済みルートの定義配列です。
71
+ */
72
+ routes: readonly Route[];
73
+
74
+ /**
75
+ * 各履歴エントリーに紐づくアクションの非同期状態を保持する共有データストアです。
76
+ */
77
+ actionDataStore: Map<HistoryEntryId, Map<ActionFunction, NinjaPromise<unknown>>>;
78
+
79
+ /**
80
+ * 各履歴エントリーに紐づくローダーの非同期状態を保持する共有データストアです。
81
+ */
82
+ loaderDataStore: Map<HistoryEntryId, Map<LoaderFunction, NinjaPromise<unknown>>>;
83
+
84
+ /**
85
+ * エンジン内部で遷移が確定した際、新しい状態を Reactに通知して画面の再描画を要求するための更新関数です。
86
+ *
87
+ * 引数なしの呼び出しは、現在の状態を維持したままの強制再レンダリングを意味します。
88
+ */
89
+ update: {
90
+ /**
91
+ * 現在の状態を維持したまま強制的に再レンダリングします。
92
+ */
93
+ (): void;
94
+
95
+ /**
96
+ * ルーターの状態を更新します。
97
+ *
98
+ * @param newRouterState 新しいルーターの状態です。
99
+ */
100
+ (newRouterState: RouterState | null): void;
101
+ };
102
+
103
+ /**
104
+ * 中断シグナルを取得します。
105
+ */
106
+ getSignal: () => AbortSignal;
107
+ };
108
+
109
+ /**
110
+ * エンジンの稼働開始メソッド `start` の戻り値です。
111
+ *
112
+ * 監視イベントのリスナーを解除するためのクリーンアップ関数を返すか、環境によって何も返さない場合があります。
113
+ */
114
+ export type StartReturn = IStopEngine | void;
115
+
116
+ /**
117
+ * プログラムからのフォーム送信やクエリー更新を行う `submit` メソッドの引数の型定義です。
118
+ */
119
+ export type SubmitArgs =
120
+ | {
121
+ /**
122
+ * HTTP POST メソッドに相当する、マルチパートまたは URL エンコードされたフォームデータの送信です。
123
+ */
124
+ type: "FORM_DATA";
125
+
126
+ /**
127
+ * 送信する不変のフォームデータ本体です。
128
+ */
129
+ target: ReadonlyFormData;
130
+
131
+ /**
132
+ * アクションの送信先となる対象の URL パス文字列です。
133
+ */
134
+ action: string;
135
+ }
136
+ | {
137
+ /**
138
+ * HTTP GET メソッドに相当する、URL の検索クエリーの更新送信です。
139
+ */
140
+ type: "URL_SEARCH_PARAMS";
141
+
142
+ /**
143
+ * 更新対象となる検索クエリーパラメータです。
144
+ */
145
+ target: ReadonlyURLSearchParams;
146
+
147
+ /**
148
+ * クエリーの付与先となる対象の URL パス文字列です。
149
+ */
150
+ action: string;
151
+
152
+ /**
153
+ * 履歴スタックへの追加方法を指定します。
154
+ *
155
+ * - `"push"`: 履歴エントリーの新規追加
156
+ * - `"replace"`: 履歴エントリーの上書き
157
+ */
158
+ history: "replace" | "push";
159
+ };
160
+
161
+ /**
162
+ * 命令的な画面遷移を行う `navigate` メソッドの引数の型定義です。
163
+ *
164
+ * リンクをクリックした際のアドレス遷移か、ブラウザーの「戻る・進む」に相当する相対移動かで分岐します。
165
+ */
166
+ export type NavigateArgs =
167
+ | {
168
+ /**
169
+ * 明示的なアドレス指定による前方移動です。
170
+ */
171
+ type: "LINK";
172
+
173
+ /**
174
+ * 遷移先のアドレス表現の指定です。完全なパス文字列か、部分的なパーツの組み合わせかを選択します。
175
+ */
176
+ to:
177
+ | {
178
+ /**
179
+ * URL パスで前方移動する形式です。
180
+ */
181
+ type: "PATH";
182
+
183
+ /**
184
+ * URL パスです。
185
+ */
186
+ path: string;
187
+ }
188
+ | {
189
+ /**
190
+ * URL の各コンポーネントを個別に指定する形式です。
191
+ */
192
+ type: "PARTIAL";
193
+
194
+ /**
195
+ * 最初のスラッシュ `/` から始まる URL のパス部分です。
196
+ */
197
+ pathname?: string | undefined;
198
+
199
+ /**
200
+ * 先頭のクエスチョンマーク `?` を含む URL のクエリー文字列です。
201
+ */
202
+ search?: string | undefined;
203
+
204
+ /**
205
+ * URL のハッシュ(シャープ記号 `#` を含むフラグメント識別子)です。
206
+ */
207
+ hash?: string | undefined;
208
+ };
209
+
210
+ /**
211
+ * 履歴スタックへの追加方法を指定します。
212
+ *
213
+ * - `"push"`: 履歴エントリーの新規追加
214
+ * - `"replace"`: 履歴エントリーの上書き
215
+ */
216
+ history: "replace" | "push";
217
+ }
218
+ | {
219
+ /**
220
+ * 履歴スタック内の相対的な位置移動(例: `-1` で1つ戻る、`2` で2つ進む)です。
221
+ */
222
+ type: "MOVE";
223
+
224
+ /**
225
+ * 履歴を移動させる差分ステップ数です。
226
+ */
227
+ delta: number;
228
+ };
229
+ }
182
230
 
183
231
  /**
184
- * ルーティングの基幹処理を担うエンジンのインターフェースです。
232
+ * ルーティングエンジンのインターフェース定義です。
185
233
  */
186
234
  export interface IEngine {
187
235
  /**
188
- * 与えられた引数に基づいて、ルーターを初期化します。
189
- *
190
- * @param args 状態生成に必要なルート情報やデータマップです。
191
- * @returns 生成されたルーター状態、またはマッチしなかった場合は `null` を返します。
236
+ * 現在の URL を基にルーターの初期状態を計算し、同期的に取得します。
192
237
  */
193
- init(args: InitEngineArgs): RouterState | null;
238
+ init(args: IEngine.InitArgs): IEngine.InitReturn;
194
239
 
195
240
  /**
196
- * エンジンの動作を開始します。履歴の変化の監視などを開始します。
197
- *
198
- * @param args エンジンの開始に必要な設定とコールバック関数です。
199
- * @returns エンジンを停止するための関数を返します。停止処理が不要な場合は何も返しません。
241
+ * エンジンを稼働させ、ブラウザーの履歴変更やナビゲーションイベントの継続的な監視を開始します。
200
242
  */
201
- start(args: StartEngineArgs): IStopEngine | void;
243
+ start(args: IEngine.StartArgs): IEngine.StartReturn;
202
244
 
203
245
  /**
204
- * フォームデータやクエリーパラメーターを送信します。
205
- *
206
- * @param args 送信内容と送信先を含む引数です。
246
+ * ユーザーからの意図的なフォームデータまたはクエリーパラメータの送信を検知し、対応するルートのアクションやローダーを起動します。
207
247
  */
208
- submit(args: SubmitArgs): void;
248
+ submit(args: IEngine.SubmitArgs): void;
209
249
 
210
250
  /**
211
- * 指定されたパスへ遷移します。
212
- *
213
- * @param args 遷移先と遷移オプションを含む引数です。
251
+ * プログラムからの命令的なページ遷移を処理します。
214
252
  */
215
- navigate(args: NavigateArgs): void;
253
+ navigate(args: IEngine.NavigateArgs): void;
216
254
  }