@unsetsoft/ryunixjs 0.4.13-nightly.46 → 0.4.13-nightly.48

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.
package/dist/Ryunix.js CHANGED
@@ -245,6 +245,11 @@
245
245
  vars.hookIndex++;
246
246
  };
247
247
 
248
+ /**
249
+ * The `useQuery` function is a custom hook in JavaScript that retrieves query parameters from the URL
250
+ * and stores them in a hook for easy access.
251
+ * @returns The `useQuery` function returns the `query` property of the `hook` object.
252
+ */
248
253
  const useQuery = () => {
249
254
  vars.hookIndex++;
250
255
 
@@ -269,7 +274,7 @@
269
274
  return hook.query
270
275
  };
271
276
 
272
- const Router = ({ path, component }) => {
277
+ const Router = ({ path, component, children }) => {
273
278
  const [currentPath, setCurrentPath] = useStore(window.location.pathname);
274
279
 
275
280
  useEffect(() => {
@@ -277,18 +282,16 @@
277
282
  setCurrentPath(() => window.location.pathname);
278
283
  };
279
284
 
280
- window.addEventListener('navigate', onLocationChange);
281
- window.addEventListener('pushsatate', onLocationChange);
282
285
  window.addEventListener('popstate', onLocationChange);
283
286
 
284
287
  return () => {
285
- window.removeEventListener('navigate', onLocationChange);
286
- window.removeEventListener('pushsatate', onLocationChange);
287
288
  window.removeEventListener('popstate', onLocationChange);
288
289
  }
289
290
  }, [currentPath]);
290
291
 
291
- return currentPath === path ? component() : null
292
+ const Children = children ? children : component();
293
+
294
+ return currentPath === path ? Children : null
292
295
  };
293
296
 
294
297
  const Navigate = () => {
@@ -306,8 +309,9 @@
306
309
  */
307
310
  const push = (to, state = {}) => {
308
311
  if (window.location.pathname === to) return
312
+
309
313
  window.history.pushState(state, '', to);
310
- const navigationEvent = new Event('pushsatate');
314
+ const navigationEvent = new PopStateEvent('popstate');
311
315
  window.dispatchEvent(navigationEvent);
312
316
  };
313
317
 
@@ -334,6 +338,10 @@
334
338
  throw new Error("Missig 'to' param.")
335
339
  }
336
340
  const preventReload = (event) => {
341
+ if (event.metaKey || event.ctrlKey) {
342
+ return
343
+ }
344
+
337
345
  event.preventDefault();
338
346
  const { push } = Navigate();
339
347
  push(props.to);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.4.13-nightly.46",
3
+ "version": "0.4.13-nightly.48",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "types": "./dist/Ryunix.d.ts",
package/src/lib/hooks.js CHANGED
@@ -74,6 +74,11 @@ const useEffect = (effect, deps) => {
74
74
  vars.hookIndex++
75
75
  }
76
76
 
77
+ /**
78
+ * The `useQuery` function is a custom hook in JavaScript that retrieves query parameters from the URL
79
+ * and stores them in a hook for easy access.
80
+ * @returns The `useQuery` function returns the `query` property of the `hook` object.
81
+ */
77
82
  const useQuery = () => {
78
83
  vars.hookIndex++
79
84
 
@@ -1,6 +1,6 @@
1
1
  import { useStore, useEffect } from './hooks'
2
2
  import { createElement } from './createElement'
3
- const Router = ({ path, component }) => {
3
+ const Router = ({ path, component, children }) => {
4
4
  const [currentPath, setCurrentPath] = useStore(window.location.pathname)
5
5
 
6
6
  useEffect(() => {
@@ -8,18 +8,16 @@ const Router = ({ path, component }) => {
8
8
  setCurrentPath(() => window.location.pathname)
9
9
  }
10
10
 
11
- window.addEventListener('navigate', onLocationChange)
12
- window.addEventListener('pushsatate', onLocationChange)
13
11
  window.addEventListener('popstate', onLocationChange)
14
12
 
15
13
  return () => {
16
- window.removeEventListener('navigate', onLocationChange)
17
- window.removeEventListener('pushsatate', onLocationChange)
18
14
  window.removeEventListener('popstate', onLocationChange)
19
15
  }
20
16
  }, [currentPath])
21
17
 
22
- return currentPath === path ? component() : null
18
+ const Children = children ? children : component()
19
+
20
+ return currentPath === path ? Children : null
23
21
  }
24
22
 
25
23
  const Navigate = () => {
@@ -37,8 +35,9 @@ const Navigate = () => {
37
35
  */
38
36
  const push = (to, state = {}) => {
39
37
  if (window.location.pathname === to) return
38
+
40
39
  window.history.pushState(state, '', to)
41
- const navigationEvent = new Event('pushsatate')
40
+ const navigationEvent = new PopStateEvent('popstate')
42
41
  window.dispatchEvent(navigationEvent)
43
42
  }
44
43
 
@@ -65,6 +64,10 @@ const Link = (props) => {
65
64
  throw new Error("Missig 'to' param.")
66
65
  }
67
66
  const preventReload = (event) => {
67
+ if (event.metaKey || event.ctrlKey) {
68
+ return
69
+ }
70
+
68
71
  event.preventDefault()
69
72
  const { push } = Navigate()
70
73
  push(props.to)