@richie-router/react 0.0.1 → 0.1.2
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/cjs/history.cjs +150 -0
- package/dist/cjs/index.cjs +48 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/router.cjs +887 -0
- package/dist/esm/history.mjs +110 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/router.mjs +841 -0
- package/dist/types/history.d.ts +19 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/router.d.ts +263 -0
- package/package.json +46 -7
- package/README.md +0 -45
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// packages/react/src/history.ts
|
|
40
|
+
var exports_history = {};
|
|
41
|
+
__export(exports_history, {
|
|
42
|
+
createMemoryHistory: () => createMemoryHistory,
|
|
43
|
+
createHashHistory: () => createHashHistory,
|
|
44
|
+
createBrowserHistory: () => createBrowserHistory
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(exports_history);
|
|
47
|
+
function readBrowserLocation() {
|
|
48
|
+
return {
|
|
49
|
+
href: `${window.location.pathname}${window.location.search}${window.location.hash}`,
|
|
50
|
+
pathname: window.location.pathname,
|
|
51
|
+
search: window.location.search,
|
|
52
|
+
hash: window.location.hash,
|
|
53
|
+
state: window.history.state
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function createBrowserHistory() {
|
|
57
|
+
return {
|
|
58
|
+
get location() {
|
|
59
|
+
return readBrowserLocation();
|
|
60
|
+
},
|
|
61
|
+
listen(listener) {
|
|
62
|
+
window.addEventListener("popstate", listener);
|
|
63
|
+
return () => window.removeEventListener("popstate", listener);
|
|
64
|
+
},
|
|
65
|
+
push(href, state) {
|
|
66
|
+
window.history.pushState(state, "", href);
|
|
67
|
+
},
|
|
68
|
+
replace(href, state) {
|
|
69
|
+
window.history.replaceState(state, "", href);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function readHashLocation() {
|
|
74
|
+
const rawHash = window.location.hash.replace(/^#/, "") || "/";
|
|
75
|
+
const url = new URL(rawHash.startsWith("/") ? `http://hash.local${rawHash}` : `http://hash.local/${rawHash}`);
|
|
76
|
+
return {
|
|
77
|
+
href: `${url.pathname}${url.search}${url.hash}`,
|
|
78
|
+
pathname: url.pathname,
|
|
79
|
+
search: url.search,
|
|
80
|
+
hash: url.hash,
|
|
81
|
+
state: window.history.state
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function createHashHistory() {
|
|
85
|
+
return {
|
|
86
|
+
get location() {
|
|
87
|
+
return readHashLocation();
|
|
88
|
+
},
|
|
89
|
+
listen(listener) {
|
|
90
|
+
window.addEventListener("popstate", listener);
|
|
91
|
+
window.addEventListener("hashchange", listener);
|
|
92
|
+
return () => {
|
|
93
|
+
window.removeEventListener("popstate", listener);
|
|
94
|
+
window.removeEventListener("hashchange", listener);
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
push(href, state) {
|
|
98
|
+
window.history.pushState(state, "", `#${href.startsWith("/") ? href : `/${href}`}`);
|
|
99
|
+
},
|
|
100
|
+
replace(href, state) {
|
|
101
|
+
window.history.replaceState(state, "", `#${href.startsWith("/") ? href : `/${href}`}`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class MemoryHistory {
|
|
107
|
+
entries;
|
|
108
|
+
index = 0;
|
|
109
|
+
listeners = new Set;
|
|
110
|
+
constructor(options) {
|
|
111
|
+
const initialEntries = options?.initialEntries?.length ? options.initialEntries : ["/"];
|
|
112
|
+
this.entries = initialEntries.map((entry) => ({ href: entry, state: null }));
|
|
113
|
+
this.index = this.entries.length - 1;
|
|
114
|
+
}
|
|
115
|
+
get location() {
|
|
116
|
+
const current = this.entries[this.index] ?? { href: "/", state: null };
|
|
117
|
+
const url = new URL(current.href, "http://memory.local");
|
|
118
|
+
return {
|
|
119
|
+
href: `${url.pathname}${url.search}${url.hash}`,
|
|
120
|
+
pathname: url.pathname,
|
|
121
|
+
search: url.search,
|
|
122
|
+
hash: url.hash,
|
|
123
|
+
state: current.state
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
listen(listener) {
|
|
127
|
+
this.listeners.add(listener);
|
|
128
|
+
return () => {
|
|
129
|
+
this.listeners.delete(listener);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
push(href, state) {
|
|
133
|
+
this.entries.splice(this.index + 1);
|
|
134
|
+
this.entries.push({ href, state });
|
|
135
|
+
this.index = this.entries.length - 1;
|
|
136
|
+
this.emit();
|
|
137
|
+
}
|
|
138
|
+
replace(href, state) {
|
|
139
|
+
this.entries[this.index] = { href, state };
|
|
140
|
+
this.emit();
|
|
141
|
+
}
|
|
142
|
+
emit() {
|
|
143
|
+
for (const listener of this.listeners) {
|
|
144
|
+
listener();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function createMemoryHistory(options) {
|
|
149
|
+
return new MemoryHistory(options);
|
|
150
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __reExport = (target, mod, secondTarget) => {
|
|
9
|
+
var keys = __getOwnPropNames(mod);
|
|
10
|
+
for (let key of keys)
|
|
11
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
12
|
+
__defProp(target, key, {
|
|
13
|
+
get: __accessProp.bind(mod, key),
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
if (secondTarget) {
|
|
17
|
+
for (let key of keys)
|
|
18
|
+
if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
|
|
19
|
+
__defProp(secondTarget, key, {
|
|
20
|
+
get: __accessProp.bind(mod, key),
|
|
21
|
+
enumerable: true
|
|
22
|
+
});
|
|
23
|
+
return secondTarget;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (from) => {
|
|
27
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
28
|
+
if (entry)
|
|
29
|
+
return entry;
|
|
30
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (var key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(entry, key))
|
|
34
|
+
__defProp(entry, key, {
|
|
35
|
+
get: __accessProp.bind(from, key),
|
|
36
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
__moduleCache.set(from, entry);
|
|
40
|
+
return entry;
|
|
41
|
+
};
|
|
42
|
+
var __moduleCache;
|
|
43
|
+
|
|
44
|
+
// packages/react/src/index.ts
|
|
45
|
+
var exports_src = {};
|
|
46
|
+
module.exports = __toCommonJS(exports_src);
|
|
47
|
+
__reExport(exports_src, require("./history.cjs"), module.exports);
|
|
48
|
+
__reExport(exports_src, require("./router.cjs"), module.exports);
|