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 CHANGED
@@ -1,34 +1,50 @@
1
- {
2
- "name": "the-react",
3
- "version": "1.0.0",
4
- "description": "A React library for TheBugs Project",
5
- "main": "dist/my-react.umd.js",
6
- "module": "dist/my-react.esm.js",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "build": "vite build",
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/ArtemS18/My-React.git"
15
- },
16
- "keywords": [
17
- "typescript",
18
- "react",
19
- "library",
20
- "js",
21
- "ts"
22
- ],
23
- "author": "Artemii",
24
- "license": "ISC",
25
- "bugs": {
26
- "url": "https://github.com/ArtemS18/My-React/issues"
27
- },
28
- "homepage": "https://github.com/ArtemS18/My-React#readme",
29
- "devDependencies": {
30
- "typescript": "~5.9.3",
31
- "vite": "^7.3.1",
32
- "vite-tsconfig-paths": "^6.1.1"
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
+ }
@@ -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
- }
@@ -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";