@unsetsoft/ryunixjs 0.4.13-nightly.3 → 0.4.13-nightly.4

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
@@ -286,7 +286,30 @@
286
286
  return currentPath === path ? component() : null
287
287
  };
288
288
 
289
- const Navigate = (props) => {
289
+ const Navigate = () => {
290
+ /**
291
+ * The function `push` is used to push a new state to the browser's history and trigger a custom
292
+ * event called 'pushstate'.
293
+ * @param to - The `to` parameter is a string representing the URL path to which you want to
294
+ * navigate.
295
+ * @param [state] - The `state` parameter is an optional object that represents the state associated
296
+ * with the new history entry. It can be used to store any data that you want to associate with the
297
+ * new URL. When you navigate back or forward in the browser history, this state object will be
298
+ * passed to the `popstate
299
+ * @returns The function `push` does not have a return statement, so it returns `undefined` by
300
+ * default.
301
+ */
302
+ const push = (to, state = {}) => {
303
+ if (window.location.pathname === to) return
304
+ window.history.pushState(state, '', to);
305
+ const navigationEvent = new Event('pushsatate');
306
+ window.dispatchEvent(navigationEvent);
307
+ };
308
+
309
+ return { push }
310
+ };
311
+
312
+ const Link = (props) => {
290
313
  if (props.style) {
291
314
  throw new Error(
292
315
  'The style attribute is not supported on internal components, use className.',
@@ -307,11 +330,8 @@
307
330
  }
308
331
  const preventReload = (event) => {
309
332
  event.preventDefault();
310
- if (window.location.pathname !== props.to) {
311
- window.history.pushState({}, '', props.to);
312
- const navigationEvent = new Event('pushsatate');
313
- window.dispatchEvent(navigationEvent);
314
- }
333
+ const { push } = Navigate();
334
+ push(props.to);
315
335
  };
316
336
 
317
337
  const anchor = {
@@ -659,6 +679,7 @@
659
679
  window.Ryunix = Ryunix;
660
680
 
661
681
  exports.Fragments = Fragments;
682
+ exports.Link = Link;
662
683
  exports.Navigate = Navigate;
663
684
  exports.Router = Router;
664
685
  exports.default = Ryunix;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.4.13-nightly.3",
3
+ "version": "0.4.13-nightly.4",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
package/src/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { createElement, Fragments } from './createElement'
2
2
  import { render, init } from './render'
3
3
  import { useStore, useEffect, useQuery } from './hooks'
4
- import { Router, Navigate } from './navigation'
4
+ import { Router, Navigate, Link } from './navigation'
5
5
  import * as Dom from './dom'
6
6
  import * as Workers from './workers'
7
7
  import * as Reconciler from './reconciler'
8
8
  import * as Components from './components'
9
9
  import * as Commits from './commits'
10
10
 
11
- export { useStore, useEffect, useQuery, Fragments, Router, Navigate }
11
+ export { useStore, useEffect, useQuery, Fragments, Router, Navigate, Link }
12
12
 
13
13
  export default {
14
14
  createElement,
@@ -22,7 +22,30 @@ const Router = ({ path, component }) => {
22
22
  return currentPath === path ? component() : null
23
23
  }
24
24
 
25
- const Navigate = (props) => {
25
+ const Navigate = () => {
26
+ /**
27
+ * The function `push` is used to push a new state to the browser's history and trigger a custom
28
+ * event called 'pushstate'.
29
+ * @param to - The `to` parameter is a string representing the URL path to which you want to
30
+ * navigate.
31
+ * @param [state] - The `state` parameter is an optional object that represents the state associated
32
+ * with the new history entry. It can be used to store any data that you want to associate with the
33
+ * new URL. When you navigate back or forward in the browser history, this state object will be
34
+ * passed to the `popstate
35
+ * @returns The function `push` does not have a return statement, so it returns `undefined` by
36
+ * default.
37
+ */
38
+ const push = (to, state = {}) => {
39
+ if (window.location.pathname === to) return
40
+ window.history.pushState(state, '', to)
41
+ const navigationEvent = new Event('pushsatate')
42
+ window.dispatchEvent(navigationEvent)
43
+ }
44
+
45
+ return { push }
46
+ }
47
+
48
+ const Link = (props) => {
26
49
  if (props.style) {
27
50
  throw new Error(
28
51
  'The style attribute is not supported on internal components, use className.',
@@ -43,11 +66,8 @@ const Navigate = (props) => {
43
66
  }
44
67
  const preventReload = (event) => {
45
68
  event.preventDefault()
46
- if (window.location.pathname !== props.to) {
47
- window.history.pushState({}, '', props.to)
48
- const navigationEvent = new Event('pushsatate')
49
- window.dispatchEvent(navigationEvent)
50
- }
69
+ const { push } = Navigate()
70
+ push(props.to)
51
71
  }
52
72
 
53
73
  const anchor = {
@@ -61,4 +81,4 @@ const Navigate = (props) => {
61
81
  return createElement('a', anchor, children)
62
82
  }
63
83
 
64
- export { Router, Navigate }
84
+ export { Router, Navigate, Link }
package/src/main.js CHANGED
@@ -6,6 +6,7 @@ export {
6
6
  Fragments,
7
7
  Navigate,
8
8
  Router,
9
+ Link,
9
10
  } from './lib/index.js'
10
11
 
11
12
  window.Ryunix = Ryunix