isomorfeus-preact 10.9.0 → 22.9.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +14 -3
  3. data/README.md +23 -39
  4. data/lib/browser/delegate_native.rb +94 -72
  5. data/lib/browser/document.rb +38 -0
  6. data/lib/browser/element.rb +160 -176
  7. data/lib/browser/event.rb +99 -94
  8. data/lib/browser/history.rb +40 -20
  9. data/lib/browser/location.rb +59 -0
  10. data/lib/browser/window.rb +58 -0
  11. data/lib/data_uri/open_uri.rb +18 -0
  12. data/lib/data_uri/uri.rb +61 -0
  13. data/lib/data_uri.rb +4 -0
  14. data/lib/isomorfeus/preact/config.rb +42 -54
  15. data/lib/isomorfeus/preact/imports.rb +5 -20
  16. data/lib/isomorfeus/preact/ssr.rb +34 -0
  17. data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
  18. data/lib/isomorfeus/preact/version.rb +5 -0
  19. data/lib/isomorfeus/preact/view_helper.rb +72 -0
  20. data/lib/isomorfeus/props/validator.rb +19 -11
  21. data/lib/isomorfeus/top_level.rb +55 -33
  22. data/lib/isomorfeus-preact.rb +78 -103
  23. data/lib/link.rb +52 -0
  24. data/lib/lucid_app.rb +117 -0
  25. data/lib/lucid_component.rb +154 -0
  26. data/lib/nano_css.rb +282 -465
  27. data/lib/preact/component.rb +222 -0
  28. data/lib/preact/component_resolution.rb +49 -83
  29. data/lib/preact/context.rb +68 -0
  30. data/lib/preact/elements.rb +2 -9
  31. data/lib/preact/module_component_resolution.rb +50 -0
  32. data/lib/preact/prop_declaration_mixin.rb +73 -0
  33. data/lib/preact.rb +1548 -257
  34. data/lib/redirect.rb +34 -0
  35. data/lib/route.rb +15 -0
  36. data/lib/router.rb +145 -0
  37. data/lib/switch.rb +70 -0
  38. data/opal/iso_uri.rb +29 -0
  39. data/opal/uri/common.rb +18 -0
  40. data/opal/uri/generic.rb +47 -0
  41. metadata +45 -309
  42. data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
  43. data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
  44. data/lib/isomorfeus/preact/ssr/history.rb +0 -23
  45. data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
  46. data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
  47. data/lib/isomorfeus/preact_view_helper.rb +0 -129
  48. data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
  49. data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
  50. data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
  51. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
  52. data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
  53. data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
  54. data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
  55. data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
  56. data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
  57. data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
  58. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
  59. data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
  60. data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
  61. data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
  62. data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
  63. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
  64. data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -164
  65. data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
  66. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
  67. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
  68. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
  69. data/lib/lucid_app/context.rb +0 -24
  70. data/lib/lucid_prop_declaration/mixin.rb +0 -126
  71. data/lib/preact/component/api.rb +0 -137
  72. data/lib/preact/component/base.rb +0 -7
  73. data/lib/preact/component/callbacks.rb +0 -111
  74. data/lib/preact/component/initializer.rb +0 -7
  75. data/lib/preact/component/mixin.rb +0 -11
  76. data/lib/preact/component/native_component_constructor.rb +0 -77
  77. data/lib/preact/context_wrapper.rb +0 -48
  78. data/lib/preact/native_constant_wrapper.rb +0 -29
  79. data/lib/preact/option_hooks.rb +0 -98
  80. data/lib/preact/params.rb +0 -16
  81. data/lib/preact/props.rb +0 -69
  82. data/lib/preact/ref.rb +0 -17
  83. data/lib/preact/state.rb +0 -87
  84. data/lib/preact/version.rb +0 -3
  85. data/node_modules/.package-lock.json +0 -38
  86. data/node_modules/preact/LICENSE +0 -21
  87. data/node_modules/preact/README.md +0 -188
  88. data/node_modules/preact/compat/LICENSE +0 -21
  89. data/node_modules/preact/compat/client.js +0 -19
  90. data/node_modules/preact/compat/client.mjs +0 -17
  91. data/node_modules/preact/compat/dist/compat.js +0 -2
  92. data/node_modules/preact/compat/dist/compat.js.map +0 -1
  93. data/node_modules/preact/compat/dist/compat.mjs +0 -2
  94. data/node_modules/preact/compat/dist/compat.module.js +0 -2
  95. data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
  96. data/node_modules/preact/compat/dist/compat.umd.js +0 -2
  97. data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
  98. data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
  99. data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
  100. data/node_modules/preact/compat/jsx-runtime.js +0 -3
  101. data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
  102. data/node_modules/preact/compat/package.json +0 -49
  103. data/node_modules/preact/compat/scheduler.js +0 -15
  104. data/node_modules/preact/compat/scheduler.mjs +0 -23
  105. data/node_modules/preact/compat/server.browser.js +0 -4
  106. data/node_modules/preact/compat/server.js +0 -15
  107. data/node_modules/preact/compat/server.mjs +0 -4
  108. data/node_modules/preact/compat/src/Children.js +0 -21
  109. data/node_modules/preact/compat/src/PureComponent.js +0 -15
  110. data/node_modules/preact/compat/src/forwardRef.js +0 -44
  111. data/node_modules/preact/compat/src/index.d.ts +0 -164
  112. data/node_modules/preact/compat/src/index.js +0 -223
  113. data/node_modules/preact/compat/src/internal.d.ts +0 -47
  114. data/node_modules/preact/compat/src/memo.js +0 -34
  115. data/node_modules/preact/compat/src/portals.js +0 -82
  116. data/node_modules/preact/compat/src/render.js +0 -238
  117. data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
  118. data/node_modules/preact/compat/src/suspense-list.js +0 -126
  119. data/node_modules/preact/compat/src/suspense.d.ts +0 -15
  120. data/node_modules/preact/compat/src/suspense.js +0 -270
  121. data/node_modules/preact/compat/src/util.js +0 -28
  122. data/node_modules/preact/compat/test-utils.js +0 -1
  123. data/node_modules/preact/debug/LICENSE +0 -21
  124. data/node_modules/preact/debug/dist/debug.js +0 -2
  125. data/node_modules/preact/debug/dist/debug.js.map +0 -1
  126. data/node_modules/preact/debug/dist/debug.mjs +0 -2
  127. data/node_modules/preact/debug/dist/debug.module.js +0 -2
  128. data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
  129. data/node_modules/preact/debug/dist/debug.umd.js +0 -2
  130. data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
  131. data/node_modules/preact/debug/package.json +0 -26
  132. data/node_modules/preact/debug/src/check-props.js +0 -54
  133. data/node_modules/preact/debug/src/component-stack.js +0 -146
  134. data/node_modules/preact/debug/src/constants.js +0 -3
  135. data/node_modules/preact/debug/src/debug.js +0 -437
  136. data/node_modules/preact/debug/src/index.js +0 -6
  137. data/node_modules/preact/debug/src/internal.d.ts +0 -82
  138. data/node_modules/preact/debug/src/util.js +0 -11
  139. data/node_modules/preact/devtools/LICENSE +0 -21
  140. data/node_modules/preact/devtools/dist/devtools.js +0 -2
  141. data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
  142. data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
  143. data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
  144. data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
  145. data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
  146. data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
  147. data/node_modules/preact/devtools/package.json +0 -25
  148. data/node_modules/preact/devtools/src/devtools.js +0 -10
  149. data/node_modules/preact/devtools/src/index.d.ts +0 -8
  150. data/node_modules/preact/devtools/src/index.js +0 -15
  151. data/node_modules/preact/dist/preact.js +0 -2
  152. data/node_modules/preact/dist/preact.js.map +0 -1
  153. data/node_modules/preact/dist/preact.min.js +0 -2
  154. data/node_modules/preact/dist/preact.min.js.map +0 -1
  155. data/node_modules/preact/dist/preact.mjs +0 -2
  156. data/node_modules/preact/dist/preact.module.js +0 -2
  157. data/node_modules/preact/dist/preact.module.js.map +0 -1
  158. data/node_modules/preact/dist/preact.umd.js +0 -2
  159. data/node_modules/preact/dist/preact.umd.js.map +0 -1
  160. data/node_modules/preact/hooks/LICENSE +0 -21
  161. data/node_modules/preact/hooks/dist/hooks.js +0 -2
  162. data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
  163. data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
  164. data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
  165. data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
  166. data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
  167. data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
  168. data/node_modules/preact/hooks/package.json +0 -35
  169. data/node_modules/preact/hooks/src/index.d.ts +0 -139
  170. data/node_modules/preact/hooks/src/index.js +0 -417
  171. data/node_modules/preact/hooks/src/internal.d.ts +0 -78
  172. data/node_modules/preact/jsx-runtime/LICENSE +0 -21
  173. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
  174. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
  175. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
  176. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
  177. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
  178. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
  179. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
  180. data/node_modules/preact/jsx-runtime/package.json +0 -28
  181. data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
  182. data/node_modules/preact/jsx-runtime/src/index.js +0 -77
  183. data/node_modules/preact/package.json +0 -304
  184. data/node_modules/preact/src/cjs.js +0 -3
  185. data/node_modules/preact/src/clone-element.js +0 -34
  186. data/node_modules/preact/src/component.js +0 -225
  187. data/node_modules/preact/src/constants.js +0 -3
  188. data/node_modules/preact/src/create-context.js +0 -68
  189. data/node_modules/preact/src/create-element.js +0 -98
  190. data/node_modules/preact/src/diff/catch-error.js +0 -40
  191. data/node_modules/preact/src/diff/children.js +0 -335
  192. data/node_modules/preact/src/diff/index.js +0 -533
  193. data/node_modules/preact/src/diff/props.js +0 -158
  194. data/node_modules/preact/src/index.d.ts +0 -317
  195. data/node_modules/preact/src/index.js +0 -13
  196. data/node_modules/preact/src/internal.d.ts +0 -155
  197. data/node_modules/preact/src/jsx.d.ts +0 -1014
  198. data/node_modules/preact/src/options.js +0 -16
  199. data/node_modules/preact/src/render.js +0 -75
  200. data/node_modules/preact/src/util.js +0 -27
  201. data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
  202. data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
  203. data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
  204. data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
  205. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
  206. data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
  207. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
  208. data/node_modules/preact/test-utils/package.json +0 -28
  209. data/node_modules/preact/test-utils/src/index.d.ts +0 -3
  210. data/node_modules/preact/test-utils/src/index.js +0 -118
  211. data/node_modules/preact-render-to-string/LICENSE +0 -21
  212. data/node_modules/preact-render-to-string/README.md +0 -102
  213. data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
  214. data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
  215. data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
  216. data/node_modules/preact-render-to-string/dist/index.js +0 -1
  217. data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
  218. data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
  219. data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
  220. data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
  221. data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
  222. data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
  223. data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
  224. data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
  225. data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
  226. data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
  227. data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
  228. data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
  229. data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
  230. data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
  231. data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
  232. data/node_modules/preact-render-to-string/jsx.js +0 -1
  233. data/node_modules/preact-render-to-string/package.json +0 -142
  234. data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
  235. data/node_modules/preact-render-to-string/src/index.js +0 -462
  236. data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
  237. data/node_modules/preact-render-to-string/src/jsx.js +0 -76
  238. data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
  239. data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
  240. data/node_modules/preact-render-to-string/src/util.js +0 -78
  241. data/node_modules/preact-render-to-string/typings.json +0 -5
  242. data/node_modules/pretty-format/.npmignore +0 -3
  243. data/node_modules/pretty-format/LICENSE.md +0 -15
  244. data/node_modules/pretty-format/README.md +0 -94
  245. data/node_modules/pretty-format/index.js +0 -343
  246. data/node_modules/pretty-format/package.json +0 -26
  247. data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
  248. data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
  249. data/node_modules/pretty-format/printString.js +0 -7
  250. data/node_modules/wouter-preact/cjs/index.js +0 -180
  251. data/node_modules/wouter-preact/cjs/matcher.js +0 -72
  252. data/node_modules/wouter-preact/cjs/package.json +0 -1
  253. data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
  254. data/node_modules/wouter-preact/cjs/static-location.js +0 -21
  255. data/node_modules/wouter-preact/cjs/use-location.js +0 -94
  256. data/node_modules/wouter-preact/index.d.ts +0 -110
  257. data/node_modules/wouter-preact/index.js +0 -178
  258. data/node_modules/wouter-preact/matcher.d.ts +0 -30
  259. data/node_modules/wouter-preact/matcher.js +0 -66
  260. data/node_modules/wouter-preact/package.json +0 -33
  261. data/node_modules/wouter-preact/react-deps.js +0 -15
  262. data/node_modules/wouter-preact/static-location.d.ts +0 -16
  263. data/node_modules/wouter-preact/static-location.js +0 -17
  264. data/node_modules/wouter-preact/use-location.d.ts +0 -43
  265. data/node_modules/wouter-preact/use-location.js +0 -86
  266. data/package.json +0 -8
@@ -1,178 +0,0 @@
1
- import locationHook from "./use-location.js";
2
- import makeMatcher from "./matcher.js";
3
-
4
- import {
5
- useRef,
6
- useLayoutEffect,
7
- useContext,
8
- useCallback,
9
- createContext,
10
- isValidElement,
11
- cloneElement,
12
- createElement as h,
13
- Fragment,
14
- } from "./react-deps.js";
15
-
16
- /*
17
- * Part 1, Hooks API: useRouter, useRoute and useLocation
18
- */
19
-
20
- // one of the coolest features of `createContext`:
21
- // when no value is provided — default object is used.
22
- // allows us to use the router context as a global ref to store
23
- // the implicitly created router (see `useRouter` below)
24
- const RouterCtx = createContext({});
25
-
26
- const buildRouter = ({
27
- hook = locationHook,
28
- base = "",
29
- matcher = makeMatcher(),
30
- } = {}) => ({ hook, base, matcher });
31
-
32
- export const useRouter = () => {
33
- const globalRef = useContext(RouterCtx);
34
-
35
- // either obtain the router from the outer context (provided by the
36
- // `<Router /> component) or create an implicit one on demand.
37
- return globalRef.v || (globalRef.v = buildRouter());
38
- };
39
-
40
- export const useLocation = () => {
41
- const router = useRouter();
42
- return router.hook(router);
43
- };
44
-
45
- export const useRoute = (pattern) => {
46
- const [path] = useLocation();
47
- return useRouter().matcher(pattern, path);
48
- };
49
-
50
- // internal hook used by Link and Redirect in order to perform navigation
51
- const useNavigate = (options) => {
52
- const navRef = useRef();
53
- const [, navigate] = useLocation();
54
-
55
- navRef.current = () => navigate(options.to || options.href, options);
56
- return navRef;
57
- };
58
-
59
- /*
60
- * Part 2, Low Carb Router API: Router, Route, Link, Switch
61
- */
62
-
63
- export const Router = (props) => {
64
- const ref = useRef();
65
-
66
- // this little trick allows to avoid having unnecessary
67
- // calls to potentially expensive `buildRouter` method.
68
- // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
69
- const value = ref.current || (ref.current = { v: buildRouter(props) });
70
-
71
- return h(RouterCtx.Provider, {
72
- value,
73
- children: props.children,
74
- });
75
- };
76
-
77
- export const Route = ({ path, match, component, children }) => {
78
- const useRouteMatch = useRoute(path);
79
-
80
- // `props.match` is present - Route is controlled by the Switch
81
- const [matches, params] = match || useRouteMatch;
82
-
83
- if (!matches) return null;
84
-
85
- // React-Router style `component` prop
86
- if (component) return h(component, { params });
87
-
88
- // support render prop or plain children
89
- return typeof children === "function" ? children(params) : children;
90
- };
91
-
92
- export const Link = (props) => {
93
- const navRef = useNavigate(props);
94
- const { base } = useRouter();
95
-
96
- let { to, href = to, children, onClick } = props;
97
-
98
- const handleClick = useCallback(
99
- (event) => {
100
- // ignores the navigation when clicked using right mouse button or
101
- // by holding a special modifier key: ctrl, command, win, alt, shift
102
- if (
103
- event.ctrlKey ||
104
- event.metaKey ||
105
- event.altKey ||
106
- event.shiftKey ||
107
- event.button !== 0
108
- )
109
- return;
110
-
111
- event.preventDefault();
112
- navRef.current();
113
- onClick && onClick(event);
114
- },
115
- // navRef is a ref so it never changes
116
- // eslint-disable-next-line react-hooks/exhaustive-deps
117
- [onClick]
118
- );
119
-
120
- // wraps children in `a` if needed
121
- const extraProps = {
122
- // handle nested routers and absolute paths
123
- href: href[0] === "~" ? href.slice(1) : base + href,
124
- onClick: handleClick,
125
- to: null,
126
- };
127
- const jsx = isValidElement(children) ? children : h("a", props);
128
-
129
- return cloneElement(jsx, extraProps);
130
- };
131
-
132
- const flattenChildren = (children) => {
133
- return Array.isArray(children)
134
- ? [].concat(
135
- ...children.map((c) =>
136
- c && c.type === Fragment
137
- ? flattenChildren(c.props.children)
138
- : flattenChildren(c)
139
- )
140
- )
141
- : [children];
142
- };
143
-
144
- export const Switch = ({ children, location }) => {
145
- const { matcher } = useRouter();
146
- const [originalLocation] = useLocation();
147
-
148
- for (const element of flattenChildren(children)) {
149
- let match = 0;
150
-
151
- if (
152
- isValidElement(element) &&
153
- // we don't require an element to be of type Route,
154
- // but we do require it to contain a truthy `path` prop.
155
- // this allows to use different components that wrap Route
156
- // inside of a switch, for example <AnimatedRoute />.
157
- (match = element.props.path
158
- ? matcher(element.props.path, location || originalLocation)
159
- : [true, {}])[0]
160
- )
161
- return cloneElement(element, { match });
162
- }
163
-
164
- return null;
165
- };
166
-
167
- export const Redirect = (props) => {
168
- const navRef = useNavigate(props);
169
-
170
- // empty array means running the effect once, navRef is a ref so it never changes
171
- useLayoutEffect(() => {
172
- navRef.current();
173
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
174
-
175
- return null;
176
- };
177
-
178
- export default useRoute;
@@ -1,30 +0,0 @@
1
- /*
2
- * Match and params
3
- */
4
-
5
- import { Path } from "./use-location";
6
-
7
- export interface DefaultParams {
8
- [paramName: string]: string;
9
- }
10
- export type Params<T extends DefaultParams = DefaultParams> = T;
11
-
12
- export type MatchWithParams<T extends DefaultParams = DefaultParams> = [
13
- true,
14
- Params<T>
15
- ];
16
- export type NoMatch = [false, null];
17
- export type Match<T extends DefaultParams = DefaultParams> =
18
- | MatchWithParams<T>
19
- | NoMatch;
20
-
21
- export type MatcherFn = (pattern: Path, path: Path) => Match;
22
-
23
- export type PatternToRegexpResult = {
24
- keys: Array<{ name: string | number }>;
25
- regexp: RegExp;
26
- };
27
-
28
- export default function makeMatcher(
29
- makeRegexpFn?: (pattern: string) => PatternToRegexpResult
30
- ): MatcherFn;
@@ -1,66 +0,0 @@
1
- // creates a matcher function
2
- export default function makeMatcher(makeRegexpFn = pathToRegexp) {
3
- let cache = {};
4
-
5
- // obtains a cached regexp version of the pattern
6
- const getRegexp = (pattern) =>
7
- cache[pattern] || (cache[pattern] = makeRegexpFn(pattern));
8
-
9
- return (pattern, path) => {
10
- const { regexp, keys } = getRegexp(pattern || "");
11
- const out = regexp.exec(path);
12
-
13
- if (!out) return [false, null];
14
-
15
- // formats an object with matched params
16
- const params = keys.reduce((params, key, i) => {
17
- params[key.name] = out[i + 1];
18
- return params;
19
- }, {});
20
-
21
- return [true, params];
22
- };
23
- }
24
-
25
- // escapes a regexp string (borrowed from path-to-regexp sources)
26
- // https://github.com/pillarjs/path-to-regexp/blob/v3.0.0/index.js#L202
27
- const escapeRx = (str) => str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
28
-
29
- // returns a segment representation in RegExp based on flags
30
- // adapted and simplified version from path-to-regexp sources
31
- const rxForSegment = (repeat, optional, prefix) => {
32
- let capture = repeat ? "((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*)" : "([^\\/]+?)";
33
- if (optional && prefix) capture = "(?:\\/" + capture + ")";
34
- return capture + (optional ? "?" : "");
35
- };
36
-
37
- const pathToRegexp = (pattern) => {
38
- const groupRx = /:([A-Za-z0-9_]+)([?+*]?)/g;
39
-
40
- let match = null,
41
- lastIndex = 0,
42
- keys = [],
43
- result = "";
44
-
45
- while ((match = groupRx.exec(pattern)) !== null) {
46
- const [_, segment, mod] = match;
47
-
48
- // :foo [1] ( )
49
- // :foo? [0 - 1] ( o)
50
- // :foo+ [1 - ∞] (r )
51
- // :foo* [0 - ∞] (ro)
52
- const repeat = mod === "+" || mod === "*";
53
- const optional = mod === "?" || mod === "*";
54
- const prefix = optional && pattern[match.index - 1] === "/" ? 1 : 0;
55
-
56
- const prev = pattern.substring(lastIndex, match.index - prefix);
57
-
58
- keys.push({ name: segment });
59
- lastIndex = groupRx.lastIndex;
60
-
61
- result += escapeRx(prev) + rxForSegment(repeat, optional, prefix);
62
- }
63
-
64
- result += escapeRx(pattern.substring(lastIndex));
65
- return { keys, regexp: new RegExp("^" + result + "(?:\\/)?$", "i") };
66
- };
@@ -1,33 +0,0 @@
1
- {
2
- "name": "wouter-preact",
3
- "version": "2.7.5",
4
- "description": "A minimalistic routing for React and Preact (Preact-only version).",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "require": "./cjs/index.js",
9
- "default": "./index.js"
10
- },
11
- "./use-location": {
12
- "require": "./cjs/use-location.js",
13
- "default": "./use-location.js"
14
- },
15
- "./matcher": {
16
- "require": "./cjs/matcher.js",
17
- "default": "./matcher.js"
18
- },
19
- "./static-location": {
20
- "require": "./cjs/static-location.js",
21
- "default": "./static-location.js"
22
- }
23
- },
24
- "main": "cjs/index.js",
25
- "module": "index.js",
26
- "types": "index.d.ts",
27
- "author": "Alexey Taktarov <molefrog@gmail.com>",
28
- "repository": "molefrog/wouter",
29
- "license": "ISC",
30
- "peerDependencies": {
31
- "preact": "^10.0.0"
32
- }
33
- }
@@ -1,15 +0,0 @@
1
- export {
2
- isValidElement,
3
- createContext,
4
- cloneElement,
5
- createElement,
6
- Fragment,
7
- } from "preact";
8
- export {
9
- useRef,
10
- useEffect,
11
- useLayoutEffect,
12
- useState,
13
- useContext,
14
- useCallback,
15
- } from "preact/hooks";
@@ -1,16 +0,0 @@
1
- import { Path, LocationHook } from "./index";
2
-
3
- interface StaticLocationHookOptions {
4
- record?: boolean;
5
- }
6
-
7
- interface StaticLocationHook extends LocationHook {
8
- history: Readonly<Path[]>;
9
- }
10
-
11
- declare function staticLocationHook(
12
- path?: Path,
13
- options?: StaticLocationHookOptions,
14
- ): StaticLocationHook;
15
-
16
- export default staticLocationHook;
@@ -1,17 +0,0 @@
1
- // Generates static `useLocation` hook. The hook always
2
- // responds with initial path provided.
3
- // You can use this for server-side rendering.
4
- export default (path = "/", { record = false } = {}) => {
5
- let hook;
6
- const navigate = (to, { replace } = {}) => {
7
- if (record) {
8
- if (replace) {
9
- hook.history.pop();
10
- }
11
- hook.history.push(to);
12
- }
13
- };
14
- hook = () => [path, navigate];
15
- hook.history = [path];
16
- return hook;
17
- };
@@ -1,43 +0,0 @@
1
- /*
2
- * Foundation: useLocation and paths
3
- */
4
-
5
- export type Path = string;
6
-
7
- // the base useLocation hook type. Any custom hook (including the
8
- // default one) should inherit from it.
9
- export type BaseLocationHook = (
10
- ...args: any[]
11
- ) => [Path, (path: Path, ...args: any[]) => any];
12
-
13
- /*
14
- * Utility types that operate on hook
15
- */
16
-
17
- // Returns the type of the location tuple of the given hook.
18
- export type HookReturnValue<H extends BaseLocationHook> = ReturnType<H>;
19
-
20
- // Returns the type of the navigation options that hook's push function accepts.
21
- export type HookNavigationOptions<H extends BaseLocationHook> = HookReturnValue<
22
- H
23
- >[1] extends (path: Path, options: infer R, ...rest: any[]) => any
24
- ? R extends { [k: string]: any }
25
- ? R
26
- : {}
27
- : {};
28
-
29
- /*
30
- * Default `useLocation`
31
- */
32
-
33
- // The type of the default `useLocation` hook that wouter uses.
34
- // It operates on current URL using History API, supports base path and can
35
- // navigate with `pushState` or `replaceState`.
36
- export type LocationHook = (options?: {
37
- base?: Path;
38
- }) => [Path, (to: Path, options?: { replace?: boolean }) => void];
39
-
40
- declare const useLocation: LocationHook;
41
- export default useLocation;
42
-
43
- export type LocationTuple = HookReturnValue<LocationHook>;
@@ -1,86 +0,0 @@
1
- import { useEffect, useRef, useState, useCallback } from "./react-deps.js";
2
-
3
- /**
4
- * History API docs @see https://developer.mozilla.org/en-US/docs/Web/API/History
5
- */
6
- const eventPopstate = "popstate";
7
- const eventPushState = "pushState";
8
- const eventReplaceState = "replaceState";
9
- export const events = [eventPopstate, eventPushState, eventReplaceState];
10
-
11
- export default ({ base = "" } = {}) => {
12
- const [{ path, search }, update] = useState(() => ({
13
- path: currentPathname(base),
14
- search: location.search,
15
- })); // @see https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
16
- const prevHash = useRef(path + search);
17
-
18
- useEffect(() => {
19
- // this function checks if the location has been changed since the
20
- // last render and updates the state only when needed.
21
- // unfortunately, we can't rely on `path` value here, since it can be stale,
22
- // that's why we store the last pathname in a ref.
23
- const checkForUpdates = () => {
24
- const pathname = currentPathname(base);
25
- const search = location.search;
26
- const hash = pathname + search;
27
-
28
- if (prevHash.current !== hash) {
29
- prevHash.current = hash;
30
- update({ path: pathname, search });
31
- }
32
- };
33
-
34
- events.forEach((e) => addEventListener(e, checkForUpdates));
35
-
36
- // it's possible that an update has occurred between render and the effect handler,
37
- // so we run additional check on mount to catch these updates. Based on:
38
- // https://gist.github.com/bvaughn/e25397f70e8c65b0ae0d7c90b731b189
39
- checkForUpdates();
40
-
41
- return () => events.forEach((e) => removeEventListener(e, checkForUpdates));
42
- }, [base]);
43
-
44
- // the 2nd argument of the `useLocation` return value is a function
45
- // that allows to perform a navigation.
46
- //
47
- // the function reference should stay the same between re-renders, so that
48
- // it can be passed down as an element prop without any performance concerns.
49
- const navigate = useCallback(
50
- (to, { replace = false } = {}) =>
51
- history[replace ? eventReplaceState : eventPushState](
52
- null,
53
- "",
54
- // handle nested routers and absolute paths
55
- to[0] === "~" ? to.slice(1) : base + to
56
- ),
57
- [base]
58
- );
59
-
60
- return [path, navigate];
61
- };
62
-
63
- // While History API does have `popstate` event, the only
64
- // proper way to listen to changes via `push/replaceState`
65
- // is to monkey-patch these methods.
66
- //
67
- // See https://stackoverflow.com/a/4585031
68
- if (typeof history !== "undefined") {
69
- for (const type of [eventPushState, eventReplaceState]) {
70
- const original = history[type];
71
-
72
- history[type] = function () {
73
- const result = original.apply(this, arguments);
74
- const event = new Event(type);
75
- event.arguments = arguments;
76
-
77
- dispatchEvent(event);
78
- return result;
79
- };
80
- }
81
- }
82
-
83
- const currentPathname = (base, path = location.pathname) =>
84
- !path.toLowerCase().indexOf(base.toLowerCase())
85
- ? path.slice(base.length) || "/"
86
- : "~" + path;
data/package.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "name": "isomorfeus-preact",
3
- "dependencies": {
4
- "preact": "10.9.0",
5
- "preact-render-to-string": "5.2.0",
6
- "wouter-preact": "2.7.5"
7
- }
8
- }