vorma 0.0.0-pre.0 → 0.83.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 (225) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +48 -0
  3. package/internal/framework/_typescript/client/index.ts +64 -0
  4. package/internal/framework/_typescript/client/src/asset_manager.ts +67 -0
  5. package/internal/framework/_typescript/client/src/client.ts +1201 -0
  6. package/internal/framework/_typescript/client/src/client_loaders.ts +249 -0
  7. package/internal/framework/_typescript/client/src/component_loader.ts +105 -0
  8. package/internal/framework/_typescript/client/src/error_boundary.ts +7 -0
  9. package/internal/framework/_typescript/client/src/events.ts +54 -0
  10. package/internal/framework/_typescript/client/src/global_loading_indicator/global_loading_indicator.ts +125 -0
  11. package/internal/framework/_typescript/client/src/hard_reload.ts +1 -0
  12. package/internal/framework/_typescript/client/src/head_elements/head_elements.ts +193 -0
  13. package/internal/framework/_typescript/client/src/history/history.ts +118 -0
  14. package/internal/framework/_typescript/client/src/history/npm_history_types.ts +83 -0
  15. package/internal/framework/_typescript/client/src/hmr/hmr.ts +71 -0
  16. package/internal/framework/_typescript/client/src/init_client.ts +134 -0
  17. package/internal/framework/_typescript/client/src/links.ts +218 -0
  18. package/internal/framework/_typescript/client/src/redirects/redirects.ts +203 -0
  19. package/internal/framework/_typescript/client/src/rendering.ts +135 -0
  20. package/internal/framework/_typescript/client/src/resolve_public_href.ts +15 -0
  21. package/internal/framework/_typescript/client/src/scroll_state_manager.ts +100 -0
  22. package/internal/framework/_typescript/client/src/static_route_defs/route_def_helpers.ts +22 -0
  23. package/internal/framework/_typescript/client/src/ui_lib_impl_helpers/link_components.ts +131 -0
  24. package/internal/framework/_typescript/client/src/ui_lib_impl_helpers/route_components.ts +56 -0
  25. package/internal/framework/_typescript/client/src/ui_lib_impl_helpers/typed_navigate.ts +58 -0
  26. package/internal/framework/_typescript/client/src/utils/errors.ts +10 -0
  27. package/internal/framework/_typescript/client/src/utils/logging.ts +7 -0
  28. package/internal/framework/_typescript/client/src/vorma_app_helpers/vorma_app_helpers.ts +290 -0
  29. package/internal/framework/_typescript/client/src/vorma_ctx/vorma_ctx.ts +128 -0
  30. package/internal/framework/_typescript/client/src/window_focus_revalidation/window_focus_revalidation.ts +32 -0
  31. package/internal/framework/_typescript/client/tsconfig.json +3 -0
  32. package/internal/framework/_typescript/create/main.ts +378 -0
  33. package/internal/framework/_typescript/create/package.json +33 -0
  34. package/internal/framework/_typescript/create/pnpm-lock.yaml +70 -0
  35. package/internal/framework/_typescript/create/tsconfig.json +3 -0
  36. package/internal/framework/_typescript/preact/index.tsx +10 -0
  37. package/internal/framework/_typescript/preact/src/helpers.ts +113 -0
  38. package/internal/framework/_typescript/preact/src/link.tsx +107 -0
  39. package/internal/framework/_typescript/preact/src/preact.tsx +191 -0
  40. package/internal/framework/_typescript/preact/tsconfig.json +7 -0
  41. package/internal/framework/_typescript/react/index.tsx +10 -0
  42. package/internal/framework/_typescript/react/src/helpers.ts +118 -0
  43. package/internal/framework/_typescript/react/src/link.tsx +115 -0
  44. package/internal/framework/_typescript/react/src/react.tsx +299 -0
  45. package/internal/framework/_typescript/react/tsconfig.json +6 -0
  46. package/internal/framework/_typescript/solid/index.tsx +10 -0
  47. package/internal/framework/_typescript/solid/src/helpers.ts +114 -0
  48. package/internal/framework/_typescript/solid/src/link.tsx +104 -0
  49. package/internal/framework/_typescript/solid/src/solid.tsx +204 -0
  50. package/internal/framework/_typescript/solid/tsconfig.json +7 -0
  51. package/internal/framework/_typescript/vite/tsconfig.json +3 -0
  52. package/internal/framework/_typescript/vite/vite.ts +93 -0
  53. package/internal/site/frontend/assets/vorma-banner.webp +0 -0
  54. package/kit/_typescript/converters/converters.ts +152 -0
  55. package/kit/_typescript/cookies/cookies.ts +18 -0
  56. package/kit/_typescript/csrf/csrf.ts +10 -0
  57. package/kit/_typescript/debounce/debounce.ts +17 -0
  58. package/kit/_typescript/fmt/fmt.ts +3 -0
  59. package/kit/_typescript/json/deep_equals.ts +54 -0
  60. package/kit/_typescript/json/json.ts +3 -0
  61. package/kit/_typescript/json/search_param_serializer.ts +49 -0
  62. package/kit/_typescript/json/stringify_stable.ts +43 -0
  63. package/kit/_typescript/listeners/listeners.ts +16 -0
  64. package/kit/_typescript/matcher/find_best_match.ts +205 -0
  65. package/kit/_typescript/matcher/find_nested_matches.ts +357 -0
  66. package/kit/_typescript/matcher/parse_segments.ts +30 -0
  67. package/kit/_typescript/matcher/register.ts +271 -0
  68. package/kit/_typescript/theme/theme.ts +177 -0
  69. package/kit/_typescript/tsconfig.json +3 -0
  70. package/kit/_typescript/url/url.ts +132 -0
  71. package/npm_dist/internal/framework/_typescript/client/index.d.ts +17 -0
  72. package/npm_dist/internal/framework/_typescript/client/index.d.ts.map +1 -0
  73. package/npm_dist/internal/framework/_typescript/client/index.js +2489 -0
  74. package/npm_dist/internal/framework/_typescript/client/index.js.map +7 -0
  75. package/npm_dist/internal/framework/_typescript/client/src/asset_manager.d.ts +6 -0
  76. package/npm_dist/internal/framework/_typescript/client/src/asset_manager.d.ts.map +1 -0
  77. package/npm_dist/internal/framework/_typescript/client/src/client.d.ts +119 -0
  78. package/npm_dist/internal/framework/_typescript/client/src/client.d.ts.map +1 -0
  79. package/npm_dist/internal/framework/_typescript/client/src/client_loaders.d.ts +18 -0
  80. package/npm_dist/internal/framework/_typescript/client/src/client_loaders.d.ts.map +1 -0
  81. package/npm_dist/internal/framework/_typescript/client/src/component_loader.d.ts +10 -0
  82. package/npm_dist/internal/framework/_typescript/client/src/component_loader.d.ts.map +1 -0
  83. package/npm_dist/internal/framework/_typescript/client/src/error_boundary.d.ts +3 -0
  84. package/npm_dist/internal/framework/_typescript/client/src/error_boundary.d.ts.map +1 -0
  85. package/npm_dist/internal/framework/_typescript/client/src/events.d.ts +26 -0
  86. package/npm_dist/internal/framework/_typescript/client/src/events.d.ts.map +1 -0
  87. package/npm_dist/internal/framework/_typescript/client/src/global_loading_indicator/global_loading_indicator.d.ts +12 -0
  88. package/npm_dist/internal/framework/_typescript/client/src/global_loading_indicator/global_loading_indicator.d.ts.map +1 -0
  89. package/npm_dist/internal/framework/_typescript/client/src/hard_reload.d.ts +2 -0
  90. package/npm_dist/internal/framework/_typescript/client/src/hard_reload.d.ts.map +1 -0
  91. package/npm_dist/internal/framework/_typescript/client/src/head_elements/head_elements.d.ts +7 -0
  92. package/npm_dist/internal/framework/_typescript/client/src/head_elements/head_elements.d.ts.map +1 -0
  93. package/npm_dist/internal/framework/_typescript/client/src/history/history.d.ts +14 -0
  94. package/npm_dist/internal/framework/_typescript/client/src/history/history.d.ts.map +1 -0
  95. package/npm_dist/internal/framework/_typescript/client/src/history/npm_history_types.d.ts +84 -0
  96. package/npm_dist/internal/framework/_typescript/client/src/history/npm_history_types.d.ts.map +1 -0
  97. package/npm_dist/internal/framework/_typescript/client/src/hmr/hmr.d.ts +3 -0
  98. package/npm_dist/internal/framework/_typescript/client/src/hmr/hmr.d.ts.map +1 -0
  99. package/npm_dist/internal/framework/_typescript/client/src/init_client.d.ts +9 -0
  100. package/npm_dist/internal/framework/_typescript/client/src/init_client.d.ts.map +1 -0
  101. package/npm_dist/internal/framework/_typescript/client/src/links.d.ts +33 -0
  102. package/npm_dist/internal/framework/_typescript/client/src/links.d.ts.map +1 -0
  103. package/npm_dist/internal/framework/_typescript/client/src/redirects/redirects.d.ts +26 -0
  104. package/npm_dist/internal/framework/_typescript/client/src/redirects/redirects.d.ts.map +1 -0
  105. package/npm_dist/internal/framework/_typescript/client/src/rendering.d.ts +18 -0
  106. package/npm_dist/internal/framework/_typescript/client/src/rendering.d.ts.map +1 -0
  107. package/npm_dist/internal/framework/_typescript/client/src/resolve_public_href.d.ts +2 -0
  108. package/npm_dist/internal/framework/_typescript/client/src/resolve_public_href.d.ts.map +1 -0
  109. package/npm_dist/internal/framework/_typescript/client/src/scroll_state_manager.d.ts +22 -0
  110. package/npm_dist/internal/framework/_typescript/client/src/scroll_state_manager.d.ts.map +1 -0
  111. package/npm_dist/internal/framework/_typescript/client/src/static_route_defs/route_def_helpers.d.ts +12 -0
  112. package/npm_dist/internal/framework/_typescript/client/src/static_route_defs/route_def_helpers.d.ts.map +1 -0
  113. package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/link_components.d.ts +28 -0
  114. package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/link_components.d.ts.map +1 -0
  115. package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/route_components.d.ts +18 -0
  116. package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/route_components.d.ts.map +1 -0
  117. package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/typed_navigate.d.ts +11 -0
  118. package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/typed_navigate.d.ts.map +1 -0
  119. package/npm_dist/internal/framework/_typescript/client/src/utils/errors.d.ts +3 -0
  120. package/npm_dist/internal/framework/_typescript/client/src/utils/errors.d.ts.map +1 -0
  121. package/npm_dist/internal/framework/_typescript/client/src/utils/logging.d.ts +3 -0
  122. package/npm_dist/internal/framework/_typescript/client/src/utils/logging.d.ts.map +1 -0
  123. package/npm_dist/internal/framework/_typescript/client/src/vorma_app_helpers/vorma_app_helpers.d.ts +119 -0
  124. package/npm_dist/internal/framework/_typescript/client/src/vorma_app_helpers/vorma_app_helpers.d.ts.map +1 -0
  125. package/npm_dist/internal/framework/_typescript/client/src/vorma_ctx/vorma_ctx.d.ts +88 -0
  126. package/npm_dist/internal/framework/_typescript/client/src/vorma_ctx/vorma_ctx.d.ts.map +1 -0
  127. package/npm_dist/internal/framework/_typescript/client/src/window_focus_revalidation/window_focus_revalidation.d.ts +10 -0
  128. package/npm_dist/internal/framework/_typescript/client/src/window_focus_revalidation/window_focus_revalidation.d.ts.map +1 -0
  129. package/npm_dist/internal/framework/_typescript/create/main.d.ts +3 -0
  130. package/npm_dist/internal/framework/_typescript/create/main.d.ts.map +1 -0
  131. package/npm_dist/internal/framework/_typescript/preact/index.d.ts +4 -0
  132. package/npm_dist/internal/framework/_typescript/preact/index.d.ts.map +1 -0
  133. package/npm_dist/internal/framework/_typescript/preact/index.js +283 -0
  134. package/npm_dist/internal/framework/_typescript/preact/index.js.map +7 -0
  135. package/npm_dist/internal/framework/_typescript/preact/src/helpers.d.ts +21 -0
  136. package/npm_dist/internal/framework/_typescript/preact/src/helpers.d.ts.map +1 -0
  137. package/npm_dist/internal/framework/_typescript/preact/src/link.d.ts +11 -0
  138. package/npm_dist/internal/framework/_typescript/preact/src/link.d.ts.map +1 -0
  139. package/npm_dist/internal/framework/_typescript/preact/src/preact.d.ts +21 -0
  140. package/npm_dist/internal/framework/_typescript/preact/src/preact.d.ts.map +1 -0
  141. package/npm_dist/internal/framework/_typescript/react/index.d.ts +4 -0
  142. package/npm_dist/internal/framework/_typescript/react/index.d.ts.map +1 -0
  143. package/npm_dist/internal/framework/_typescript/react/index.js +370 -0
  144. package/npm_dist/internal/framework/_typescript/react/index.js.map +7 -0
  145. package/npm_dist/internal/framework/_typescript/react/src/helpers.d.ts +21 -0
  146. package/npm_dist/internal/framework/_typescript/react/src/helpers.d.ts.map +1 -0
  147. package/npm_dist/internal/framework/_typescript/react/src/link.d.ts +11 -0
  148. package/npm_dist/internal/framework/_typescript/react/src/link.d.ts.map +1 -0
  149. package/npm_dist/internal/framework/_typescript/react/src/react.d.ts +20 -0
  150. package/npm_dist/internal/framework/_typescript/react/src/react.d.ts.map +1 -0
  151. package/npm_dist/internal/framework/_typescript/solid/index.d.ts +4 -0
  152. package/npm_dist/internal/framework/_typescript/solid/index.d.ts.map +1 -0
  153. package/npm_dist/internal/framework/_typescript/solid/index.js +314 -0
  154. package/npm_dist/internal/framework/_typescript/solid/index.js.map +7 -0
  155. package/npm_dist/internal/framework/_typescript/solid/src/helpers.d.ts +22 -0
  156. package/npm_dist/internal/framework/_typescript/solid/src/helpers.d.ts.map +1 -0
  157. package/npm_dist/internal/framework/_typescript/solid/src/link.d.ts +11 -0
  158. package/npm_dist/internal/framework/_typescript/solid/src/link.d.ts.map +1 -0
  159. package/npm_dist/internal/framework/_typescript/solid/src/solid.d.ts +22 -0
  160. package/npm_dist/internal/framework/_typescript/solid/src/solid.d.ts.map +1 -0
  161. package/npm_dist/internal/framework/_typescript/vite/vite.d.ts +11 -0
  162. package/npm_dist/internal/framework/_typescript/vite/vite.d.ts.map +1 -0
  163. package/npm_dist/internal/framework/_typescript/vite/vite.js +82 -0
  164. package/npm_dist/internal/framework/_typescript/vite/vite.js.map +7 -0
  165. package/npm_dist/kit/_typescript/chunk-YBAPNBS2.js +202 -0
  166. package/npm_dist/kit/_typescript/chunk-YBAPNBS2.js.map +7 -0
  167. package/npm_dist/kit/_typescript/converters/converters.d.ts +26 -0
  168. package/npm_dist/kit/_typescript/converters/converters.d.ts.map +1 -0
  169. package/npm_dist/kit/_typescript/converters/converters.js +99 -0
  170. package/npm_dist/kit/_typescript/converters/converters.js.map +7 -0
  171. package/npm_dist/kit/_typescript/cookies/cookies.d.ts +13 -0
  172. package/npm_dist/kit/_typescript/cookies/cookies.d.ts.map +1 -0
  173. package/npm_dist/kit/_typescript/cookies/cookies.js +13 -0
  174. package/npm_dist/kit/_typescript/cookies/cookies.js.map +7 -0
  175. package/npm_dist/kit/_typescript/csrf/csrf.d.ts +5 -0
  176. package/npm_dist/kit/_typescript/csrf/csrf.d.ts.map +1 -0
  177. package/npm_dist/kit/_typescript/csrf/csrf.js +11 -0
  178. package/npm_dist/kit/_typescript/csrf/csrf.js.map +7 -0
  179. package/npm_dist/kit/_typescript/debounce/debounce.d.ts +4 -0
  180. package/npm_dist/kit/_typescript/debounce/debounce.d.ts.map +1 -0
  181. package/npm_dist/kit/_typescript/debounce/debounce.js +16 -0
  182. package/npm_dist/kit/_typescript/debounce/debounce.js.map +7 -0
  183. package/npm_dist/kit/_typescript/fmt/fmt.d.ts +2 -0
  184. package/npm_dist/kit/_typescript/fmt/fmt.d.ts.map +1 -0
  185. package/npm_dist/kit/_typescript/fmt/fmt.js +8 -0
  186. package/npm_dist/kit/_typescript/fmt/fmt.js.map +7 -0
  187. package/npm_dist/kit/_typescript/json/deep_equals.d.ts +7 -0
  188. package/npm_dist/kit/_typescript/json/deep_equals.d.ts.map +1 -0
  189. package/npm_dist/kit/_typescript/json/json.d.ts +4 -0
  190. package/npm_dist/kit/_typescript/json/json.d.ts.map +1 -0
  191. package/npm_dist/kit/_typescript/json/json.js +110 -0
  192. package/npm_dist/kit/_typescript/json/json.js.map +7 -0
  193. package/npm_dist/kit/_typescript/json/search_param_serializer.d.ts +2 -0
  194. package/npm_dist/kit/_typescript/json/search_param_serializer.d.ts.map +1 -0
  195. package/npm_dist/kit/_typescript/json/stringify_stable.d.ts +7 -0
  196. package/npm_dist/kit/_typescript/json/stringify_stable.d.ts.map +1 -0
  197. package/npm_dist/kit/_typescript/listeners/listeners.d.ts +2 -0
  198. package/npm_dist/kit/_typescript/listeners/listeners.d.ts.map +1 -0
  199. package/npm_dist/kit/_typescript/listeners/listeners.js +20 -0
  200. package/npm_dist/kit/_typescript/listeners/listeners.js.map +7 -0
  201. package/npm_dist/kit/_typescript/matcher/find_best_match.d.ts +10 -0
  202. package/npm_dist/kit/_typescript/matcher/find_best_match.d.ts.map +1 -0
  203. package/npm_dist/kit/_typescript/matcher/find_best_match.js +146 -0
  204. package/npm_dist/kit/_typescript/matcher/find_best_match.js.map +7 -0
  205. package/npm_dist/kit/_typescript/matcher/find_nested_matches.d.ts +14 -0
  206. package/npm_dist/kit/_typescript/matcher/find_nested_matches.d.ts.map +1 -0
  207. package/npm_dist/kit/_typescript/matcher/find_nested_matches.js +248 -0
  208. package/npm_dist/kit/_typescript/matcher/find_nested_matches.js.map +7 -0
  209. package/npm_dist/kit/_typescript/matcher/parse_segments.d.ts +2 -0
  210. package/npm_dist/kit/_typescript/matcher/parse_segments.d.ts.map +1 -0
  211. package/npm_dist/kit/_typescript/matcher/register.d.ts +54 -0
  212. package/npm_dist/kit/_typescript/matcher/register.d.ts.map +1 -0
  213. package/npm_dist/kit/_typescript/matcher/register.js +21 -0
  214. package/npm_dist/kit/_typescript/matcher/register.js.map +7 -0
  215. package/npm_dist/kit/_typescript/theme/theme.d.ts +24 -0
  216. package/npm_dist/kit/_typescript/theme/theme.d.ts.map +1 -0
  217. package/npm_dist/kit/_typescript/theme/theme.js +133 -0
  218. package/npm_dist/kit/_typescript/theme/theme.js.map +7 -0
  219. package/npm_dist/kit/_typescript/url/url.d.ts +30 -0
  220. package/npm_dist/kit/_typescript/url/url.d.ts.map +1 -0
  221. package/npm_dist/kit/_typescript/url/url.js +100 -0
  222. package/npm_dist/kit/_typescript/url/url.js.map +7 -0
  223. package/package.json +135 -3
  224. package/tsconfig.base.json +17 -0
  225. package/index.js +0 -1
@@ -0,0 +1,131 @@
1
+ import { __getPrefetchHandlers, __makeLinkOnClickFn } from "../links.ts";
2
+ import { __resolvePath } from "../vorma_app_helpers/vorma_app_helpers.ts";
3
+ import { __vormaClientGlobal } from "../vorma_ctx/vorma_ctx.ts";
4
+
5
+ export type VormaLinkPropsBase<LinkOnClickCallback> = {
6
+ href?: string;
7
+ prefetch?: "intent";
8
+ prefetchDelayMs?: number;
9
+ beforeBegin?: LinkOnClickCallback;
10
+ beforeRender?: LinkOnClickCallback;
11
+ afterRender?: LinkOnClickCallback;
12
+ scrollToTop?: boolean;
13
+ replace?: boolean;
14
+ state?: unknown;
15
+ };
16
+
17
+ function linkPropsToPrefetchObj<LinkOnClickCallback>(
18
+ props: VormaLinkPropsBase<LinkOnClickCallback>,
19
+ ) {
20
+ if (!props.href || props.prefetch !== "intent") {
21
+ return undefined;
22
+ }
23
+
24
+ return __getPrefetchHandlers({
25
+ href: props.href,
26
+ delayMs: props.prefetchDelayMs,
27
+ beforeBegin: props.beforeBegin as any,
28
+ beforeRender: props.beforeRender as any,
29
+ afterRender: props.afterRender as any,
30
+ scrollToTop: props.scrollToTop,
31
+ replace: props.replace,
32
+ state: props.state,
33
+ });
34
+ }
35
+
36
+ function linkPropsToOnClickFn<LinkOnClickCallback>(
37
+ props: VormaLinkPropsBase<LinkOnClickCallback>,
38
+ ) {
39
+ return __makeLinkOnClickFn({
40
+ beforeBegin: props.beforeBegin as any,
41
+ beforeRender: props.beforeRender as any,
42
+ afterRender: props.afterRender as any,
43
+ scrollToTop: props.scrollToTop,
44
+ replace: props.replace,
45
+ state: props.state,
46
+ });
47
+ }
48
+
49
+ type handlerKeys = {
50
+ onPointerEnter: string;
51
+ onFocus: string;
52
+ onPointerLeave: string;
53
+ onBlur: string;
54
+ onTouchCancel: string;
55
+ onClick: string;
56
+ };
57
+
58
+ const standardCamelHandlerKeys = {
59
+ onPointerEnter: "onPointerEnter",
60
+ onFocus: "onFocus",
61
+ onPointerLeave: "onPointerLeave",
62
+ onBlur: "onBlur",
63
+ onTouchCancel: "onTouchCancel",
64
+ onClick: "onClick",
65
+ } satisfies handlerKeys;
66
+
67
+ export function __makeFinalLinkProps<LinkOnClickCallback>(
68
+ props: VormaLinkPropsBase<LinkOnClickCallback>,
69
+ keys: {
70
+ onPointerEnter: string;
71
+ onFocus: string;
72
+ onPointerLeave: string;
73
+ onBlur: string;
74
+ onTouchCancel: string;
75
+ onClick: string;
76
+ } = standardCamelHandlerKeys,
77
+ ) {
78
+ const prefetchObj = linkPropsToPrefetchObj(props);
79
+
80
+ return {
81
+ dataExternal: prefetchObj?.isExternal || undefined,
82
+ onPointerEnter: (e: any) => {
83
+ prefetchObj?.start(e);
84
+ if (isFn((props as any)[keys.onPointerEnter])) {
85
+ (props as any)[keys.onPointerEnter](e);
86
+ }
87
+ },
88
+ onFocus: (e: any) => {
89
+ prefetchObj?.start(e);
90
+ if (isFn((props as any)[keys.onFocus])) {
91
+ (props as any)[keys.onFocus](e);
92
+ }
93
+ },
94
+ onPointerLeave: (e: any) => {
95
+ // we don't want to stop on a touch device, because this triggers
96
+ // even when the user "clicks" on the link for some reason
97
+ if (!__vormaClientGlobal.get("isTouchDevice")) {
98
+ prefetchObj?.stop();
99
+ }
100
+ if (isFn((props as any)[keys.onPointerLeave])) {
101
+ (props as any)[keys.onPointerLeave](e);
102
+ }
103
+ },
104
+ onBlur: (e: any) => {
105
+ prefetchObj?.stop();
106
+ if (isFn((props as any)[keys.onBlur])) {
107
+ (props as any)[keys.onBlur](e);
108
+ }
109
+ },
110
+ onTouchCancel: (e: any) => {
111
+ prefetchObj?.stop();
112
+ if (isFn((props as any)[keys.onTouchCancel])) {
113
+ (props as any)[keys.onTouchCancel](e);
114
+ }
115
+ },
116
+ onClick: async (e: any) => {
117
+ if (isFn((props as any)[keys.onClick])) {
118
+ (props as any)[keys.onClick](e);
119
+ }
120
+ if (prefetchObj) {
121
+ await prefetchObj.onClick(e);
122
+ } else {
123
+ await linkPropsToOnClickFn(props)(e);
124
+ }
125
+ },
126
+ };
127
+ }
128
+
129
+ function isFn(fn: any): fn is (...args: Array<any>) => any {
130
+ return typeof fn === "function";
131
+ }
@@ -0,0 +1,56 @@
1
+ import {
2
+ __resolvePath,
3
+ type VormaAppBase,
4
+ type VormaLoaderPattern,
5
+ type VormaRouteParams,
6
+ } from "../vorma_app_helpers/vorma_app_helpers.ts";
7
+ import {
8
+ __vormaClientGlobal,
9
+ type getRouterData,
10
+ } from "../vorma_ctx/vorma_ctx.ts";
11
+
12
+ export type VormaRoutePropsGeneric<
13
+ JSXElement,
14
+ App extends VormaAppBase,
15
+ Pattern extends VormaLoaderPattern<App> = VormaLoaderPattern<App>,
16
+ > = {
17
+ idx: number;
18
+ Outlet: (props: Record<string, any>) => JSXElement;
19
+ __phantom_pattern: Pattern;
20
+ } & Record<string, any>;
21
+
22
+ export type VormaRouteGeneric<
23
+ JSXElement,
24
+ App extends VormaAppBase,
25
+ Pattern extends VormaLoaderPattern<App> = VormaLoaderPattern<App>,
26
+ > = (props: VormaRoutePropsGeneric<JSXElement, App, Pattern>) => JSXElement;
27
+
28
+ export type ParamsForPattern<
29
+ App extends VormaAppBase,
30
+ Pattern extends VormaLoaderPattern<App>,
31
+ > = VormaRouteParams<App, Pattern>;
32
+
33
+ type BaseRouterData<RootData, Params extends string> = ReturnType<
34
+ typeof getRouterData<RootData, Record<Params, string>>
35
+ >;
36
+
37
+ type Wrapper<UseAccessor extends boolean, T> = UseAccessor extends false
38
+ ? T
39
+ : () => T;
40
+
41
+ export type UseRouterDataFunction<
42
+ App extends VormaAppBase,
43
+ UseAccessor extends boolean = false,
44
+ > = {
45
+ <Pattern extends VormaLoaderPattern<App>>(
46
+ props: VormaRoutePropsGeneric<any, App, Pattern>,
47
+ ): Wrapper<
48
+ UseAccessor,
49
+ BaseRouterData<App["rootData"], ParamsForPattern<App, Pattern>>
50
+ >;
51
+ <Pattern extends VormaLoaderPattern<App>>(): Wrapper<
52
+ UseAccessor,
53
+ BaseRouterData<App["rootData"], ParamsForPattern<App, Pattern>>
54
+ >;
55
+ (): Wrapper<UseAccessor, BaseRouterData<App["rootData"], string>>;
56
+ };
@@ -0,0 +1,58 @@
1
+ import { vormaNavigate } from "../client.ts";
2
+ import {
3
+ __resolvePath,
4
+ type ExtractApp,
5
+ type PermissivePatternBasedProps,
6
+ type VormaAppBase,
7
+ type VormaAppConfig,
8
+ type VormaLoaderPattern,
9
+ } from "../vorma_app_helpers/vorma_app_helpers.ts";
10
+ import { __vormaClientGlobal } from "../vorma_ctx/vorma_ctx.ts";
11
+
12
+ type TypedNavigateOptions<
13
+ App extends VormaAppBase,
14
+ Pattern extends VormaLoaderPattern<App>,
15
+ > = PermissivePatternBasedProps<App, Pattern> & {
16
+ replace?: boolean;
17
+ scrollToTop?: boolean;
18
+ search?: string;
19
+ hash?: string;
20
+ state?: unknown;
21
+ };
22
+
23
+ export function makeTypedNavigate<C extends VormaAppConfig>(vormaAppConfig: C) {
24
+ type App = ExtractApp<C>;
25
+
26
+ return async function typedNavigate<
27
+ Pattern extends VormaLoaderPattern<App>,
28
+ >(options: TypedNavigateOptions<App, Pattern>): Promise<void> {
29
+ const {
30
+ pattern,
31
+ params,
32
+ splatValues,
33
+ replace,
34
+ scrollToTop,
35
+ search,
36
+ hash,
37
+ state,
38
+ } = options as any;
39
+
40
+ const href = __resolvePath({
41
+ vormaAppConfig,
42
+ type: "loader",
43
+ props: {
44
+ pattern,
45
+ ...(params && { params }),
46
+ ...(splatValues && { splatValues }),
47
+ },
48
+ });
49
+
50
+ return vormaNavigate(href, {
51
+ replace,
52
+ scrollToTop,
53
+ search,
54
+ hash,
55
+ state,
56
+ });
57
+ };
58
+ }
@@ -0,0 +1,10 @@
1
+ import { logError } from "./logging.ts";
2
+
3
+ export function isAbortError(error: unknown) {
4
+ return error instanceof Error && error.name === "AbortError";
5
+ }
6
+
7
+ export function panic(msg?: string): never {
8
+ logError("Panic");
9
+ throw new Error(msg ?? "panic");
10
+ }
@@ -0,0 +1,7 @@
1
+ export function logInfo(message?: any, ...optionalParams: Array<any>) {
2
+ console.log("Vorma:", message, ...optionalParams);
3
+ }
4
+
5
+ export function logError(message?: any, ...optionalParams: Array<any>) {
6
+ console.error("Vorma:", message, ...optionalParams);
7
+ }
@@ -0,0 +1,290 @@
1
+ import { serializeToSearchParams } from "vorma/kit/json";
2
+ import type { SubmitOptions } from "../client.ts";
3
+
4
+ export type VormaAppConfig = {
5
+ actionsRouterMountRoot: string;
6
+ actionsDynamicRune: string;
7
+ actionsSplatRune: string;
8
+ loadersDynamicRune: string;
9
+ loadersSplatRune: string;
10
+ loadersExplicitIndexSegment: string;
11
+ __phantom?: any;
12
+ };
13
+
14
+ export type VormaAppBase = {
15
+ routes: readonly any[];
16
+ appConfig: VormaAppConfig;
17
+ rootData: any;
18
+ };
19
+
20
+ export type ExtractApp<C extends VormaAppConfig> = C["__phantom"];
21
+
22
+ type RouteByType<App extends VormaAppBase, T extends string> = Extract<
23
+ App["routes"][number],
24
+ { _type: T }
25
+ >;
26
+
27
+ type RouteByPattern<Routes, P> = Extract<Routes, { pattern: P }>;
28
+
29
+ type VormaLoader<App extends VormaAppBase> = RouteByType<App, "loader">;
30
+ type VormaQuery<App extends VormaAppBase> = RouteByType<App, "query">;
31
+ type VormaMutation<App extends VormaAppBase> = RouteByType<App, "mutation">;
32
+
33
+ // Pattern types
34
+ export type VormaLoaderPattern<App extends VormaAppBase> =
35
+ VormaLoader<App>["pattern"];
36
+ export type VormaQueryPattern<App extends VormaAppBase> =
37
+ VormaQuery<App>["pattern"];
38
+ export type VormaMutationPattern<App extends VormaAppBase> =
39
+ VormaMutation<App>["pattern"];
40
+
41
+ // IO types
42
+ export type VormaLoaderOutput<
43
+ App extends VormaAppBase,
44
+ P extends VormaLoaderPattern<App>,
45
+ > =
46
+ RouteByPattern<VormaLoader<App>, P> extends { phantomOutputType: infer T }
47
+ ? T
48
+ : null | undefined;
49
+
50
+ export type VormaQueryInput<
51
+ App extends VormaAppBase,
52
+ P extends VormaQueryPattern<App>,
53
+ > =
54
+ RouteByPattern<VormaQuery<App>, P> extends { phantomInputType: infer T }
55
+ ? T
56
+ : null | undefined;
57
+
58
+ export type VormaQueryOutput<
59
+ App extends VormaAppBase,
60
+ P extends VormaQueryPattern<App>,
61
+ > =
62
+ RouteByPattern<VormaQuery<App>, P> extends { phantomOutputType: infer T }
63
+ ? T
64
+ : null | undefined;
65
+
66
+ export type VormaMutationInput<
67
+ App extends VormaAppBase,
68
+ P extends VormaMutationPattern<App>,
69
+ > =
70
+ RouteByPattern<VormaMutation<App>, P> extends { phantomInputType: infer T }
71
+ ? T
72
+ : null | undefined;
73
+
74
+ export type VormaMutationOutput<
75
+ App extends VormaAppBase,
76
+ P extends VormaMutationPattern<App>,
77
+ > =
78
+ RouteByPattern<VormaMutation<App>, P> extends { phantomOutputType: infer T }
79
+ ? T
80
+ : null | undefined;
81
+
82
+ export type VormaMutationMethod<
83
+ App extends VormaAppBase,
84
+ P extends VormaMutationPattern<App>,
85
+ > =
86
+ RouteByPattern<VormaMutation<App>, P> extends { method: infer M }
87
+ ? M extends string
88
+ ? M
89
+ : "POST"
90
+ : "POST";
91
+
92
+ // Route metadata
93
+ type RouteMetadata<App extends VormaAppBase, P extends string> = Extract<
94
+ App["routes"][number],
95
+ { pattern: P }
96
+ >;
97
+
98
+ export type GetParams<App extends VormaAppBase, P extends string> =
99
+ RouteMetadata<App, P> extends { params: ReadonlyArray<infer Params> }
100
+ ? Params extends string
101
+ ? Params
102
+ : never
103
+ : never;
104
+
105
+ export type VormaRouteParams<
106
+ App extends VormaAppBase,
107
+ P extends VormaLoaderPattern<App>,
108
+ > = GetParams<App, P>;
109
+
110
+ export type HasParams<App extends VormaAppBase, P extends string> =
111
+ GetParams<App, P> extends never ? false : true;
112
+
113
+ export type IsSplat<App extends VormaAppBase, P extends string> =
114
+ RouteMetadata<App, P> extends { isSplat: true } ? true : false;
115
+
116
+ export type IsEmptyInput<T> = [T] extends [null | undefined | never]
117
+ ? true
118
+ : false;
119
+
120
+ // Pattern-based props composition
121
+ type ConditionalParams<App extends VormaAppBase, P extends string> =
122
+ HasParams<App, P> extends true
123
+ ? { params: { [K in GetParams<App, P>]: string } }
124
+ : {};
125
+
126
+ type ConditionalSplat<App extends VormaAppBase, P extends string> =
127
+ IsSplat<App, P> extends true ? { splatValues: Array<string> } : {};
128
+
129
+ export type PatternBasedProps<App extends VormaAppBase, P extends string> = {
130
+ pattern: P;
131
+ } & ConditionalParams<App, P> &
132
+ ConditionalSplat<App, P>;
133
+
134
+ export type PermissivePatternBasedProps<
135
+ App extends VormaAppBase,
136
+ P extends VormaLoaderPattern<App>,
137
+ > = {
138
+ pattern: PermissiveLoaderPattern<App, P>;
139
+ } & ConditionalParams<App, P> &
140
+ ConditionalSplat<App, P>;
141
+
142
+ type PermissiveLoaderPattern<
143
+ App extends VormaAppBase,
144
+ P extends VormaLoaderPattern<App>,
145
+ > = P extends `${infer Prefix}/${App["appConfig"]["loadersExplicitIndexSegment"]}`
146
+ ? P | (Prefix extends "" ? "/" : Prefix)
147
+ : P;
148
+
149
+ export type VormaRoutePropsGeneric<
150
+ JSXElement,
151
+ App extends VormaAppBase,
152
+ P extends VormaLoaderPattern<App>,
153
+ > = {
154
+ idx: number;
155
+ Outlet: (props: Record<string, any>) => JSXElement;
156
+ __phantom_pattern: P;
157
+ } & Record<string, any>;
158
+
159
+ /////////////////////////////////////////////////////////////////////
160
+ /////// API CLIENT HELPERS
161
+ /////////////////////////////////////////////////////////////////////
162
+
163
+ type Props = PatternBasedProps<any, string> & {
164
+ options?: SubmitOptions;
165
+ requestInit?: RequestInit;
166
+ input?: any;
167
+ };
168
+
169
+ type APIClientHelperOpts = {
170
+ vormaAppConfig: VormaAppConfig;
171
+ type: "loader" | "query" | "mutation";
172
+ props: Props;
173
+ };
174
+
175
+ export type VormaQueryProps<
176
+ App extends VormaAppBase,
177
+ P extends VormaQueryPattern<App>,
178
+ > = (PatternBasedProps<App, P> & {
179
+ options?: SubmitOptions;
180
+ requestInit?: Omit<RequestInit, "method"> & { method?: "GET" };
181
+ }) &
182
+ (IsEmptyInput<VormaQueryInput<App, P>> extends true
183
+ ? { input?: VormaQueryInput<App, P> }
184
+ : { input: VormaQueryInput<App, P> });
185
+
186
+ export type VormaMutationProps<
187
+ App extends VormaAppBase,
188
+ P extends VormaMutationPattern<App>,
189
+ > = PatternBasedProps<App, P> & {
190
+ options?: SubmitOptions;
191
+ } & (VormaMutationMethod<App, P> extends "POST"
192
+ ? { requestInit?: Omit<RequestInit, "method"> & { method?: "POST" } }
193
+ : {
194
+ requestInit: RequestInit & {
195
+ method: VormaMutationMethod<App, P>;
196
+ };
197
+ }) &
198
+ (IsEmptyInput<VormaMutationInput<App, P>> extends true
199
+ ? { input?: VormaMutationInput<App, P> }
200
+ : { input: VormaMutationInput<App, P> });
201
+
202
+ export function buildQueryURL(
203
+ vormaAppConfig: VormaAppConfig,
204
+ props: Props,
205
+ ): URL {
206
+ return buildURL({ vormaAppConfig, props, type: "query" });
207
+ }
208
+
209
+ export function buildMutationURL(
210
+ vormaAppConfig: VormaAppConfig,
211
+ props: Props,
212
+ ): URL {
213
+ return buildURL({ vormaAppConfig, props, type: "mutation" });
214
+ }
215
+
216
+ export function resolveBody(props: Props): BodyInit | null | undefined {
217
+ const { input } = props;
218
+ if (
219
+ input == null ||
220
+ typeof input === "string" ||
221
+ input instanceof Blob ||
222
+ input instanceof FormData ||
223
+ input instanceof URLSearchParams ||
224
+ input instanceof ReadableStream ||
225
+ input instanceof ArrayBuffer ||
226
+ ArrayBuffer.isView(input)
227
+ ) {
228
+ return input;
229
+ }
230
+ return JSON.stringify(input);
231
+ }
232
+
233
+ function buildURL(opts: APIClientHelperOpts): URL {
234
+ const base_path = stripTrailingSlash(
235
+ opts.vormaAppConfig.actionsRouterMountRoot,
236
+ );
237
+ const resolved_path = __resolvePath(opts);
238
+ const url = new URL(base_path + resolved_path, getCurrentOrigin());
239
+
240
+ if (opts.type === "query" && opts.props.input) {
241
+ url.search = serializeToSearchParams(opts.props.input).toString();
242
+ }
243
+
244
+ return url;
245
+ }
246
+
247
+ export function __resolvePath(opts: APIClientHelperOpts): string {
248
+ const { props, vormaAppConfig } = opts;
249
+ let path = props.pattern;
250
+
251
+ let dynamicParamPrefixRune = vormaAppConfig.actionsDynamicRune;
252
+ let splatSegmentRune = vormaAppConfig.actionsSplatRune;
253
+
254
+ if (opts.type === "loader") {
255
+ dynamicParamPrefixRune = vormaAppConfig.loadersDynamicRune;
256
+ splatSegmentRune = vormaAppConfig.loadersSplatRune;
257
+ }
258
+
259
+ if ("params" in props && props.params) {
260
+ for (const [key, value] of Object.entries(props.params)) {
261
+ path = path.replace(
262
+ `${dynamicParamPrefixRune}${key}`,
263
+ String(value),
264
+ );
265
+ }
266
+ }
267
+
268
+ if ("splatValues" in props && props.splatValues) {
269
+ const splatPath = (props.splatValues as Array<string>).join("/");
270
+ path = path.replace(splatSegmentRune, splatPath);
271
+ }
272
+
273
+ // Strip explicit index segment
274
+ if (opts.type === "loader" && vormaAppConfig.loadersExplicitIndexSegment) {
275
+ const indexSegment = `/${vormaAppConfig.loadersExplicitIndexSegment}`;
276
+ if (path.endsWith(indexSegment)) {
277
+ path = path.slice(0, -indexSegment.length) || "/";
278
+ }
279
+ }
280
+
281
+ return path;
282
+ }
283
+
284
+ function getCurrentOrigin(): string {
285
+ return new URL(window.location.href).origin;
286
+ }
287
+
288
+ function stripTrailingSlash(path: string): string {
289
+ return path.endsWith("/") ? path.slice(0, -1) : path;
290
+ }
@@ -0,0 +1,128 @@
1
+ import type { PatternRegistry } from "vorma/kit/matcher/register";
2
+ import type { VormaAppConfig } from "../vorma_app_helpers/vorma_app_helpers.ts";
3
+
4
+ export type HeadEl = {
5
+ tag?: string;
6
+ attributesKnownSafe?: Record<string, string>;
7
+ booleanAttributes?: Array<string>;
8
+ dangerousInnerHTML?: string;
9
+ };
10
+
11
+ type Meta = {
12
+ title: HeadEl | null | undefined;
13
+ metaHeadEls: Array<HeadEl> | null | undefined;
14
+ restHeadEls: Array<HeadEl> | null | undefined;
15
+ };
16
+
17
+ type shared = {
18
+ outermostServerError?: string;
19
+ outermostClientError?: string;
20
+ outermostServerErrorIdx?: number;
21
+ outermostClientErrorIdx?: number;
22
+ outermostError?: string; // derived from above
23
+ outermostErrorIdx?: number; // derived from above
24
+
25
+ matchedPatterns: Array<string>;
26
+ loadersData: Array<any>;
27
+ importURLs: Array<string>;
28
+ exportKeys: Array<string>;
29
+ errorExportKeys: string[];
30
+ hasRootData: boolean;
31
+
32
+ params: Record<string, string>;
33
+ splatValues: Array<string>;
34
+
35
+ buildID: string;
36
+
37
+ activeComponents: Array<any> | null;
38
+ activeErrorBoundary?: any;
39
+ };
40
+
41
+ export type GetRouteDataOutput = Omit<shared, "buildID"> &
42
+ Meta & {
43
+ deps: Array<string>;
44
+ cssBundles: Array<string>;
45
+ };
46
+
47
+ export const VORMA_SYMBOL = Symbol.for("__vorma_internal__");
48
+
49
+ export type RouteErrorComponent = (props: { error: string }) => any;
50
+
51
+ export type ClientLoaderAwaitedServerData<RD, LD> = {
52
+ matchedPatterns: string[];
53
+ loaderData: LD;
54
+ rootData: RD;
55
+ buildID: string;
56
+ };
57
+
58
+ export type VormaClientGlobal = shared & {
59
+ isDev: boolean;
60
+ viteDevURL: string;
61
+ publicPathPrefix: string;
62
+ isTouchDevice: boolean;
63
+ patternToWaitFnMap: Record<
64
+ string,
65
+ (props: {
66
+ params: Record<string, string>;
67
+ splatValues: string[];
68
+ serverDataPromise: Promise<ClientLoaderAwaitedServerData<any, any>>;
69
+ signal: AbortSignal;
70
+ }) => Promise<any>
71
+ >;
72
+ clientLoadersData: Array<any>;
73
+ defaultErrorBoundary: RouteErrorComponent;
74
+ useViewTransitions: boolean;
75
+ deploymentID: string;
76
+ vormaAppConfig: VormaAppConfig;
77
+ // SSR'd
78
+ routeManifestURL: string;
79
+ // Fetched at startup -- fine because progressive enhancement
80
+ // and not needed until any given route's second navigation
81
+ // anyway
82
+ routeManifest: Record<string, number> | undefined;
83
+ // built up as we navigate
84
+ clientModuleMap: Record<
85
+ string,
86
+ {
87
+ importURL: string;
88
+ exportKey: string;
89
+ errorExportKey: string;
90
+ }
91
+ >;
92
+ patternRegistry: PatternRegistry;
93
+ };
94
+
95
+ export function __getVormaClientGlobal() {
96
+ const dangerousGlobalThis = globalThis as any;
97
+ function get<K extends keyof VormaClientGlobal>(key: K) {
98
+ return dangerousGlobalThis[VORMA_SYMBOL][key] as VormaClientGlobal[K];
99
+ }
100
+ function set<
101
+ K extends keyof VormaClientGlobal,
102
+ V extends VormaClientGlobal[K],
103
+ >(key: K, value: V) {
104
+ dangerousGlobalThis[VORMA_SYMBOL][key] = value;
105
+ }
106
+ return { get, set };
107
+ }
108
+
109
+ export const __vormaClientGlobal = __getVormaClientGlobal();
110
+
111
+ // to debug ctx in browser, paste this:
112
+ // const vorma_ctx = window[Symbol.for("__vorma_internal__")];
113
+
114
+ export function getRouterData<
115
+ T = any,
116
+ P extends Record<string, string> = Record<string, string>,
117
+ >() {
118
+ const rootData: T = __vormaClientGlobal.get("hasRootData")
119
+ ? __vormaClientGlobal.get("loadersData")[0]
120
+ : null;
121
+ return {
122
+ buildID: __vormaClientGlobal.get("buildID") || "",
123
+ matchedPatterns: __vormaClientGlobal.get("matchedPatterns") || [],
124
+ splatValues: __vormaClientGlobal.get("splatValues") || [],
125
+ params: (__vormaClientGlobal.get("params") || {}) as P,
126
+ rootData,
127
+ };
128
+ }