ezh 0.2.0 → 0.2.1
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/lib/2.min.mjs +1 -0
- package/lib/3.min.mjs +1 -0
- package/lib/debugCheck.min.mjs +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.min.mjs +1 -0
- package/package.json +4 -5
- package/lib/RbTree.js +0 -727
- package/lib/bundle.min.js +0 -1
- package/lib/debugCheck.d.ts +0 -2
- package/lib/debugCheck.js +0 -69
- package/lib/elements.js +0 -1256
- package/lib/index.js +0 -4
- package/lib/router.js +0 -111
- package/lib/state.js +0 -340
package/lib/index.js
DELETED
package/lib/router.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Path } from 'path-parser';
|
|
2
|
-
import { $ezh } from './elements';
|
|
3
|
-
import { useState } from './state';
|
|
4
|
-
export { navigate, route, Router, Link, RouteLink, };
|
|
5
|
-
let c = 0;
|
|
6
|
-
const d = useState({ ver: 0 });
|
|
7
|
-
window.addEventListener('popstate', () => {
|
|
8
|
-
d.ver = ++c;
|
|
9
|
-
});
|
|
10
|
-
const navigate = (to, replace) => {
|
|
11
|
-
const { pathname, search, hash } = window.location;
|
|
12
|
-
const a = `${pathname}${search}${hash}`;
|
|
13
|
-
if (to !== a) {
|
|
14
|
-
if (!replace) {
|
|
15
|
-
window.history.pushState(undefined, '', to);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
window.history.replaceState(undefined, '', to);
|
|
19
|
-
}
|
|
20
|
-
queueMicrotask(() => {
|
|
21
|
-
d.ver = ++c;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const e = 'ezhEZH';
|
|
26
|
-
class h {
|
|
27
|
-
constructor(com, path, needAuth) {
|
|
28
|
-
this.com = com;
|
|
29
|
-
this.b = Path.createPath(path + e);
|
|
30
|
-
this.needAuth = needAuth;
|
|
31
|
-
}
|
|
32
|
-
com;
|
|
33
|
-
needAuth;
|
|
34
|
-
parseParam(url) {
|
|
35
|
-
const param = this.b.test(url);
|
|
36
|
-
if (param) {
|
|
37
|
-
delete param[e];
|
|
38
|
-
return param;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
buildUrl(j) {
|
|
42
|
-
throw new Error('WildcardRoute does not support buildUrl');
|
|
43
|
-
}
|
|
44
|
-
b;
|
|
45
|
-
}
|
|
46
|
-
class i {
|
|
47
|
-
constructor(com, path, needAuth) {
|
|
48
|
-
this.com = com;
|
|
49
|
-
this.b = Path.createPath(path);
|
|
50
|
-
this.needAuth = needAuth;
|
|
51
|
-
}
|
|
52
|
-
com;
|
|
53
|
-
needAuth;
|
|
54
|
-
parseParam(url) {
|
|
55
|
-
return this.b.test(url);
|
|
56
|
-
}
|
|
57
|
-
buildUrl(param) {
|
|
58
|
-
return this.b.build(param);
|
|
59
|
-
}
|
|
60
|
-
b;
|
|
61
|
-
}
|
|
62
|
-
const route = (com, path, needAuth = true) => {
|
|
63
|
-
return path.endsWith('*') ? new h(com, path, needAuth) : new i(com, path, needAuth);
|
|
64
|
-
};
|
|
65
|
-
const Router = ({ routes, notFound, checkAuth }) => {
|
|
66
|
-
c = d.ver;
|
|
67
|
-
const { pathname, search, hash } = window.location;
|
|
68
|
-
const a = `${pathname}${search}${hash}`;
|
|
69
|
-
const { $s, $k, $c } = $ezh;
|
|
70
|
-
for (const key in routes) {
|
|
71
|
-
const route = routes[key];
|
|
72
|
-
const param = route.parseParam(a);
|
|
73
|
-
if (param) {
|
|
74
|
-
if (checkAuth && route.needAuth) {
|
|
75
|
-
const f = checkAuth(a);
|
|
76
|
-
if (f) {
|
|
77
|
-
navigate(f);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return $s($k(key), $c('_', route.com, param, undefined, -1));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return notFound ? $s($k('404'), $c('_', notFound, {})) : undefined;
|
|
85
|
-
};
|
|
86
|
-
const g = (u, url, replace) => {
|
|
87
|
-
u.preventDefault();
|
|
88
|
-
const { pathname, search, hash } = window.location;
|
|
89
|
-
const a = `${pathname}${search}${hash}`;
|
|
90
|
-
if (url !== a) {
|
|
91
|
-
if (!replace) {
|
|
92
|
-
window.history.pushState(undefined, '', url);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
window.history.replaceState(undefined, '', url);
|
|
96
|
-
}
|
|
97
|
-
d.ver = ++c;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const Link = (props, children) => {
|
|
101
|
-
const { href, className, style, title, replace } = props;
|
|
102
|
-
const onclick = href ? (u) => g(u, href, replace) : undefined;
|
|
103
|
-
return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
|
|
104
|
-
};
|
|
105
|
-
const RouteLink = (props, children) => {
|
|
106
|
-
const { route, params, className, style, title, replace } = props;
|
|
107
|
-
const href = route.buildUrl(params);
|
|
108
|
-
const onclick = (u) => g(u, href, replace);
|
|
109
|
-
return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=router.js.map
|
package/lib/state.js
DELETED
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { addComReader, o, refreshComReaders } from './elements';
|
|
2
|
-
const i = Symbol();
|
|
3
|
-
const k = Array.prototype;
|
|
4
|
-
const x = addComReader;
|
|
5
|
-
let m = (readerRecord, key) => {
|
|
6
|
-
m = refreshComReaders;
|
|
7
|
-
m(readerRecord, key);
|
|
8
|
-
};
|
|
9
|
-
export let u = false;
|
|
10
|
-
export const y = new WeakMap();
|
|
11
|
-
const r = (_) => {
|
|
12
|
-
return function (...n) {
|
|
13
|
-
const h = this.length;
|
|
14
|
-
let begin, d, l;
|
|
15
|
-
switch (_) {
|
|
16
|
-
case k.push:
|
|
17
|
-
begin = h;
|
|
18
|
-
d = begin + n.length;
|
|
19
|
-
l = h;
|
|
20
|
-
break;
|
|
21
|
-
case k.unshift:
|
|
22
|
-
begin = 0;
|
|
23
|
-
d = n.length;
|
|
24
|
-
l = h;
|
|
25
|
-
break;
|
|
26
|
-
case k.fill:
|
|
27
|
-
begin = n[1];
|
|
28
|
-
if (begin === undefined || begin <= -h) {
|
|
29
|
-
begin = 0;
|
|
30
|
-
}
|
|
31
|
-
else if (begin < 0) {
|
|
32
|
-
begin = h + begin;
|
|
33
|
-
}
|
|
34
|
-
d = n[2];
|
|
35
|
-
if (d === undefined || d > h) {
|
|
36
|
-
d = h;
|
|
37
|
-
}
|
|
38
|
-
else if (d <= -h) {
|
|
39
|
-
d = 0;
|
|
40
|
-
}
|
|
41
|
-
else if (d < 0) {
|
|
42
|
-
d = h + d;
|
|
43
|
-
}
|
|
44
|
-
l = d;
|
|
45
|
-
break;
|
|
46
|
-
case k.sort:
|
|
47
|
-
case k.reverse:
|
|
48
|
-
begin = d = 0;
|
|
49
|
-
l = h;
|
|
50
|
-
break;
|
|
51
|
-
case k.pop:
|
|
52
|
-
begin = d = h - 1;
|
|
53
|
-
l = h;
|
|
54
|
-
break;
|
|
55
|
-
case k.shift:
|
|
56
|
-
begin = d = 0;
|
|
57
|
-
l = h;
|
|
58
|
-
break;
|
|
59
|
-
default:
|
|
60
|
-
begin = n[0];
|
|
61
|
-
if (begin < 0) {
|
|
62
|
-
begin = h + begin;
|
|
63
|
-
}
|
|
64
|
-
d = n.length > 2 ? n.length - 2 : 0;
|
|
65
|
-
l = n[1];
|
|
66
|
-
if (l === undefined) {
|
|
67
|
-
l = h - begin;
|
|
68
|
-
}
|
|
69
|
-
l = l > 0 ? (l !== d ? h : begin + d) : (d ? h : begin);
|
|
70
|
-
d += begin;
|
|
71
|
-
}
|
|
72
|
-
const e = _.bind(this)(...n);
|
|
73
|
-
const p = this[i];
|
|
74
|
-
let q;
|
|
75
|
-
for (let b = begin; b < d; b++) {
|
|
76
|
-
q = this[b];
|
|
77
|
-
switch (typeof q) {
|
|
78
|
-
case 'object':
|
|
79
|
-
if (q) {
|
|
80
|
-
while (b < d) {
|
|
81
|
-
q = this[b];
|
|
82
|
-
if (q && !q[i]) {
|
|
83
|
-
this[b] = s(q);
|
|
84
|
-
}
|
|
85
|
-
b++;
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case 'undefined':
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (h !== this.length) {
|
|
95
|
-
m(p, 'length');
|
|
96
|
-
}
|
|
97
|
-
m(p, Symbol.iterator);
|
|
98
|
-
return e;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
const C = {
|
|
102
|
-
'push': r(k.push),
|
|
103
|
-
'unshift': r(k.unshift),
|
|
104
|
-
'fill': r(k.fill),
|
|
105
|
-
'sort': r(k.sort),
|
|
106
|
-
'reverse': r(k.reverse),
|
|
107
|
-
'pop': r(k.pop),
|
|
108
|
-
'shift': r(k.shift),
|
|
109
|
-
'splice': r(k.splice),
|
|
110
|
-
};
|
|
111
|
-
const D = (target, f) => {
|
|
112
|
-
const w = f.length;
|
|
113
|
-
const h = target.length;
|
|
114
|
-
let g;
|
|
115
|
-
for (let b = 0; b < w; b++) {
|
|
116
|
-
let c = f[b];
|
|
117
|
-
if (c && typeof c === 'object') {
|
|
118
|
-
do {
|
|
119
|
-
c = f[b];
|
|
120
|
-
g = target[b];
|
|
121
|
-
if (c) {
|
|
122
|
-
if (g) {
|
|
123
|
-
if (g !== c) {
|
|
124
|
-
g[i] = c;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
target[b] = s(c);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
target[b] = c;
|
|
133
|
-
}
|
|
134
|
-
} while (++b < w);
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
else if (c !== null && c !== undefined) {
|
|
138
|
-
do {
|
|
139
|
-
target[b] = f[b];
|
|
140
|
-
} while (++b < w);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
target[b] = c;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const p = target[i];
|
|
148
|
-
if (h !== w) {
|
|
149
|
-
if (h > w) {
|
|
150
|
-
target.length = w;
|
|
151
|
-
}
|
|
152
|
-
m(p, 'length');
|
|
153
|
-
}
|
|
154
|
-
m(p, Symbol.iterator);
|
|
155
|
-
};
|
|
156
|
-
const E = (target, z, f) => {
|
|
157
|
-
const A = { ...target };
|
|
158
|
-
let g;
|
|
159
|
-
for (const v in f) {
|
|
160
|
-
delete A[v];
|
|
161
|
-
const c = f[v];
|
|
162
|
-
if (c && typeof c === 'object') {
|
|
163
|
-
g = target[v];
|
|
164
|
-
if (g) {
|
|
165
|
-
g[i] = c;
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (target[v] !== c) {
|
|
170
|
-
z[v] = c;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
for (const v in A) {
|
|
174
|
-
delete z[v];
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const F = {
|
|
178
|
-
get(target, key) {
|
|
179
|
-
if (key !== i) {
|
|
180
|
-
let e = target[key];
|
|
181
|
-
if (e && e === k[key]) {
|
|
182
|
-
const B = C[key];
|
|
183
|
-
if (B) {
|
|
184
|
-
return B.bind(target);
|
|
185
|
-
}
|
|
186
|
-
e = e.bind(target);
|
|
187
|
-
}
|
|
188
|
-
x(target[i], key !== 'length' ? Symbol.iterator : key);
|
|
189
|
-
return e;
|
|
190
|
-
}
|
|
191
|
-
return target;
|
|
192
|
-
},
|
|
193
|
-
set(target, key, f) {
|
|
194
|
-
if (key !== i) {
|
|
195
|
-
if (target[key] === f) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
const p = target[i];
|
|
199
|
-
if (f && typeof f === 'object') {
|
|
200
|
-
f = s(f);
|
|
201
|
-
}
|
|
202
|
-
target[key] = f;
|
|
203
|
-
if (key === 'length') {
|
|
204
|
-
m(p, key);
|
|
205
|
-
}
|
|
206
|
-
m(p, Symbol.iterator);
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
D(target, f);
|
|
210
|
-
return true;
|
|
211
|
-
},
|
|
212
|
-
has(target, key) {
|
|
213
|
-
x(target[i], !isNaN(parseInt(key)) ? Symbol.iterator : key);
|
|
214
|
-
return key in target;
|
|
215
|
-
},
|
|
216
|
-
deleteProperty(target, key) {
|
|
217
|
-
if (!isNaN(parseInt(key))) {
|
|
218
|
-
key = Symbol.iterator;
|
|
219
|
-
}
|
|
220
|
-
if (target[key] !== undefined) {
|
|
221
|
-
m(target[i], key);
|
|
222
|
-
}
|
|
223
|
-
return delete target[key];
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
const G = {
|
|
227
|
-
get(target, key) {
|
|
228
|
-
if (key !== i) {
|
|
229
|
-
const e = target[key];
|
|
230
|
-
if (key !== 'id') {
|
|
231
|
-
x(target[i], key);
|
|
232
|
-
}
|
|
233
|
-
return e;
|
|
234
|
-
}
|
|
235
|
-
return target;
|
|
236
|
-
},
|
|
237
|
-
set(target, key, f, z) {
|
|
238
|
-
if (key !== i) {
|
|
239
|
-
if (target[key] === f) {
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
const p = target[i];
|
|
243
|
-
if (f && typeof f === 'object') {
|
|
244
|
-
f = s(f);
|
|
245
|
-
}
|
|
246
|
-
target[key] = f;
|
|
247
|
-
m(p, key);
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
E(target, z, f);
|
|
251
|
-
return true;
|
|
252
|
-
},
|
|
253
|
-
has(target, key) {
|
|
254
|
-
x(target[i], key);
|
|
255
|
-
return key in target;
|
|
256
|
-
},
|
|
257
|
-
deleteProperty(target, key) {
|
|
258
|
-
if (target[key] !== undefined) {
|
|
259
|
-
m(target[i], key);
|
|
260
|
-
}
|
|
261
|
-
return delete target[key];
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
const s = (state) => {
|
|
265
|
-
let target;
|
|
266
|
-
if (!Array.isArray(state)) {
|
|
267
|
-
target = {};
|
|
268
|
-
for (const key in state) {
|
|
269
|
-
const c = state[key];
|
|
270
|
-
target[key] = c && typeof c === 'object' ? s(c) : c;
|
|
271
|
-
}
|
|
272
|
-
state = new Proxy(target, G);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
target = [];
|
|
276
|
-
const length = state.length;
|
|
277
|
-
for (let b = 0; b < length; b++) {
|
|
278
|
-
let c = state[b];
|
|
279
|
-
if (c && typeof c === 'object') {
|
|
280
|
-
do {
|
|
281
|
-
target[b] = (c = state[b]) && s(c);
|
|
282
|
-
} while (++b < length);
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
else if (c !== null && c !== undefined) {
|
|
286
|
-
do {
|
|
287
|
-
target[b] = state[b];
|
|
288
|
-
} while (++b < length);
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
target[b] = c;
|
|
292
|
-
}
|
|
293
|
-
state = new Proxy(target, F);
|
|
294
|
-
}
|
|
295
|
-
target[i] = {};
|
|
296
|
-
return state;
|
|
297
|
-
};
|
|
298
|
-
const $ = (a, a1) => {
|
|
299
|
-
if (a1) {
|
|
300
|
-
a.ver = 0;
|
|
301
|
-
a.hook(0, a.state);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
a.com.watchMountChange('s', $, a);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
export const bindData = (data, key) => {
|
|
308
|
-
return [data, key, data[key]];
|
|
309
|
-
};
|
|
310
|
-
export const useState = (initial, hook) => {
|
|
311
|
-
const com = o;
|
|
312
|
-
if (com.id) {
|
|
313
|
-
let t = y.get(com);
|
|
314
|
-
if (t) {
|
|
315
|
-
const { state, hook } = t;
|
|
316
|
-
if (hook) {
|
|
317
|
-
if (!t.ver) {
|
|
318
|
-
com.watchMountChange('s', $, t);
|
|
319
|
-
}
|
|
320
|
-
u = true;
|
|
321
|
-
hook(++t.ver, state);
|
|
322
|
-
u = false;
|
|
323
|
-
}
|
|
324
|
-
return state;
|
|
325
|
-
}
|
|
326
|
-
const state = s(initial);
|
|
327
|
-
t = { com, state, ver: 1, hook };
|
|
328
|
-
y.set(com, t);
|
|
329
|
-
if (hook) {
|
|
330
|
-
com.watchMountChange('s', $, t);
|
|
331
|
-
u = true;
|
|
332
|
-
hook(1, state);
|
|
333
|
-
u = false;
|
|
334
|
-
}
|
|
335
|
-
return state;
|
|
336
|
-
}
|
|
337
|
-
const state = s(initial);
|
|
338
|
-
return state;
|
|
339
|
-
};
|
|
340
|
-
//# sourceMappingURL=state.js.map
|