the-react 1.0.1 → 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 CHANGED
@@ -1,55 +1,50 @@
1
- {
2
- "name": "the-react",
3
- "version": "1.0.1",
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"
15
- },
16
- "./jsx-dev-runtime": {
17
- "types": "./src/types/jsx.ts",
18
- "import": "./src/jsx-dev-runtime"
19
- },
20
- "./router-dom": {
21
- "types": "./src/index.ts",
22
- "import": "./src/router-dom/index.ts"
23
- },
24
- "./hooks": {
25
- "types": "./src/index.ts",
26
- "import": "./src/hooks/index.ts"
27
- }
28
- },
29
- "scripts": {
30
- "build": "vite build",
31
- "test": "echo \"Error: no test specified\" && exit 1"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/ArtemS18/My-React.git"
36
- },
37
- "keywords": [
38
- "typescript",
39
- "react",
40
- "library",
41
- "js",
42
- "ts"
43
- ],
44
- "author": "Artemii",
45
- "license": "ISC",
46
- "bugs": {
47
- "url": "https://github.com/ArtemS18/My-React/issues"
48
- },
49
- "homepage": "https://github.com/ArtemS18/My-React#readme",
50
- "devDependencies": {
51
- "typescript": "~5.9.3",
52
- "vite": "^7.3.1",
53
- "vite-tsconfig-paths": "^6.1.1"
54
- }
55
- }
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
+ }
@@ -1,116 +0,0 @@
1
- import type { JSXElementType } from "@my-react/types/jsx"
2
-
3
-
4
- interface IRouterProps {
5
- path: string
6
- children: JSXElementType
7
- currentPath: string
8
- currentSearch?: string
9
- }
10
-
11
- export function matchPath(pattern: string, path: string) {
12
- const names: string[] = []
13
- let regexStr = ''
14
-
15
- for (let i = 0; i < pattern.length;) {
16
- const ch = pattern[i]
17
- if (ch === '{') {
18
- const close = pattern.indexOf('}', i + 1)
19
- if (close === -1) {
20
- regexStr += '\\{'
21
- i++
22
- continue
23
- }
24
- const name = pattern.substring(i + 1, close)
25
- names.push(name)
26
- regexStr += '([^/]+)'
27
- i = close + 1
28
- } else {
29
- if ('^$\\.*+?()[]|/'.includes(ch)) {
30
- regexStr += '\\' + ch
31
- } else {
32
- regexStr += ch
33
- }
34
- i++
35
- }
36
- }
37
-
38
- const regex = new RegExp('^' + regexStr + '$')
39
- const m = regex.exec(path)
40
- if (!m) return { matches: false, params: {} as Record<string, string> }
41
-
42
- const params: Record<string, string> = {}
43
- for (let i = 0; i < names.length; i++) {
44
- params[names[i]] = decodeURIComponent(m[i + 1])
45
- }
46
- return { matches: true, params }
47
- }
48
-
49
- export function parseSearch(search: string): Record<string, string> {
50
- const params: Record<string, string> = {}
51
- if (!search) return params
52
-
53
- const queryString = search.startsWith('?') ? search.slice(1) : search
54
- const pairs = queryString.split('&')
55
-
56
- for (const pair of pairs) {
57
- const [key, value] = pair.split('=')
58
- if (key) {
59
- params[decodeURIComponent(key)] = decodeURIComponent(value || '').replaceAll('+', ' ')
60
- }
61
- }
62
- return params
63
- }
64
-
65
- export function Router({path, children, currentPath, currentSearch}: IRouterProps){
66
- const { matches, params: pathParams } = matchPath(path, currentPath)
67
-
68
-
69
- console.log(`Router ${path}:`, {
70
- currentPath,
71
- currentSearch,
72
- pathParams,
73
- children,
74
- })
75
-
76
- if (!matches && path != "*") return null
77
-
78
- if (children.type === 'component') {
79
- children.props = {
80
- ...children.props,
81
- ...pathParams,
82
- }
83
- if (currentSearch){
84
- const queryParams = parseSearch(currentSearch)
85
- children.props = {
86
- ...children.props,
87
- ...queryParams
88
-
89
- }
90
- console.log(currentSearch)
91
- }
92
- console.log(`render children ${path}`)
93
- return <div>{children}</div>
94
- }
95
-
96
- return <div>{children}</div>
97
- }
98
-
99
- interface ISwitchrProps {
100
- children: any[]
101
- currentPath: string
102
- }
103
-
104
- export function Switch({ currentPath, children }: ISwitchrProps) {
105
- const childrenArray = Array.isArray(children) ? children : [children];
106
-
107
- for (const child of childrenArray) {
108
- if (child && child.type === 'component' && child.props.path) {
109
- const { matches } = matchPath(child.props.path, currentPath);
110
- if (matches || child.props.path == "*") {
111
- return <div>{child}</div>;
112
- }
113
- }
114
- }
115
- return null;
116
- }
@@ -1,8 +0,0 @@
1
- export function useNavigate() {
2
- const navigate = (path: string) => {
3
- console.log(path)
4
- window.history.pushState({}, '', path);
5
- window.dispatchEvent(new PopStateEvent('popstate'));
6
- };
7
- return navigate;
8
- }
@@ -1,2 +0,0 @@
1
- export { Router, Switch } from "./Router";
2
- export { useNavigate } from "./hooks";