the-react 1.0.0 → 1.0.3
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 +50 -34
- package/src/my-react/index.ts +0 -1
- package/src/router-dom/Router.tsx +0 -79
- package/src/router-dom/hooks.ts +0 -8
- package/src/router-dom/index.ts +0 -2
package/package.json
CHANGED
|
@@ -1,34 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "the-react",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A React library for TheBugs Project",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "the-react",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "A React library for TheBugs Project",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
|
+
"import": "./src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./jsx-runtime": {
|
|
13
|
+
"types": "./src/types/jsx.ts",
|
|
14
|
+
"import": "./src/jsx-runtime/index.ts"
|
|
15
|
+
},
|
|
16
|
+
"./jsx-dev-runtime": {
|
|
17
|
+
"import": "./src/jsx-dev-runtime/index.ts"
|
|
18
|
+
},
|
|
19
|
+
"./hooks": {
|
|
20
|
+
"types": "./src/index.ts",
|
|
21
|
+
"import": "./src/hooks/index.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "vite build",
|
|
26
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ArtemS18/My-React.git"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"typescript",
|
|
34
|
+
"react",
|
|
35
|
+
"library",
|
|
36
|
+
"js",
|
|
37
|
+
"ts"
|
|
38
|
+
],
|
|
39
|
+
"author": "Artemii",
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/ArtemS18/My-React/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/ArtemS18/My-React#readme",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"typescript": "~5.9.3",
|
|
47
|
+
"vite": "^7.3.1",
|
|
48
|
+
"vite-tsconfig-paths": "^6.1.1"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/my-react/index.ts
CHANGED
|
@@ -363,7 +363,6 @@ export class ComponentInstance<PropsType extends ComponentPropsType> {
|
|
|
363
363
|
if (typeof vNode !== "string" && vNode.type === "component") {
|
|
364
364
|
const compInstance = this.instanceMap.get(vNode.key) as ComponentInstance<any>;
|
|
365
365
|
const compDom = compInstance.domElement;
|
|
366
|
-
console.log("compInstance", compInstance)
|
|
367
366
|
if (!compDom) {
|
|
368
367
|
branchIndex++;
|
|
369
368
|
continue
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { JSXElementType } from "../types/jsx"
|
|
2
|
-
|
|
3
|
-
interface IRouterProps{
|
|
4
|
-
path: string
|
|
5
|
-
children: JSXElementType
|
|
6
|
-
currentPath: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function matchPath(pattern: string, path: string) {
|
|
10
|
-
const names: string[] = []
|
|
11
|
-
let regexStr = ''
|
|
12
|
-
|
|
13
|
-
for (let i = 0; i < pattern.length;) {
|
|
14
|
-
const ch = pattern[i]
|
|
15
|
-
if (ch === '{') {
|
|
16
|
-
const close = pattern.indexOf('}', i + 1)
|
|
17
|
-
if (close === -1) {
|
|
18
|
-
regexStr += '\\{'
|
|
19
|
-
i++
|
|
20
|
-
continue
|
|
21
|
-
}
|
|
22
|
-
const name = pattern.substring(i + 1, close)
|
|
23
|
-
names.push(name)
|
|
24
|
-
regexStr += '([^/]+)'
|
|
25
|
-
i = close + 1
|
|
26
|
-
} else {
|
|
27
|
-
if ('^$\\.*+?()[]|/'.includes(ch)) {
|
|
28
|
-
regexStr += '\\' + ch
|
|
29
|
-
} else {
|
|
30
|
-
regexStr += ch
|
|
31
|
-
}
|
|
32
|
-
i++
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const regex = new RegExp('^' + regexStr + '$')
|
|
37
|
-
const m = regex.exec(path)
|
|
38
|
-
if (!m) return { matches: false, params: {} as Record<string, string> }
|
|
39
|
-
|
|
40
|
-
const params: Record<string, string> = {}
|
|
41
|
-
for (let i = 0; i < names.length; i++) {
|
|
42
|
-
params[names[i]] = decodeURIComponent(m[i + 1])
|
|
43
|
-
}
|
|
44
|
-
return { matches: true, params }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function Router({path, children, currentPath}: IRouterProps){
|
|
48
|
-
const { matches, params } = matchPath(path, currentPath)
|
|
49
|
-
console.log(`Router ${path}:`, { currentPath, matches, params, children })
|
|
50
|
-
|
|
51
|
-
if (!matches && path != "*") return null
|
|
52
|
-
|
|
53
|
-
if (children.type === 'component') {
|
|
54
|
-
children.props = { ...children.props, ...params }
|
|
55
|
-
console.log(`render children ${path}`)
|
|
56
|
-
return (<div>{children}</div>)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (<div>{children}</div>)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
interface ISwitchrProps{
|
|
63
|
-
children: any[]
|
|
64
|
-
currentPath: string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function Switch({ currentPath, children }: ISwitchrProps) {
|
|
68
|
-
const childrenArray = Array.isArray(children) ? children : [children];
|
|
69
|
-
|
|
70
|
-
for (const child of childrenArray) {
|
|
71
|
-
if (child && child.type === 'component' && child.props.path) {
|
|
72
|
-
const { matches } = matchPath(child.props.path, currentPath);
|
|
73
|
-
if (matches || child.props.path == "*") {
|
|
74
|
-
return <div>{child}</div>;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
package/src/router-dom/hooks.ts
DELETED
package/src/router-dom/index.ts
DELETED