@unsetsoft/ryunixjs 0.2.29 → 0.2.30-nightly.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.
- package/package.json +1 -2
- package/src/lib/createElement.js +2 -0
- package/src/lib/index.js +10 -1
- package/src/lib/navigation.js +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unsetsoft/ryunixjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30-nightly.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/Ryunix.js",
|
|
6
6
|
"private": false,
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"@babel/polyfill": "7.12.1",
|
|
28
28
|
"@babel/preset-env": "^7.22.14",
|
|
29
29
|
"@babel/preset-react": "^7.22.5",
|
|
30
|
-
"@mdx-js/loader": "^2.3.0",
|
|
31
30
|
"babel-loader": "^9.1.3",
|
|
32
31
|
"css-loader": "^6.8.1",
|
|
33
32
|
"error-overlay-webpack-plugin": "^1.1.1",
|
package/src/lib/createElement.js
CHANGED
package/src/lib/index.js
CHANGED
|
@@ -2,13 +2,22 @@ import { createElement, Fragments } from "./createElement";
|
|
|
2
2
|
import { render, init } from "./render";
|
|
3
3
|
import { useContext, useStore, useEffect } from "./hooks";
|
|
4
4
|
import { createContext } from "./createContext";
|
|
5
|
+
import { Router, Link } from "./navigation";
|
|
5
6
|
import * as Dom from "./dom";
|
|
6
7
|
import * as Workers from "./workers";
|
|
7
8
|
import * as Reconciler from "./reconciler";
|
|
8
9
|
import * as Components from "./components";
|
|
9
10
|
import * as Commits from "./commits";
|
|
10
11
|
|
|
11
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
useStore,
|
|
14
|
+
useEffect,
|
|
15
|
+
createContext,
|
|
16
|
+
useContext,
|
|
17
|
+
Fragments,
|
|
18
|
+
Router,
|
|
19
|
+
Link,
|
|
20
|
+
};
|
|
12
21
|
|
|
13
22
|
export default {
|
|
14
23
|
createElement,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useStore, useEffect } from "./hooks";
|
|
2
|
+
import { createElement } from "./createElement";
|
|
3
|
+
const Router = ({ path, component }) => {
|
|
4
|
+
const [currentPath, setCurrentPath] = useStore(window.location.pathname);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const onLocationChange = () => {
|
|
8
|
+
setCurrentPath(() => window.location.pathname);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
window.addEventListener("navigate", onLocationChange);
|
|
12
|
+
window.addEventListener("pushsatate", onLocationChange);
|
|
13
|
+
window.addEventListener("popstate", onLocationChange);
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
window.removeEventListener("navigate", onLocationChange);
|
|
17
|
+
window.removeEventListener("pushsatate", onLocationChange);
|
|
18
|
+
window.removeEventListener("popstate", onLocationChange);
|
|
19
|
+
};
|
|
20
|
+
}, [currentPath]);
|
|
21
|
+
|
|
22
|
+
return currentPath === path ? component() : null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const Link = (props) => {
|
|
26
|
+
const p = {
|
|
27
|
+
href: props.to,
|
|
28
|
+
...props,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return createElement("a", p, props.children);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { Router, Link };
|