soseki 0.0.5 → 0.0.7

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 +47 -40
  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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026-present, tai-kun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ import type { RouteDefinition } from "../core/route.types.js";
2
+ /**
3
+ * `BrowserRouter` コンポーネントに引き渡すプロパティーの型定義です。
4
+ */
5
+ export type BrowserRouterProps = {
6
+ /**
7
+ * アプリケーション全体の画面構造を定義したルート定義の配列です。
8
+ */
9
+ routes: readonly RouteDefinition[];
10
+ };
11
+ /**
12
+ * ブラウザー環境における SPA ルーティングを開始するための、最上位エントリーポイントコンポーネントです。
13
+ *
14
+ * モダンなブラウザー標準の `Navigation API` に依存しています。
15
+ *
16
+ * @param props アプリケーションに組み込むルート定義の配列です。
17
+ */
18
+ export default function BrowserRouter(props: BrowserRouterProps): React.ReactElement;
19
+ //# sourceMappingURL=browser-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-router.d.ts","sourceRoot":"","sources":["../../../src/components/browser-router.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK9D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,KAAK,CAAC,YAAY,CAKnF"}
@@ -0,0 +1,15 @@
1
+ import NavigationApiEngine from "../engines/navigation-api-engine.js";
2
+ import useSingleton from "../hooks/_use-singleton.js";
3
+ import Router from "./router.jsx";
4
+ /**
5
+ * ブラウザー環境における SPA ルーティングを開始するための、最上位エントリーポイントコンポーネントです。
6
+ *
7
+ * モダンなブラウザー標準の `Navigation API` に依存しています。
8
+ *
9
+ * @param props アプリケーションに組み込むルート定義の配列です。
10
+ */
11
+ export default function BrowserRouter(props) {
12
+ const { routes } = props;
13
+ const engine = useSingleton(() => new NavigationApiEngine());
14
+ return <Router engine={engine} routes={routes}/>;
15
+ }
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ /**
3
+ * ネストされたルーティング構造において、親ルートのレイアウト内にマッチした子ルートを適切な位置にはめ込んで描画するためのプレースホルダーコンポーネントです。
4
+ *
5
+ * @returns 描画すべき子ルートの React 要素を返します。これ以上下位のルートがない場合は `null` を返します。
6
+ */
7
+ export default function Outlet(): React.ReactElement | null;
8
+ //# sourceMappingURL=outlet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outlet.d.ts","sourceRoot":"","sources":["../../../src/components/outlet.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,KAAK,CAAC,YAAY,GAAG,IAAI,CAO1D"}
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ import RouteContext from "../contexts/route-context.js";
3
+ import { RouteContextMissingError } from "../core/errors.js";
4
+ /**
5
+ * ネストされたルーティング構造において、親ルートのレイアウト内にマッチした子ルートを適切な位置にはめ込んで描画するためのプレースホルダーコンポーネントです。
6
+ *
7
+ * @returns 描画すべき子ルートの React 要素を返します。これ以上下位のルートがない場合は `null` を返します。
8
+ */
9
+ export default function Outlet() {
10
+ const routeContext = React.use(RouteContext);
11
+ if (!routeContext) {
12
+ throw new RouteContextMissingError();
13
+ }
14
+ return routeContext.outlet;
15
+ }
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ import type { RouteDefinition } from "../core/route.types.js";
3
+ import type { IEngine } from "../engines/engine.types.js";
4
+ /**
5
+ * `Router` コンポーネントに渡されるルートプロパティーの型定義です。
6
+ */
7
+ export type RouterProps = {
8
+ /**
9
+ * プラグイン形式で差し込まれる、ルーティングの実装です。
10
+ */
11
+ engine: IEngine;
12
+ /**
13
+ * ユーザーがアプリケーションに定義したルート定義の配列です。
14
+ */
15
+ routes: readonly RouteDefinition[];
16
+ };
17
+ /**
18
+ * 宣言的なルート定義と、命令的なルーティング実行エンジンを仲介・統合し、アプリケーションの最上位でルーティングのライフサイクルと状態管理を司るプロバイダーコンポーネントです。
19
+ */
20
+ export default function Router(props: RouterProps): React.JSX.Element | null;
21
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/components/router.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAW/B,OAAO,KAAK,EAAkC,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,KAAK,EAAE,OAAO,EAAe,MAAM,4BAA4B,CAAC;AAkEvE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,4BAkIhD"}
@@ -0,0 +1,138 @@
1
+ import * as React from "react";
2
+ import RouteContext from "../contexts/route-context.js";
3
+ import RouterContext from "../contexts/router-context.js";
4
+ import processRoutes from "../core/_process-routes.js";
5
+ /**
6
+ * マッチした個々のルートコンポーネントを、固有の `RouteContext` で包み込みながら再帰的にマウント・展開していくための内部レンダラーコンポーネントです。
7
+ */
8
+ function ComponentRenderer(props) {
9
+ const parentRoute = React.use(RouteContext);
10
+ const { route, outlet } = props;
11
+ const context = {
12
+ ...route,
13
+ outlet,
14
+ // 親ルートのアクションとローダーを引き継ぐことで、`useActionData` と `useLoaderData` がデータを参照できようにします。
15
+ action: route.action ?? parentRoute?.action,
16
+ loader: route.loader ?? parentRoute?.loader,
17
+ };
18
+ const Comp = route.component;
19
+ return (<RouteContext value={context}>{typeof Comp === "function" ? <Comp /> : outlet}</RouteContext>);
20
+ }
21
+ /**
22
+ * マッチしたルート配列を親から子の順番へと正しく巡回し、各階層を入れ子状の React エレメントツリーへと再帰的にビルドするコンポーネントです。
23
+ */
24
+ function RouteRenderer(props) {
25
+ const { index = 0, routes } = props;
26
+ const route = routes[index];
27
+ // 配列の終端に達していない場合はインデックスを 1 進めて自身を再帰的に呼び出し、ネストされる子要素を生成します。
28
+ const outlet = index < routes.length - 1 ? <RouteRenderer routes={routes} index={index + 1}/> : null;
29
+ return <ComponentRenderer route={route} outlet={outlet}/>;
30
+ }
31
+ /**
32
+ * 宣言的なルート定義と、命令的なルーティング実行エンジンを仲介・統合し、アプリケーションの最上位でルーティングのライフサイクルと状態管理を司るプロバイダーコンポーネントです。
33
+ */
34
+ export default function Router(props) {
35
+ const { engine, routes: routesProp } = props;
36
+ // レンダリングを跨いで常に同一参照を維持し、かつ子コンポーネントから不要な再レンダリングなしでメソッドを叩けるように、ルーターコアの外部参照実体を useRef で永続管理します。
37
+ const routerRef = React.useRef({});
38
+ // エンジン、ストア、イベント購読メカニズムのセットアップを一元化し、useMemo でインスタンス化します。
39
+ const router = React.useMemo(() => {
40
+ const actionDataStore = new Map();
41
+ const loaderDataStore = new Map();
42
+ const subscribers = new Set();
43
+ const routes = processRoutes(routesProp);
44
+ let ac = null;
45
+ /**
46
+ * 現在のフェーズで有効な、シングルトン構造の中断シグナルをオンデマンドで生成・回収します。
47
+ */
48
+ function getAbortSignal() {
49
+ return (ac || (ac = new AbortController())).signal;
50
+ }
51
+ // エンジンを初期化し、初期ロード時のマッチングルートおよび解決済みのデータマップを取得・登録します。
52
+ const initialState = engine.init({
53
+ routes,
54
+ getSignal: getAbortSignal,
55
+ loaderDataStore,
56
+ });
57
+ let currentRoutes = initialState?.routes;
58
+ /**
59
+ * エンジン内部での遷移確定時に、状態を React 側へ通知・マージするための状態更新関数です。
60
+ */
61
+ function updateRouter(newState) {
62
+ if (newState !== undefined) {
63
+ currentRoutes = newState?.routes;
64
+ }
65
+ if (newState) {
66
+ routerRef.current.currentEntry = newState.entry;
67
+ }
68
+ // 状態変更の発生を、React の useSyncExternalStore などのすべての購読者に一斉通知して再描画を促します。
69
+ subscribers.forEach((notify) => notify());
70
+ }
71
+ /**
72
+ * エンジンによるイベントのリアルタイム監視を開始するトリガー関数です。
73
+ */
74
+ function startRouterEngine() {
75
+ const stop = engine.start({
76
+ routes,
77
+ update: updateRouter,
78
+ getSignal: getAbortSignal,
79
+ actionDataStore,
80
+ loaderDataStore,
81
+ });
82
+ return function stopRouterEngine() {
83
+ try {
84
+ if (typeof stop === "function") {
85
+ stop();
86
+ }
87
+ }
88
+ finally {
89
+ try {
90
+ ac?.abort();
91
+ }
92
+ catch { }
93
+ ac = null;
94
+ }
95
+ };
96
+ }
97
+ // 作成した各種ストアや命令型メソッドの参照を、永続化 Ref オブジェクトへと安全にマージします。
98
+ Object.assign(routerRef.current, {
99
+ submit(args) {
100
+ return engine.submit(args);
101
+ },
102
+ navigate(args) {
103
+ return engine.navigate(args);
104
+ },
105
+ currentEntry: initialState?.entry,
106
+ actionDataStore,
107
+ loaderDataStore,
108
+ });
109
+ return {
110
+ start: startRouterEngine,
111
+ context: {
112
+ routerRef,
113
+ subscribe(cb) {
114
+ subscribers.add(cb);
115
+ return () => {
116
+ subscribers.delete(cb);
117
+ };
118
+ },
119
+ },
120
+ getRoutes() {
121
+ return currentRoutes;
122
+ },
123
+ };
124
+ }, [engine, routesProp]);
125
+ // コンポーネントのマウント時にルーターエンジンを始動させ、アンマウント時には自動的に破棄タスクを連動させます。
126
+ React.useEffect(() => router.start(), [router]);
127
+ // マッチしたルート階層配列をリアクティブに常時監視します。
128
+ const routes = React.useSyncExternalStore(router.context.subscribe, router.getRoutes);
129
+ // 有効なルートマッチングがない場合は何も描画しません。
130
+ if (!routes) {
131
+ // TODO(tai-kun): 404 Not Found ページを表示できるようにします。
132
+ return null;
133
+ }
134
+ return (<RouterContext value={router.context}>
135
+ {/* マッチルート配列は詳細度の高い「子 -> 親」の順で並んでいるため、React のネストレイアウト構造(親の中に子を入れる)に適合させるために `.toReversed()` で「親 -> 子」の順に反転させてからレンダラーへ投入します。*/}
136
+ <RouteRenderer routes={routes.toReversed()}/>
137
+ </RouterContext>);
138
+ }
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ import type { MatchedRoute } from "../core/match-routes.js";
3
+ /**
4
+ * 現在のコンポーネント階層に紐づいている個別ルートのコンテキスト形状定義です。
5
+ */
6
+ export type RouteContextValue = MatchedRoute & {
7
+ /**
8
+ * 現在のルートの下位に位置する子ルートを表示するための React 要素です。
9
+ *
10
+ * これ以上下位にマッチする子ルートが存在しない場合は `null` になります。
11
+ */
12
+ readonly outlet: React.ReactElement | null;
13
+ };
14
+ /**
15
+ * 階層的にネストされたルーターのレイアウト構造において、親ルートから子ルートへそれぞれの階層固有のルート情報伝播させるための React コンテキストです。
16
+ */
17
+ declare const RouteContext: React.Context<RouteContextValue | null>;
18
+ export default RouteContext;
19
+ //# sourceMappingURL=route-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-context.d.ts","sourceRoot":"","sources":["../../../src/contexts/route-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAC7C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,YAAY,yCAAoE,CAAC;AAEvF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ /**
3
+ * 階層的にネストされたルーターのレイアウト構造において、親ルートから子ルートへそれぞれの階層固有のルート情報伝播させるための React コンテキストです。
4
+ */
5
+ const RouteContext = /*#__PURE__*/ React.createContext(null);
6
+ export default RouteContext;
@@ -0,0 +1,55 @@
1
+ import type { NinjaPromise } from "ninja-promise";
2
+ import * as React from "react";
3
+ import type { HistoryEntry } from "../core/expect-history-entry.js";
4
+ import type { HistoryEntryId } from "../core/history-entry-id-schema.js";
5
+ import type { ActionFunction, LoaderFunction } from "../core/route.types.js";
6
+ import type { IEngine } from "../engines/engine.types.js";
7
+ /**
8
+ * ルーターの実体へのアクセスを提供する、読み取り専用の Ref オブジェクト型です。
9
+ */
10
+ export type RouterRef = Readonly<React.RefObject<{
11
+ /**
12
+ * フォームデータやクエリーパラメーターをルーターに送信するための関数です。
13
+ */
14
+ readonly submit: (args: IEngine.SubmitArgs) => void;
15
+ /**
16
+ * URL 遷移や履歴スタックの相対移動をルーターに命令するための関数です。
17
+ */
18
+ readonly navigate: (args: IEngine.NavigateArgs) => void;
19
+ /**
20
+ * 現在ブラウザー上でアクティブになっている履歴エントリーの情報です。
21
+ */
22
+ readonly currentEntry: HistoryEntry;
23
+ /**
24
+ * 履歴エントリーの ID ごとにアクションの実行状態を管理するデータストアです。
25
+ */
26
+ readonly actionDataStore: ReadonlyMap<HistoryEntryId, ReadonlyMap<ActionFunction, NinjaPromise<unknown>>>;
27
+ /**
28
+ * 履歴エントリーの ID ごとにローダーの実行状態を管理するデータストアです。
29
+ */
30
+ readonly loaderDataStore: ReadonlyMap<HistoryEntryId, ReadonlyMap<LoaderFunction, NinjaPromise<unknown>>>;
31
+ }>>;
32
+ /**
33
+ * `RouterContext` がコンポーネントツリーの配下に供給するオブジェクトの型定義です。
34
+ */
35
+ export type RouterContextValue = {
36
+ /**
37
+ * ルーターの最新実体への参照を保持する Ref オブジェクトです。
38
+ */
39
+ readonly routerRef: RouterRef;
40
+ /**
41
+ * ルーターの状態変更を監視するための購読関数です。
42
+ *
43
+ * @param onRouterChange ルーターの内部状態が変化した際に実行されるコールバック関数です。
44
+ * @returns 監視を安全に解除するためのクリーンアップ関数を返します。
45
+ */
46
+ readonly subscribe: (onRouterChange: () => void) => () => void;
47
+ };
48
+ /**
49
+ * アプリケーションの最上位からルーターのグローバル状態を子コンポーネントへ一元的に伝播させるための React コンテキストです。
50
+ *
51
+ * パフォーマンス最適化のためにプロバイダー自体は基本的に更新されず、子コンポーネントは `subscribe` と `useSyncExternalStore`を使って必要な部分データだけを購読します。
52
+ */
53
+ declare const RouterContext: React.Context<RouterContextValue | null>;
54
+ export default RouterContext;
55
+ //# sourceMappingURL=router-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router-context.d.ts","sourceRoot":"","sources":["../../../src/contexts/router-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,CAC9B,KAAK,CAAC,SAAS,CAAC;IACd;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,KAAK,IAAI,CAAC;IAEpD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC;IAExD;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,WAAW,CACnC,cAAc,EACd,WAAW,CAAC,cAAc,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CACnD,CAAC;IAEF;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,WAAW,CACnC,cAAc,EACd,WAAW,CAAC,cAAc,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CACnD,CAAC;CACH,CAAC,CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,cAAc,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAChE,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,aAAa,0CAAqE,CAAC;AAEzF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ /**
3
+ * アプリケーションの最上位からルーターのグローバル状態を子コンポーネントへ一元的に伝播させるための React コンテキストです。
4
+ *
5
+ * パフォーマンス最適化のためにプロバイダー自体は基本的に更新されず、子コンポーネントは `subscribe` と `useSyncExternalStore`を使って必要な部分データだけを購読します。
6
+ */
7
+ const RouterContext = /*#__PURE__*/ React.createContext(null);
8
+ export default RouterContext;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 2つのルートパスの優先順位を比較し、ソート順を決定するための比較関数です。
3
+ *
4
+ * より具体的で制限の厳しいパス(詳細度スコアが高いパス)が、ソート結果においてより前方に配置されるように負の値を返します。
5
+ *
6
+ * @param pathA 比較対象となる1つ目のパス文字列です。
7
+ * @param pathB 比較対象となる2つ目のパス文字列です。
8
+ * @returns `pathA` を優先する場合は負の数、`pathB` を優先する場合は正の数、等価である場合は `0` を返します。
9
+ */
10
+ export default function compareRoutePaths(pathA: string, pathB: string): number;
11
+ //# sourceMappingURL=_compare-route-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_compare-route-paths.d.ts","sourceRoot":"","sources":["../../../src/core/_compare-route-paths.ts"],"names":[],"mappings":"AA+DA;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA+B9E"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * セグメントの種類に応じたスコア定数です。
3
+ *
4
+ * 数値が大きいほど優先順位(詳細度)が高いです。
5
+ *
6
+ * 詳細度(regexparam の README より):
7
+ * | 順位 | 種別 | 例 |
8
+ * | --: | :-- | :-- |
9
+ * | 1 | Static | `/foo`, `/foo/bar` |
10
+ * | 2 | Parameter with suffix | `/movies/:title.mp4`, `/movies/:title.(mp4\|mov)` |
11
+ * | 3 | Parameter | `/:title`, `/books/:title`, `/books/:genre/:title` |
12
+ * | 4 | Optional Parameters | `/:title?`, `/books/:title?`, `/books/:genre/:title?` |
13
+ * | 5 | Wildcards | `*`, `/books/*`, `/books/:genre/*` |
14
+ * | 6 | Optional Wildcard | `/books/*?` |
15
+ *
16
+ * @see https://github.com/lukeed/regexparam
17
+ */
18
+ const SCORE = {
19
+ PARAM: 4,
20
+ STATIC: 6,
21
+ WILDCARD: 2,
22
+ OPTIONAL_PARAM: 3,
23
+ OPTIONAL_WILDCARD: 1,
24
+ PARAM_WITH_SUFFIX: 5,
25
+ };
26
+ /**
27
+ * 与えられた単一のセグメント文字列を解析し、その特性に応じた詳細度スコアを算出します。
28
+ *
29
+ * @param s 解析対象となるセグメント文字列です。
30
+ * @returns セグメントの種別に対応する、`SCORE` 定数から抽出された数値スコアです。
31
+ */
32
+ function getSegmentScore(s) {
33
+ if (s === "*?") {
34
+ return SCORE.OPTIONAL_WILDCARD;
35
+ }
36
+ if (s === "*") {
37
+ return SCORE.WILDCARD;
38
+ }
39
+ if (s[0] === ":") {
40
+ if (s[s.length - 1] === "?") {
41
+ return SCORE.OPTIONAL_PARAM;
42
+ }
43
+ if (s.indexOf(".") < 0) {
44
+ return SCORE.PARAM;
45
+ }
46
+ return SCORE.PARAM_WITH_SUFFIX;
47
+ }
48
+ return SCORE.STATIC;
49
+ }
50
+ /**
51
+ * 英語のロケール設定に基づき、大文字小文字などを標準化した文字列比較を行うための `Intl.Collator` インスタンスです。
52
+ *
53
+ * 決定論的な辞書順ソートを保証するために使用します。
54
+ */
55
+ const enCollator = new Intl.Collator("en");
56
+ /**
57
+ * 2つのルートパスの優先順位を比較し、ソート順を決定するための比較関数です。
58
+ *
59
+ * より具体的で制限の厳しいパス(詳細度スコアが高いパス)が、ソート結果においてより前方に配置されるように負の値を返します。
60
+ *
61
+ * @param pathA 比較対象となる1つ目のパス文字列です。
62
+ * @param pathB 比較対象となる2つ目のパス文字列です。
63
+ * @returns `pathA` を優先する場合は負の数、`pathB` を優先する場合は正の数、等価である場合は `0` を返します。
64
+ */
65
+ export default function compareRoutePaths(pathA, pathB) {
66
+ const partsA = pathA.split("/").filter(Boolean);
67
+ const partsB = pathB.split("/").filter(Boolean);
68
+ const length = Math.max(partsA.length, partsB.length);
69
+ for (let i = 0; i < length; i++) {
70
+ const a = partsA[i];
71
+ // パス A のセグメントが先に終了した場合は、パス B を優先します。
72
+ if (a === undefined) {
73
+ return 1;
74
+ }
75
+ const b = partsB[i];
76
+ // パス B のセグメントが先に終了した場合は、パス A を優先します。
77
+ if (b === undefined) {
78
+ return -1;
79
+ }
80
+ const scoreA = getSegmentScore(a);
81
+ const scoreB = getSegmentScore(b);
82
+ // スコアが異なる場合は、スコアが高い方を優先します。
83
+ if (scoreA !== scoreB) {
84
+ return scoreB - scoreA;
85
+ }
86
+ // スコアが同じ場合は、文字列の辞書順で比較します。
87
+ if (a !== b) {
88
+ return enCollator.compare(a, b);
89
+ }
90
+ }
91
+ return 0;
92
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReadonlyURL } from "./readonly-url.types.js";
2
+ import type { Route, RoutePathParams } from "./route.types.js";
3
+ /**
4
+ * パスマッチングの処理結果を表すオブジェクトの型定義です。
5
+ */
6
+ export type MatchPathResult = {
7
+ /**
8
+ * マッチした URL パスから抽出されたパラメーターのキーと値のオブジェクトです。
9
+ */
10
+ params: RoutePathParams;
11
+ };
12
+ /**
13
+ * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
14
+ *
15
+ * ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
16
+ *
17
+ * @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
18
+ * @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
19
+ * @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
20
+ */
21
+ export default function matchPath(route: Pick<Route, "paramKeys" | "pathPattern">, url: ReadonlyURL): MatchPathResult | null;
22
+ //# sourceMappingURL=_match-route-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_match-route-path.d.ts","sourceRoot":"","sources":["../../../src/core/_match-route-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CAAC,EAC/C,GAAG,EAAE,WAAW,GACf,eAAe,GAAG,IAAI,CAmBxB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
3
+ *
4
+ * ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
5
+ *
6
+ * @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
7
+ * @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
8
+ * @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
9
+ */
10
+ export default function matchPath(route, url) {
11
+ const matches = route.pathPattern.exec(url.pathname);
12
+ if (!matches) {
13
+ return null;
14
+ }
15
+ const params = {};
16
+ for (let i = 0, param; i < route.paramKeys.length; i++) {
17
+ // exec メソッドの戻り値のインデックス 0 にはマッチした文字列全体が格納されているため、各パラメーターの値はインデックス 1 以降(i + 1)から取得します。
18
+ param = matches[i + 1];
19
+ // キャプチャーされたセグメントが存在し、かつ文字列型である場合にのみ、対応するパラメーターキーと値をマッピングします。
20
+ // オプショナルなパラメーターが URL 側で省略されている場合は undefined となるため、この条件節により除外されます。
21
+ if (typeof param === "string") {
22
+ params[route.paramKeys[i]] = param;
23
+ }
24
+ }
25
+ return { params };
26
+ }
@@ -0,0 +1,14 @@
1
+ import type { Route, RouteDefinition } from "./route.types.js";
2
+ /**
3
+ * 定義したルーティング設定の配列を、内部のルーティングエンジンが直接利用可能な正規化済みのルートオブジェクトの配列へと変換します。
4
+ *
5
+ * 実行内容:
6
+ * - 各ルートのパス正規化
7
+ * - 動的解析用の正規表現コンパイル
8
+ * - 詳細度に基づく優先順位ソート
9
+ *
10
+ * @param routes ルーティング定義を格納した読み取り専用の配列です。
11
+ * @returns 読み取り専用の正規化済みルートオブジェクトの配列です。
12
+ */
13
+ export default function processRoutes(routes: readonly RouteDefinition[]): readonly Route[];
14
+ //# sourceMappingURL=_process-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_process-routes.d.ts","sourceRoot":"","sources":["../../../src/core/_process-routes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,KAAK,EAAE,CAoC1F"}
@@ -0,0 +1,45 @@
1
+ import { parse } from "regexparam";
2
+ import compareRoutePaths from "./_compare-route-paths.js";
3
+ import RoutePath from "./route-path.js";
4
+ /**
5
+ * 定義したルーティング設定の配列を、内部のルーティングエンジンが直接利用可能な正規化済みのルートオブジェクトの配列へと変換します。
6
+ *
7
+ * 実行内容:
8
+ * - 各ルートのパス正規化
9
+ * - 動的解析用の正規表現コンパイル
10
+ * - 詳細度に基づく優先順位ソート
11
+ *
12
+ * @param routes ルーティング定義を格納した読み取り専用の配列です。
13
+ * @returns 読み取り専用の正規化済みルートオブジェクトの配列です。
14
+ */
15
+ export default function processRoutes(routes) {
16
+ return (routes
17
+ .map((route) => {
18
+ const path = RoutePath.encode(route.path);
19
+ const index = route.index === true;
20
+ const { keys: paramKeys, pattern: pathPattern } = parse(path,
21
+ // インデックスルートでないとき loose オプションを `true` にして子ルートに対してもマッチするようにします。
22
+ // これにより、前方一致による階層的なマッチングが有効になります。
23
+ !index);
24
+ return {
25
+ path,
26
+ index,
27
+ action: route.action,
28
+ loader: route.loader,
29
+ // オブジェクト形式またはモジュール形式の双方を安全に評価し、描画対象となる React コンポーネントを確定します。
30
+ component: typeof route.component === "function"
31
+ ? route.component
32
+ : Symbol.toStringTag in route &&
33
+ route[Symbol.toStringTag] === "Module" &&
34
+ typeof route.default === "function"
35
+ ? route.default
36
+ : undefined,
37
+ paramKeys,
38
+ pathPattern,
39
+ shouldReload: route.shouldReload || ((args) => args.defaultShouldReload),
40
+ };
41
+ })
42
+ // すべてのルートを正規化した後、compareRoutePaths 関数を用いて詳細度が高い順にソートします。
43
+ // マッチング漏れや誤ったルートへの誤認を防ぐため、制限の厳しい(具体的な)パスパターンを持つルートオブジェクトが配列のより前方に配置されます。
44
+ .sort((a, b) => compareRoutePaths(a.path, b.path)));
45
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 指定された識別子に対して、渡されたファクトリー関数を一度だけ実行し、その生成結果をシングルトンとして永続化および共有します。
3
+ *
4
+ * 2回目以降の呼び出しでは、ファクトリー関数は実行されず、初回に生成されたキャッシュデータが即座に返されます。
5
+ *
6
+ * @template T ファクトリー関数が生成するシングルトンオブジェクトの型定義です。
7
+ * @param key シングルトンオブジェクトをキャッシュ内で一意に識別するためのキーです。
8
+ * @param fn 初回呼び出し時にのみ実行される、オブジェクト生成用のファクトリー関数です。
9
+ * @returns 初回実行時に生成された、またはキャッシュから回収された型 `T` のシングルトンインスタンスを返します。
10
+ */
11
+ export default function singleton<T>(key: unknown, fn: (...args: any) => T): T;
12
+ //# sourceMappingURL=_singleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_singleton.d.ts","sourceRoot":"","sources":["../../../src/core/_singleton.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAE7E"}
@@ -0,0 +1,18 @@
1
+ import { callFnOnce } from "call-fn-once";
2
+ /**
3
+ * 初回実行時の生成結果を保持するためのグローバルなキャッシュ管理マップです。
4
+ */
5
+ const cacheMap = new Map();
6
+ /**
7
+ * 指定された識別子に対して、渡されたファクトリー関数を一度だけ実行し、その生成結果をシングルトンとして永続化および共有します。
8
+ *
9
+ * 2回目以降の呼び出しでは、ファクトリー関数は実行されず、初回に生成されたキャッシュデータが即座に返されます。
10
+ *
11
+ * @template T ファクトリー関数が生成するシングルトンオブジェクトの型定義です。
12
+ * @param key シングルトンオブジェクトをキャッシュ内で一意に識別するためのキーです。
13
+ * @param fn 初回呼び出し時にのみ実行される、オブジェクト生成用のファクトリー関数です。
14
+ * @returns 初回実行時に生成された、またはキャッシュから回収された型 `T` のシングルトンインスタンスを返します。
15
+ */
16
+ export default function singleton(key, fn) {
17
+ return callFnOnce(cacheMap, key, fn);
18
+ }