convex-cms 0.0.2 → 0.0.5-alpha.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 (311) hide show
  1. package/README.md +109 -13
  2. package/admin-dist/nitro.json +15 -0
  3. package/admin-dist/public/assets/CmsEmptyState-CiMQwSQV.js +5 -0
  4. package/admin-dist/public/assets/CmsPageHeader-ohOq0luT.js +1 -0
  5. package/admin-dist/public/assets/CmsStatusBadge-BdNf0V9v.js +1 -0
  6. package/admin-dist/public/assets/CmsSurface-CWup6Jh7.js +1 -0
  7. package/admin-dist/public/assets/CmsToolbar-cEBlCHa3.js +1 -0
  8. package/admin-dist/public/assets/ContentEntryEditor-BY5ypfUs.js +4 -0
  9. package/admin-dist/public/assets/ErrorState-C4nJ-ml4.js +1 -0
  10. package/admin-dist/public/assets/TaxonomyFilter-BgE_SR_O.js +1 -0
  11. package/admin-dist/public/assets/_contentTypeId-DtZectcC.js +1 -0
  12. package/admin-dist/public/assets/_entryId-BpSmrfAm.js +1 -0
  13. package/admin-dist/public/assets/alert-Bf2l8kxw.js +1 -0
  14. package/admin-dist/public/assets/badge-qPrc4AUM.js +1 -0
  15. package/admin-dist/public/assets/circle-check-big-Dgozy3vV.js +1 -0
  16. package/admin-dist/public/assets/command-QOmNhlb0.js +1 -0
  17. package/admin-dist/public/assets/content-OEBGlxg1.js +1 -0
  18. package/admin-dist/public/assets/content-types-CjQliqVV.js +2 -0
  19. package/admin-dist/public/assets/globals-hAmgC66w.css +1 -0
  20. package/admin-dist/public/assets/index-BH_ECMhv.js +1 -0
  21. package/admin-dist/public/assets/label-DCsUdvFh.js +1 -0
  22. package/admin-dist/public/assets/link-2-Czw1N61H.js +1 -0
  23. package/admin-dist/public/assets/list-DtCsXj8-.js +1 -0
  24. package/admin-dist/public/assets/main-CXgkZMhe.js +97 -0
  25. package/admin-dist/public/assets/media-DTJ3-ViE.js +1 -0
  26. package/admin-dist/public/assets/new._contentTypeId-CoTDxKzf.js +1 -0
  27. package/admin-dist/public/assets/plus-xCFJK0RC.js +1 -0
  28. package/admin-dist/public/assets/rotate-ccw-DIqK63wY.js +1 -0
  29. package/admin-dist/public/assets/scroll-area-B-yrE66a.js +1 -0
  30. package/admin-dist/public/assets/search-CbCbboeU.js +1 -0
  31. package/admin-dist/public/assets/select-Co3TZFJb.js +1 -0
  32. package/admin-dist/public/assets/settings-BspTTv_o.js +1 -0
  33. package/admin-dist/public/assets/switch-CfavASmR.js +1 -0
  34. package/admin-dist/public/assets/tabs-CN5s5u2W.js +1 -0
  35. package/admin-dist/public/assets/tanstack-adapter-npeE3RdY.js +1 -0
  36. package/admin-dist/public/assets/taxonomies-CgG46fIF.js +1 -0
  37. package/admin-dist/public/assets/textarea-BJ0XFZpT.js +1 -0
  38. package/admin-dist/public/assets/trash-B3daldm5.js +1 -0
  39. package/admin-dist/public/assets/triangle-alert-BZRcqsUg.js +1 -0
  40. package/admin-dist/public/assets/useBreadcrumbLabel-DwZlwvFF.js +1 -0
  41. package/admin-dist/public/assets/usePermissions-C1JQhfqb.js +1 -0
  42. package/admin-dist/public/favicon.ico +0 -0
  43. package/admin-dist/server/_chunks/_libs/@date-fns/tz.mjs +217 -0
  44. package/admin-dist/server/_chunks/_libs/@floating-ui/core.mjs +719 -0
  45. package/admin-dist/server/_chunks/_libs/@floating-ui/dom.mjs +622 -0
  46. package/admin-dist/server/_chunks/_libs/@floating-ui/react-dom.mjs +292 -0
  47. package/admin-dist/server/_chunks/_libs/@floating-ui/utils.mjs +320 -0
  48. package/admin-dist/server/_chunks/_libs/@radix-ui/number.mjs +6 -0
  49. package/admin-dist/server/_chunks/_libs/@radix-ui/primitive.mjs +11 -0
  50. package/admin-dist/server/_chunks/_libs/@radix-ui/react-arrow.mjs +23 -0
  51. package/admin-dist/server/_chunks/_libs/@radix-ui/react-avatar.mjs +119 -0
  52. package/admin-dist/server/_chunks/_libs/@radix-ui/react-checkbox.mjs +270 -0
  53. package/admin-dist/server/_chunks/_libs/@radix-ui/react-collection.mjs +69 -0
  54. package/admin-dist/server/_chunks/_libs/@radix-ui/react-compose-refs.mjs +39 -0
  55. package/admin-dist/server/_chunks/_libs/@radix-ui/react-context.mjs +137 -0
  56. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dialog.mjs +325 -0
  57. package/admin-dist/server/_chunks/_libs/@radix-ui/react-direction.mjs +9 -0
  58. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dismissable-layer.mjs +210 -0
  59. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dropdown-menu.mjs +253 -0
  60. package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-guards.mjs +29 -0
  61. package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-scope.mjs +206 -0
  62. package/admin-dist/server/_chunks/_libs/@radix-ui/react-id.mjs +14 -0
  63. package/admin-dist/server/_chunks/_libs/@radix-ui/react-label.mjs +23 -0
  64. package/admin-dist/server/_chunks/_libs/@radix-ui/react-menu.mjs +812 -0
  65. package/admin-dist/server/_chunks/_libs/@radix-ui/react-popover.mjs +300 -0
  66. package/admin-dist/server/_chunks/_libs/@radix-ui/react-popper.mjs +286 -0
  67. package/admin-dist/server/_chunks/_libs/@radix-ui/react-portal.mjs +16 -0
  68. package/admin-dist/server/_chunks/_libs/@radix-ui/react-presence.mjs +128 -0
  69. package/admin-dist/server/_chunks/_libs/@radix-ui/react-primitive.mjs +141 -0
  70. package/admin-dist/server/_chunks/_libs/@radix-ui/react-roving-focus.mjs +224 -0
  71. package/admin-dist/server/_chunks/_libs/@radix-ui/react-scroll-area.mjs +721 -0
  72. package/admin-dist/server/_chunks/_libs/@radix-ui/react-select.mjs +1163 -0
  73. package/admin-dist/server/_chunks/_libs/@radix-ui/react-separator.mjs +28 -0
  74. package/admin-dist/server/_chunks/_libs/@radix-ui/react-slot.mjs +601 -0
  75. package/admin-dist/server/_chunks/_libs/@radix-ui/react-switch.mjs +152 -0
  76. package/admin-dist/server/_chunks/_libs/@radix-ui/react-tabs.mjs +189 -0
  77. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-callback-ref.mjs +11 -0
  78. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-controllable-state.mjs +69 -0
  79. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-effect-event.mjs +1 -0
  80. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-escape-keydown.mjs +17 -0
  81. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-is-hydrated.mjs +15 -0
  82. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-layout-effect.mjs +6 -0
  83. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-previous.mjs +14 -0
  84. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-size.mjs +39 -0
  85. package/admin-dist/server/_chunks/_libs/@radix-ui/react-visually-hidden.mjs +33 -0
  86. package/admin-dist/server/_chunks/_libs/@tanstack/history.mjs +409 -0
  87. package/admin-dist/server/_chunks/_libs/@tanstack/react-router.mjs +1718 -0
  88. package/admin-dist/server/_chunks/_libs/@tanstack/react-store.mjs +56 -0
  89. package/admin-dist/server/_chunks/_libs/@tanstack/router-core.mjs +4829 -0
  90. package/admin-dist/server/_chunks/_libs/@tanstack/store.mjs +134 -0
  91. package/admin-dist/server/_chunks/_libs/react-dom.mjs +10781 -0
  92. package/admin-dist/server/_chunks/_libs/react.mjs +513 -0
  93. package/admin-dist/server/_libs/aria-hidden.mjs +122 -0
  94. package/admin-dist/server/_libs/class-variance-authority.mjs +44 -0
  95. package/admin-dist/server/_libs/clsx.mjs +16 -0
  96. package/admin-dist/server/_libs/cmdk.mjs +315 -0
  97. package/admin-dist/server/_libs/convex.mjs +4841 -0
  98. package/admin-dist/server/_libs/cookie-es.mjs +58 -0
  99. package/admin-dist/server/_libs/croner.mjs +1 -0
  100. package/admin-dist/server/_libs/crossws.mjs +1 -0
  101. package/admin-dist/server/_libs/date-fns.mjs +1716 -0
  102. package/admin-dist/server/_libs/detect-node-es.mjs +1 -0
  103. package/admin-dist/server/_libs/get-nonce.mjs +9 -0
  104. package/admin-dist/server/_libs/h3-v2.mjs +277 -0
  105. package/admin-dist/server/_libs/h3.mjs +401 -0
  106. package/admin-dist/server/_libs/hookable.mjs +1 -0
  107. package/admin-dist/server/_libs/isbot.mjs +20 -0
  108. package/admin-dist/server/_libs/lucide-react.mjs +850 -0
  109. package/admin-dist/server/_libs/ohash.mjs +1 -0
  110. package/admin-dist/server/_libs/react-day-picker.mjs +2201 -0
  111. package/admin-dist/server/_libs/react-remove-scroll-bar.mjs +82 -0
  112. package/admin-dist/server/_libs/react-remove-scroll.mjs +328 -0
  113. package/admin-dist/server/_libs/react-style-singleton.mjs +69 -0
  114. package/admin-dist/server/_libs/rou3.mjs +8 -0
  115. package/admin-dist/server/_libs/seroval-plugins.mjs +58 -0
  116. package/admin-dist/server/_libs/seroval.mjs +1765 -0
  117. package/admin-dist/server/_libs/srvx.mjs +719 -0
  118. package/admin-dist/server/_libs/tailwind-merge.mjs +3010 -0
  119. package/admin-dist/server/_libs/tiny-invariant.mjs +12 -0
  120. package/admin-dist/server/_libs/tiny-warning.mjs +5 -0
  121. package/admin-dist/server/_libs/tslib.mjs +39 -0
  122. package/admin-dist/server/_libs/ufo.mjs +54 -0
  123. package/admin-dist/server/_libs/unctx.mjs +1 -0
  124. package/admin-dist/server/_libs/unstorage.mjs +1 -0
  125. package/admin-dist/server/_libs/use-callback-ref.mjs +66 -0
  126. package/admin-dist/server/_libs/use-sidecar.mjs +106 -0
  127. package/admin-dist/server/_libs/use-sync-external-store.mjs +139 -0
  128. package/admin-dist/server/_libs/zod.mjs +4223 -0
  129. package/admin-dist/server/_ssr/CmsButton-B45JAKR1.mjs +125 -0
  130. package/admin-dist/server/_ssr/CmsEmptyState-D_BQFAVR.mjs +290 -0
  131. package/admin-dist/server/_ssr/CmsPageHeader-CrUZA59A.mjs +24 -0
  132. package/admin-dist/server/_ssr/CmsStatusBadge-B-sj6yaj.mjs +127 -0
  133. package/admin-dist/server/_ssr/CmsSurface-DKJZhpjk.mjs +44 -0
  134. package/admin-dist/server/_ssr/CmsToolbar-ByaW5iXf.mjs +49 -0
  135. package/admin-dist/server/_ssr/ContentEntryEditor-D3_Jb1dq.mjs +3720 -0
  136. package/admin-dist/server/_ssr/ErrorState-cI-bKLez.mjs +89 -0
  137. package/admin-dist/server/_ssr/TaxonomyFilter-BRJkuCtA.mjs +188 -0
  138. package/admin-dist/server/_ssr/_contentTypeId-B9kA6CaM.mjs +379 -0
  139. package/admin-dist/server/_ssr/_entryId-BddcMkZN.mjs +161 -0
  140. package/admin-dist/server/_ssr/_tanstack-start-manifest_v-Dd7AmelK.mjs +4 -0
  141. package/admin-dist/server/_ssr/command-CGtVr8Gb.mjs +128 -0
  142. package/admin-dist/server/_ssr/config.server-D7JHDcDv.mjs +117 -0
  143. package/admin-dist/server/_ssr/content-D1tbeOd0.mjs +647 -0
  144. package/admin-dist/server/_ssr/content-types-BZqY_BER.mjs +1342 -0
  145. package/admin-dist/server/_ssr/index-BIdq4xaC.mjs +264 -0
  146. package/admin-dist/server/_ssr/index.mjs +1275 -0
  147. package/admin-dist/server/_ssr/label-T-QNKAr6.mjs +22 -0
  148. package/admin-dist/server/_ssr/media-C-xqjBrl.mjs +1832 -0
  149. package/admin-dist/server/_ssr/new._contentTypeId-DWic9cRq.mjs +144 -0
  150. package/admin-dist/server/_ssr/router-D1BMAMJT.mjs +1556 -0
  151. package/admin-dist/server/_ssr/scroll-area-C0pic_WA.mjs +59 -0
  152. package/admin-dist/server/_ssr/select-CqmuN2F6.mjs +142 -0
  153. package/admin-dist/server/_ssr/settings-CAkncGGV.mjs +430 -0
  154. package/admin-dist/server/_ssr/start-HYkvq4Ni.mjs +4 -0
  155. package/admin-dist/server/_ssr/switch-CgmuJkT9.mjs +31 -0
  156. package/admin-dist/server/_ssr/tabs-CnMj0aRy.mjs +630 -0
  157. package/admin-dist/server/_ssr/tanstack-adapter-BXZrMauE.mjs +119 -0
  158. package/admin-dist/server/_ssr/taxonomies-thl3BfVm.mjs +1015 -0
  159. package/admin-dist/server/_ssr/textarea-4K5OJgeh.mjs +18 -0
  160. package/admin-dist/server/_ssr/trash-B40Gx5zP.mjs +411 -0
  161. package/admin-dist/server/_ssr/useBreadcrumbLabel-rn-fL4zV.mjs +16 -0
  162. package/admin-dist/server/_ssr/usePermissions-CKeM6_Vw.mjs +68 -0
  163. package/admin-dist/server/favicon.ico +0 -0
  164. package/admin-dist/server/index.mjs +641 -0
  165. package/dist/cli/commands/init.d.ts +6 -0
  166. package/dist/cli/commands/init.d.ts.map +1 -0
  167. package/dist/cli/commands/init.js +156 -0
  168. package/dist/cli/commands/init.js.map +1 -0
  169. package/dist/cli/index.js +6 -0
  170. package/dist/cli/index.js.map +1 -1
  171. package/dist/client/admin-config.d.ts +2 -3
  172. package/dist/client/admin-config.d.ts.map +1 -1
  173. package/dist/client/admin-config.js +2 -3
  174. package/dist/client/admin-config.js.map +1 -1
  175. package/dist/client/adminApi.d.ts +1877 -1851
  176. package/dist/client/adminApi.d.ts.map +1 -1
  177. package/dist/client/adminApi.js +649 -629
  178. package/dist/client/adminApi.js.map +1 -1
  179. package/dist/client/agentTools.d.ts +1231 -139
  180. package/dist/client/agentTools.d.ts.map +1 -1
  181. package/dist/client/agentTools.js +37 -13
  182. package/dist/client/agentTools.js.map +1 -1
  183. package/dist/client/index.d.ts +5 -5
  184. package/dist/client/index.d.ts.map +1 -1
  185. package/dist/client/index.js +4 -4
  186. package/dist/client/index.js.map +1 -1
  187. package/dist/client/schema/codegen.d.ts +2 -2
  188. package/dist/client/schema/codegen.d.ts.map +1 -1
  189. package/dist/client/schema/codegen.js +3 -3
  190. package/dist/client/schema/codegen.js.map +1 -1
  191. package/dist/client/schema/defineContentType.d.ts +3 -3
  192. package/dist/client/schema/defineContentType.js +3 -3
  193. package/dist/client/schema/index.d.ts +7 -7
  194. package/dist/client/schema/index.d.ts.map +1 -1
  195. package/dist/client/schema/index.js +5 -5
  196. package/dist/client/schema/index.js.map +1 -1
  197. package/dist/client/schema/schemaDrift.d.ts +1 -1
  198. package/dist/client/schema/schemaDrift.js +1 -1
  199. package/dist/client/schema/typedClient.d.ts +2 -2
  200. package/dist/client/schema/typedClient.js +2 -2
  201. package/dist/client/schema/types.d.ts +1 -1
  202. package/dist/client/schema/types.js +1 -1
  203. package/dist/client/wrapper.d.ts +108 -65
  204. package/dist/client/wrapper.d.ts.map +1 -1
  205. package/dist/client/wrapper.js +22 -22
  206. package/dist/client/wrapper.js.map +1 -1
  207. package/dist/component/_generated/component.d.ts +9 -0
  208. package/dist/component/_generated/component.d.ts.map +1 -1
  209. package/dist/component/convex.config.d.ts +2 -2
  210. package/dist/component/convex.config.js +2 -2
  211. package/dist/component/index.d.ts +1 -1
  212. package/dist/component/index.js +1 -1
  213. package/dist/component/lib/ragContentChunker.d.ts +1 -1
  214. package/dist/component/lib/ragContentChunker.js +1 -1
  215. package/dist/component/mediaAssets.d.ts +35 -0
  216. package/dist/component/mediaAssets.d.ts.map +1 -1
  217. package/dist/component/mediaAssets.js +81 -0
  218. package/dist/component/mediaAssets.js.map +1 -1
  219. package/dist/component/roles.d.ts +1 -1
  220. package/dist/component/roles.js +1 -1
  221. package/dist/react/index.d.ts +2 -2
  222. package/dist/react/index.d.ts.map +1 -1
  223. package/dist/react/index.js +13 -7
  224. package/dist/react/index.js.map +1 -1
  225. package/dist/test.d.ts +2 -2
  226. package/dist/test.d.ts.map +1 -1
  227. package/dist/test.js +4 -3
  228. package/dist/test.js.map +1 -1
  229. package/package.json +37 -13
  230. package/dist/component/auditLog.d.ts +0 -410
  231. package/dist/component/auditLog.d.ts.map +0 -1
  232. package/dist/component/auditLog.js +0 -607
  233. package/dist/component/auditLog.js.map +0 -1
  234. package/dist/component/types.d.ts +0 -4
  235. package/dist/component/types.d.ts.map +0 -1
  236. package/dist/component/types.js +0 -2
  237. package/dist/component/types.js.map +0 -1
  238. package/src/cli/commands/admin.ts +0 -104
  239. package/src/cli/index.ts +0 -21
  240. package/src/cli/utils/detectConvexUrl.ts +0 -54
  241. package/src/cli/utils/openBrowser.ts +0 -16
  242. package/src/client/admin-config.ts +0 -138
  243. package/src/client/adminApi.ts +0 -942
  244. package/src/client/agentTools.ts +0 -1311
  245. package/src/client/argTypes.ts +0 -316
  246. package/src/client/field-types.ts +0 -187
  247. package/src/client/index.ts +0 -1301
  248. package/src/client/queryBuilder.ts +0 -1100
  249. package/src/client/schema/codegen.ts +0 -500
  250. package/src/client/schema/defineContentType.ts +0 -501
  251. package/src/client/schema/index.ts +0 -169
  252. package/src/client/schema/schemaDrift.ts +0 -574
  253. package/src/client/schema/typedClient.ts +0 -688
  254. package/src/client/schema/types.ts +0 -666
  255. package/src/client/types.ts +0 -723
  256. package/src/client/workflows.ts +0 -141
  257. package/src/client/wrapper.ts +0 -4304
  258. package/src/component/_generated/api.ts +0 -140
  259. package/src/component/_generated/component.ts +0 -5029
  260. package/src/component/_generated/dataModel.ts +0 -60
  261. package/src/component/_generated/server.ts +0 -156
  262. package/src/component/authorization.ts +0 -647
  263. package/src/component/authorizationHooks.ts +0 -668
  264. package/src/component/bulkOperations.ts +0 -687
  265. package/src/component/contentEntries.ts +0 -1976
  266. package/src/component/contentEntryMutations.ts +0 -1223
  267. package/src/component/contentEntryValidation.ts +0 -707
  268. package/src/component/contentLock.ts +0 -550
  269. package/src/component/contentTypeMigration.ts +0 -1064
  270. package/src/component/contentTypeMutations.ts +0 -969
  271. package/src/component/contentTypes.ts +0 -346
  272. package/src/component/convex.config.ts +0 -44
  273. package/src/component/documentTypes.ts +0 -240
  274. package/src/component/eventEmitter.ts +0 -485
  275. package/src/component/exportImport.ts +0 -1169
  276. package/src/component/index.ts +0 -491
  277. package/src/component/lib/deepReferenceResolver.ts +0 -999
  278. package/src/component/lib/errors.ts +0 -816
  279. package/src/component/lib/index.ts +0 -145
  280. package/src/component/lib/mediaReferenceResolver.ts +0 -495
  281. package/src/component/lib/metadataExtractor.ts +0 -792
  282. package/src/component/lib/mutationAuth.ts +0 -199
  283. package/src/component/lib/queries.ts +0 -79
  284. package/src/component/lib/ragContentChunker.ts +0 -1371
  285. package/src/component/lib/referenceResolver.ts +0 -430
  286. package/src/component/lib/slugGenerator.ts +0 -262
  287. package/src/component/lib/slugUniqueness.ts +0 -333
  288. package/src/component/lib/softDelete.ts +0 -44
  289. package/src/component/localeFallbackChain.ts +0 -673
  290. package/src/component/localeFields.ts +0 -896
  291. package/src/component/mediaAssetMutations.ts +0 -725
  292. package/src/component/mediaAssets.ts +0 -932
  293. package/src/component/mediaFolderMutations.ts +0 -1046
  294. package/src/component/mediaUploadMutations.ts +0 -224
  295. package/src/component/mediaVariantMutations.ts +0 -900
  296. package/src/component/mediaVariants.ts +0 -793
  297. package/src/component/ragContentIndexer.ts +0 -1067
  298. package/src/component/rateLimitHooks.ts +0 -572
  299. package/src/component/roles.ts +0 -1360
  300. package/src/component/scheduledPublish.ts +0 -358
  301. package/src/component/schema.ts +0 -617
  302. package/src/component/taxonomies.ts +0 -949
  303. package/src/component/taxonomyMutations.ts +0 -1210
  304. package/src/component/trash.ts +0 -724
  305. package/src/component/userContext.ts +0 -898
  306. package/src/component/validation.ts +0 -1388
  307. package/src/component/validators.ts +0 -949
  308. package/src/component/versionMutations.ts +0 -392
  309. package/src/component/webhookTrigger.ts +0 -1922
  310. package/src/react/index.ts +0 -898
  311. package/src/test.ts +0 -1580
@@ -0,0 +1,409 @@
1
+ const stateIndexKey = "__TSR_index";
2
+ const popStateEvent = "popstate";
3
+ const beforeUnloadEvent = "beforeunload";
4
+ function createHistory(opts) {
5
+ let location = opts.getLocation();
6
+ const subscribers = /* @__PURE__ */ new Set();
7
+ const notify = (action, navigateOpts) => {
8
+ location = opts.getLocation();
9
+ subscribers.forEach(
10
+ (subscriber) => subscriber({ location, action, navigateOpts })
11
+ );
12
+ };
13
+ const handleIndexChange = (action) => {
14
+ if (opts.notifyOnIndexChange ?? true) notify(action);
15
+ else location = opts.getLocation();
16
+ };
17
+ const tryNavigation = async ({
18
+ task,
19
+ navigateOpts,
20
+ ...actionInfo
21
+ }) => {
22
+ const ignoreBlocker = navigateOpts?.ignoreBlocker ?? false;
23
+ if (ignoreBlocker) {
24
+ task();
25
+ return { type: "SUCCESS" };
26
+ }
27
+ const blockers = opts.getBlockers?.() ?? [];
28
+ const isPushOrReplace = actionInfo.type === "PUSH" || actionInfo.type === "REPLACE";
29
+ if (typeof document !== "undefined" && blockers.length && isPushOrReplace) {
30
+ for (const blocker of blockers) {
31
+ const nextLocation = parseHref(actionInfo.path, actionInfo.state);
32
+ const isBlocked = await blocker.blockerFn({
33
+ currentLocation: location,
34
+ nextLocation,
35
+ action: actionInfo.type
36
+ });
37
+ if (isBlocked) {
38
+ opts.onBlocked?.();
39
+ return { type: "BLOCKED" };
40
+ }
41
+ }
42
+ }
43
+ task();
44
+ return { type: "SUCCESS" };
45
+ };
46
+ return {
47
+ get location() {
48
+ return location;
49
+ },
50
+ get length() {
51
+ return opts.getLength();
52
+ },
53
+ subscribers,
54
+ subscribe: (cb) => {
55
+ subscribers.add(cb);
56
+ return () => {
57
+ subscribers.delete(cb);
58
+ };
59
+ },
60
+ push: (path, state, navigateOpts) => {
61
+ const currentIndex = location.state[stateIndexKey];
62
+ state = assignKeyAndIndex(currentIndex + 1, state);
63
+ return tryNavigation({
64
+ task: () => {
65
+ opts.pushState(path, state);
66
+ notify({ type: "PUSH" }, navigateOpts);
67
+ },
68
+ navigateOpts,
69
+ type: "PUSH",
70
+ path,
71
+ state
72
+ });
73
+ },
74
+ replace: (path, state, navigateOpts) => {
75
+ const currentIndex = location.state[stateIndexKey];
76
+ state = assignKeyAndIndex(currentIndex, state);
77
+ return tryNavigation({
78
+ task: () => {
79
+ opts.replaceState(path, state);
80
+ notify({ type: "REPLACE" }, navigateOpts);
81
+ },
82
+ navigateOpts,
83
+ type: "REPLACE",
84
+ path,
85
+ state
86
+ });
87
+ },
88
+ go: (index, navigateOpts) => {
89
+ tryNavigation({
90
+ task: () => {
91
+ opts.go(index);
92
+ handleIndexChange({ type: "GO", index });
93
+ },
94
+ navigateOpts,
95
+ type: "GO"
96
+ });
97
+ },
98
+ back: (navigateOpts) => {
99
+ tryNavigation({
100
+ task: () => {
101
+ opts.back(navigateOpts?.ignoreBlocker ?? false);
102
+ handleIndexChange({ type: "BACK" });
103
+ },
104
+ navigateOpts,
105
+ type: "BACK"
106
+ });
107
+ },
108
+ forward: (navigateOpts) => {
109
+ tryNavigation({
110
+ task: () => {
111
+ opts.forward(navigateOpts?.ignoreBlocker ?? false);
112
+ handleIndexChange({ type: "FORWARD" });
113
+ },
114
+ navigateOpts,
115
+ type: "FORWARD"
116
+ });
117
+ },
118
+ canGoBack: () => location.state[stateIndexKey] !== 0,
119
+ createHref: (str) => opts.createHref(str),
120
+ block: (blocker) => {
121
+ if (!opts.setBlockers) return () => {
122
+ };
123
+ const blockers = opts.getBlockers?.() ?? [];
124
+ opts.setBlockers([...blockers, blocker]);
125
+ return () => {
126
+ const blockers2 = opts.getBlockers?.() ?? [];
127
+ opts.setBlockers?.(blockers2.filter((b) => b !== blocker));
128
+ };
129
+ },
130
+ flush: () => opts.flush?.(),
131
+ destroy: () => opts.destroy?.(),
132
+ notify
133
+ };
134
+ }
135
+ function assignKeyAndIndex(index, state) {
136
+ if (!state) {
137
+ state = {};
138
+ }
139
+ const key = createRandomKey();
140
+ return {
141
+ ...state,
142
+ key,
143
+ // TODO: Remove in v2 - use __TSR_key instead
144
+ __TSR_key: key,
145
+ [stateIndexKey]: index
146
+ };
147
+ }
148
+ function createBrowserHistory(opts) {
149
+ const win = typeof document !== "undefined" ? window : void 0;
150
+ const originalPushState = win.history.pushState;
151
+ const originalReplaceState = win.history.replaceState;
152
+ let blockers = [];
153
+ const _getBlockers = () => blockers;
154
+ const _setBlockers = (newBlockers) => blockers = newBlockers;
155
+ const createHref = ((path) => path);
156
+ const parseLocation = (() => parseHref(
157
+ `${win.location.pathname}${win.location.search}${win.location.hash}`,
158
+ win.history.state
159
+ ));
160
+ if (!win.history.state?.__TSR_key && !win.history.state?.key) {
161
+ const addedKey = createRandomKey();
162
+ win.history.replaceState(
163
+ {
164
+ [stateIndexKey]: 0,
165
+ key: addedKey,
166
+ // TODO: Remove in v2 - use __TSR_key instead
167
+ __TSR_key: addedKey
168
+ },
169
+ ""
170
+ );
171
+ }
172
+ let currentLocation = parseLocation();
173
+ let rollbackLocation;
174
+ let nextPopIsGo = false;
175
+ let ignoreNextPop = false;
176
+ let skipBlockerNextPop = false;
177
+ let ignoreNextBeforeUnload = false;
178
+ const getLocation = () => currentLocation;
179
+ let next;
180
+ let scheduled;
181
+ const flush = () => {
182
+ if (!next) {
183
+ return;
184
+ }
185
+ history._ignoreSubscribers = true;
186
+ (next.isPush ? win.history.pushState : win.history.replaceState)(
187
+ next.state,
188
+ "",
189
+ next.href
190
+ );
191
+ history._ignoreSubscribers = false;
192
+ next = void 0;
193
+ scheduled = void 0;
194
+ rollbackLocation = void 0;
195
+ };
196
+ const queueHistoryAction = (type, destHref, state) => {
197
+ const href = createHref(destHref);
198
+ if (!scheduled) {
199
+ rollbackLocation = currentLocation;
200
+ }
201
+ currentLocation = parseHref(destHref, state);
202
+ next = {
203
+ href,
204
+ state,
205
+ isPush: next?.isPush || type === "push"
206
+ };
207
+ if (!scheduled) {
208
+ scheduled = Promise.resolve().then(() => flush());
209
+ }
210
+ };
211
+ const onPushPop = (type) => {
212
+ currentLocation = parseLocation();
213
+ history.notify({ type });
214
+ };
215
+ const onPushPopEvent = async () => {
216
+ if (ignoreNextPop) {
217
+ ignoreNextPop = false;
218
+ return;
219
+ }
220
+ const nextLocation = parseLocation();
221
+ const delta = nextLocation.state[stateIndexKey] - currentLocation.state[stateIndexKey];
222
+ const isForward = delta === 1;
223
+ const isBack = delta === -1;
224
+ const isGo = !isForward && !isBack || nextPopIsGo;
225
+ nextPopIsGo = false;
226
+ const action = isGo ? "GO" : isBack ? "BACK" : "FORWARD";
227
+ const notify = isGo ? {
228
+ type: "GO",
229
+ index: delta
230
+ } : {
231
+ type: isBack ? "BACK" : "FORWARD"
232
+ };
233
+ if (skipBlockerNextPop) {
234
+ skipBlockerNextPop = false;
235
+ } else {
236
+ const blockers2 = _getBlockers();
237
+ if (typeof document !== "undefined" && blockers2.length) {
238
+ for (const blocker of blockers2) {
239
+ const isBlocked = await blocker.blockerFn({
240
+ currentLocation,
241
+ nextLocation,
242
+ action
243
+ });
244
+ if (isBlocked) {
245
+ ignoreNextPop = true;
246
+ win.history.go(1);
247
+ history.notify(notify);
248
+ return;
249
+ }
250
+ }
251
+ }
252
+ }
253
+ currentLocation = parseLocation();
254
+ history.notify(notify);
255
+ };
256
+ const onBeforeUnload = (e) => {
257
+ if (ignoreNextBeforeUnload) {
258
+ ignoreNextBeforeUnload = false;
259
+ return;
260
+ }
261
+ let shouldBlock = false;
262
+ const blockers2 = _getBlockers();
263
+ if (typeof document !== "undefined" && blockers2.length) {
264
+ for (const blocker of blockers2) {
265
+ const shouldHaveBeforeUnload = blocker.enableBeforeUnload ?? true;
266
+ if (shouldHaveBeforeUnload === true) {
267
+ shouldBlock = true;
268
+ break;
269
+ }
270
+ if (typeof shouldHaveBeforeUnload === "function" && shouldHaveBeforeUnload() === true) {
271
+ shouldBlock = true;
272
+ break;
273
+ }
274
+ }
275
+ }
276
+ if (shouldBlock) {
277
+ e.preventDefault();
278
+ return e.returnValue = "";
279
+ }
280
+ return;
281
+ };
282
+ const history = createHistory({
283
+ getLocation,
284
+ getLength: () => win.history.length,
285
+ pushState: (href, state) => queueHistoryAction("push", href, state),
286
+ replaceState: (href, state) => queueHistoryAction("replace", href, state),
287
+ back: (ignoreBlocker) => {
288
+ if (ignoreBlocker) skipBlockerNextPop = true;
289
+ ignoreNextBeforeUnload = true;
290
+ return win.history.back();
291
+ },
292
+ forward: (ignoreBlocker) => {
293
+ if (ignoreBlocker) skipBlockerNextPop = true;
294
+ ignoreNextBeforeUnload = true;
295
+ win.history.forward();
296
+ },
297
+ go: (n) => {
298
+ nextPopIsGo = true;
299
+ win.history.go(n);
300
+ },
301
+ createHref: (href) => createHref(href),
302
+ flush,
303
+ destroy: () => {
304
+ win.history.pushState = originalPushState;
305
+ win.history.replaceState = originalReplaceState;
306
+ win.removeEventListener(beforeUnloadEvent, onBeforeUnload, {
307
+ capture: true
308
+ });
309
+ win.removeEventListener(popStateEvent, onPushPopEvent);
310
+ },
311
+ onBlocked: () => {
312
+ if (rollbackLocation && currentLocation !== rollbackLocation) {
313
+ currentLocation = rollbackLocation;
314
+ }
315
+ },
316
+ getBlockers: _getBlockers,
317
+ setBlockers: _setBlockers,
318
+ notifyOnIndexChange: false
319
+ });
320
+ win.addEventListener(beforeUnloadEvent, onBeforeUnload, { capture: true });
321
+ win.addEventListener(popStateEvent, onPushPopEvent);
322
+ win.history.pushState = function(...args) {
323
+ const res = originalPushState.apply(win.history, args);
324
+ if (!history._ignoreSubscribers) onPushPop("PUSH");
325
+ return res;
326
+ };
327
+ win.history.replaceState = function(...args) {
328
+ const res = originalReplaceState.apply(win.history, args);
329
+ if (!history._ignoreSubscribers) onPushPop("REPLACE");
330
+ return res;
331
+ };
332
+ return history;
333
+ }
334
+ function createMemoryHistory(opts = {
335
+ initialEntries: ["/"]
336
+ }) {
337
+ const entries = opts.initialEntries;
338
+ let index = opts.initialIndex ? Math.min(Math.max(opts.initialIndex, 0), entries.length - 1) : entries.length - 1;
339
+ const states = entries.map(
340
+ (_entry, index2) => assignKeyAndIndex(index2, void 0)
341
+ );
342
+ const getLocation = () => parseHref(entries[index], states[index]);
343
+ let blockers = [];
344
+ const _getBlockers = () => blockers;
345
+ const _setBlockers = (newBlockers) => blockers = newBlockers;
346
+ return createHistory({
347
+ getLocation,
348
+ getLength: () => entries.length,
349
+ pushState: (path, state) => {
350
+ if (index < entries.length - 1) {
351
+ entries.splice(index + 1);
352
+ states.splice(index + 1);
353
+ }
354
+ states.push(state);
355
+ entries.push(path);
356
+ index = Math.max(entries.length - 1, 0);
357
+ },
358
+ replaceState: (path, state) => {
359
+ states[index] = state;
360
+ entries[index] = path;
361
+ },
362
+ back: () => {
363
+ index = Math.max(index - 1, 0);
364
+ },
365
+ forward: () => {
366
+ index = Math.min(index + 1, entries.length - 1);
367
+ },
368
+ go: (n) => {
369
+ index = Math.min(Math.max(index + n, 0), entries.length - 1);
370
+ },
371
+ createHref: (path) => path,
372
+ getBlockers: _getBlockers,
373
+ setBlockers: _setBlockers
374
+ });
375
+ }
376
+ function sanitizePath(path) {
377
+ let sanitized = path.replace(/[\x00-\x1f\x7f]/g, "");
378
+ if (sanitized.startsWith("//")) {
379
+ sanitized = "/" + sanitized.replace(/^\/+/, "");
380
+ }
381
+ return sanitized;
382
+ }
383
+ function parseHref(href, state) {
384
+ const sanitizedHref = sanitizePath(href);
385
+ const hashIndex = sanitizedHref.indexOf("#");
386
+ const searchIndex = sanitizedHref.indexOf("?");
387
+ const addedKey = createRandomKey();
388
+ return {
389
+ href: sanitizedHref,
390
+ pathname: sanitizedHref.substring(
391
+ 0,
392
+ hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : sanitizedHref.length
393
+ ),
394
+ hash: hashIndex > -1 ? sanitizedHref.substring(hashIndex) : "",
395
+ search: searchIndex > -1 ? sanitizedHref.slice(
396
+ searchIndex,
397
+ hashIndex === -1 ? void 0 : hashIndex
398
+ ) : "",
399
+ state: state || { [stateIndexKey]: 0, key: addedKey, __TSR_key: addedKey }
400
+ };
401
+ }
402
+ function createRandomKey() {
403
+ return (Math.random() + 1).toString(36).substring(7);
404
+ }
405
+ export {
406
+ createMemoryHistory as a,
407
+ createBrowserHistory as c,
408
+ parseHref as p
409
+ };