@viewfly/router 1.1.9 → 2.0.0-alpha.0
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/bundles/index.d.ts +1 -1
- package/bundles/index.esm.js +85 -28
- package/bundles/index.js +83 -26
- package/package.json +3 -3
package/bundles/index.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ declare function Link(props: LinkProps): () => _viewfly_core_jsx_runtime.JSX.Ele
|
|
|
81
81
|
interface RouterOutletProps extends Props {
|
|
82
82
|
config: RouteConfig[];
|
|
83
83
|
}
|
|
84
|
-
declare
|
|
84
|
+
declare function RouterOutlet(props: RouterOutletProps): () => _viewfly_core_jsx_runtime.JSX.Element;
|
|
85
85
|
|
|
86
86
|
declare class RouterModule implements Module {
|
|
87
87
|
baseUrl: string;
|
package/bundles/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import { Injectable, inject, createSignal, onUnmounted, makeError,
|
|
1
|
+
import { jsx } from '@viewfly/core/jsx-runtime';
|
|
2
|
+
import { Injectable, inject, createSignal, onUnmounted, makeError, createContext } from '@viewfly/core';
|
|
3
3
|
import { Subject, Subscription, fromEvent } from '@tanbo/stream';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
@@ -37,7 +37,12 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
37
37
|
|
|
38
38
|
class Navigator {
|
|
39
39
|
constructor(baseUrl) {
|
|
40
|
-
this
|
|
40
|
+
Object.defineProperty(this, "baseUrl", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: baseUrl
|
|
45
|
+
});
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
function formatUrl(pathname, urlFormatParams) {
|
|
@@ -66,8 +71,24 @@ let BrowserNavigator = class BrowserNavigator extends Navigator {
|
|
|
66
71
|
}
|
|
67
72
|
constructor(baseUrl) {
|
|
68
73
|
super(baseUrl);
|
|
69
|
-
this
|
|
70
|
-
|
|
74
|
+
Object.defineProperty(this, "onUrlChanged", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "urlChangeEvent", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: new Subject()
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(this, "subscription", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: new Subscription()
|
|
91
|
+
});
|
|
71
92
|
this.onUrlChanged = this.urlChangeEvent.asObservable();
|
|
72
93
|
this.subscription.add(fromEvent(window, 'popstate').subscribe(() => {
|
|
73
94
|
this.urlChangeEvent.next();
|
|
@@ -157,10 +178,36 @@ class Router {
|
|
|
157
178
|
return '';
|
|
158
179
|
}
|
|
159
180
|
constructor(navigator, parent, path) {
|
|
160
|
-
this
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
181
|
+
Object.defineProperty(this, "navigator", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
configurable: true,
|
|
184
|
+
writable: true,
|
|
185
|
+
value: navigator
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(this, "parent", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
configurable: true,
|
|
190
|
+
writable: true,
|
|
191
|
+
value: parent
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(this, "path", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: true,
|
|
197
|
+
value: path
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(this, "onRefresh", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
configurable: true,
|
|
202
|
+
writable: true,
|
|
203
|
+
value: void 0
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(this, "refreshEvent", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
configurable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: new Subject()
|
|
210
|
+
});
|
|
164
211
|
this.onRefresh = this.refreshEvent.asObservable();
|
|
165
212
|
}
|
|
166
213
|
navigateTo(path, params, fragment) {
|
|
@@ -269,24 +316,18 @@ function Link(props) {
|
|
|
269
316
|
}
|
|
270
317
|
|
|
271
318
|
const routerErrorFn = makeError('RouterOutlet');
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
provide: Router,
|
|
275
|
-
useFactory(navigator, router) {
|
|
276
|
-
return new Router(navigator, router, '');
|
|
277
|
-
},
|
|
278
|
-
deps: [
|
|
279
|
-
[Navigator],
|
|
280
|
-
[Router, new SkipSelf()]
|
|
281
|
-
]
|
|
282
|
-
}]
|
|
283
|
-
}, function RouterOutlet(props) {
|
|
284
|
-
const children = createSignal(null);
|
|
285
|
-
const router = inject(Router, null, InjectFlags.SkipSelf);
|
|
286
|
-
const childRouter = inject(Router);
|
|
319
|
+
function RouterOutlet(props) {
|
|
320
|
+
const router = inject(Router, null);
|
|
287
321
|
if (router === null) {
|
|
288
322
|
throw routerErrorFn('cannot found parent Router.');
|
|
289
323
|
}
|
|
324
|
+
const navigator = inject(Navigator);
|
|
325
|
+
const childRouter = new Router(navigator, router, '');
|
|
326
|
+
const Context = createContext([{
|
|
327
|
+
provide: Router,
|
|
328
|
+
useValue: childRouter
|
|
329
|
+
}]);
|
|
330
|
+
const children = createSignal(null);
|
|
290
331
|
const subscription = router.onRefresh.subscribe(() => {
|
|
291
332
|
updateChildren();
|
|
292
333
|
});
|
|
@@ -320,14 +361,30 @@ const RouterOutlet = withAnnotation({
|
|
|
320
361
|
}
|
|
321
362
|
updateChildren();
|
|
322
363
|
return () => {
|
|
323
|
-
return jsx(
|
|
364
|
+
return jsx(Context, { children: children() });
|
|
324
365
|
};
|
|
325
|
-
}
|
|
366
|
+
}
|
|
326
367
|
|
|
327
368
|
class RouterModule {
|
|
328
369
|
constructor(baseUrl = '') {
|
|
329
|
-
this
|
|
330
|
-
|
|
370
|
+
Object.defineProperty(this, "baseUrl", {
|
|
371
|
+
enumerable: true,
|
|
372
|
+
configurable: true,
|
|
373
|
+
writable: true,
|
|
374
|
+
value: baseUrl
|
|
375
|
+
});
|
|
376
|
+
Object.defineProperty(this, "subscription", {
|
|
377
|
+
enumerable: true,
|
|
378
|
+
configurable: true,
|
|
379
|
+
writable: true,
|
|
380
|
+
value: new Subscription()
|
|
381
|
+
});
|
|
382
|
+
Object.defineProperty(this, "navigator", {
|
|
383
|
+
enumerable: true,
|
|
384
|
+
configurable: true,
|
|
385
|
+
writable: true,
|
|
386
|
+
value: void 0
|
|
387
|
+
});
|
|
331
388
|
this.navigator = new BrowserNavigator(this.baseUrl);
|
|
332
389
|
}
|
|
333
390
|
setup(app) {
|
package/bundles/index.js
CHANGED
|
@@ -39,7 +39,12 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
39
39
|
|
|
40
40
|
class Navigator {
|
|
41
41
|
constructor(baseUrl) {
|
|
42
|
-
this
|
|
42
|
+
Object.defineProperty(this, "baseUrl", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: baseUrl
|
|
47
|
+
});
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
function formatUrl(pathname, urlFormatParams) {
|
|
@@ -68,8 +73,24 @@ exports.BrowserNavigator = class BrowserNavigator extends Navigator {
|
|
|
68
73
|
}
|
|
69
74
|
constructor(baseUrl) {
|
|
70
75
|
super(baseUrl);
|
|
71
|
-
this
|
|
72
|
-
|
|
76
|
+
Object.defineProperty(this, "onUrlChanged", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: void 0
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this, "urlChangeEvent", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
configurable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
value: new stream.Subject()
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "subscription", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: new stream.Subscription()
|
|
93
|
+
});
|
|
73
94
|
this.onUrlChanged = this.urlChangeEvent.asObservable();
|
|
74
95
|
this.subscription.add(stream.fromEvent(window, 'popstate').subscribe(() => {
|
|
75
96
|
this.urlChangeEvent.next();
|
|
@@ -159,10 +180,36 @@ class Router {
|
|
|
159
180
|
return '';
|
|
160
181
|
}
|
|
161
182
|
constructor(navigator, parent, path) {
|
|
162
|
-
this
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
183
|
+
Object.defineProperty(this, "navigator", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: navigator
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(this, "parent", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
configurable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
value: parent
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(this, "path", {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
configurable: true,
|
|
198
|
+
writable: true,
|
|
199
|
+
value: path
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(this, "onRefresh", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
configurable: true,
|
|
204
|
+
writable: true,
|
|
205
|
+
value: void 0
|
|
206
|
+
});
|
|
207
|
+
Object.defineProperty(this, "refreshEvent", {
|
|
208
|
+
enumerable: true,
|
|
209
|
+
configurable: true,
|
|
210
|
+
writable: true,
|
|
211
|
+
value: new stream.Subject()
|
|
212
|
+
});
|
|
166
213
|
this.onRefresh = this.refreshEvent.asObservable();
|
|
167
214
|
}
|
|
168
215
|
navigateTo(path, params, fragment) {
|
|
@@ -271,24 +318,18 @@ function Link(props) {
|
|
|
271
318
|
}
|
|
272
319
|
|
|
273
320
|
const routerErrorFn = core.makeError('RouterOutlet');
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
provide: Router,
|
|
277
|
-
useFactory(navigator, router) {
|
|
278
|
-
return new Router(navigator, router, '');
|
|
279
|
-
},
|
|
280
|
-
deps: [
|
|
281
|
-
[Navigator],
|
|
282
|
-
[Router, new core.SkipSelf()]
|
|
283
|
-
]
|
|
284
|
-
}]
|
|
285
|
-
}, function RouterOutlet(props) {
|
|
286
|
-
const children = core.createSignal(null);
|
|
287
|
-
const router = core.inject(Router, null, core.InjectFlags.SkipSelf);
|
|
288
|
-
const childRouter = core.inject(Router);
|
|
321
|
+
function RouterOutlet(props) {
|
|
322
|
+
const router = core.inject(Router, null);
|
|
289
323
|
if (router === null) {
|
|
290
324
|
throw routerErrorFn('cannot found parent Router.');
|
|
291
325
|
}
|
|
326
|
+
const navigator = core.inject(Navigator);
|
|
327
|
+
const childRouter = new Router(navigator, router, '');
|
|
328
|
+
const Context = core.createContext([{
|
|
329
|
+
provide: Router,
|
|
330
|
+
useValue: childRouter
|
|
331
|
+
}]);
|
|
332
|
+
const children = core.createSignal(null);
|
|
292
333
|
const subscription = router.onRefresh.subscribe(() => {
|
|
293
334
|
updateChildren();
|
|
294
335
|
});
|
|
@@ -322,14 +363,30 @@ const RouterOutlet = core.withAnnotation({
|
|
|
322
363
|
}
|
|
323
364
|
updateChildren();
|
|
324
365
|
return () => {
|
|
325
|
-
return jsxRuntime.jsx(
|
|
366
|
+
return jsxRuntime.jsx(Context, { children: children() });
|
|
326
367
|
};
|
|
327
|
-
}
|
|
368
|
+
}
|
|
328
369
|
|
|
329
370
|
class RouterModule {
|
|
330
371
|
constructor(baseUrl = '') {
|
|
331
|
-
this
|
|
332
|
-
|
|
372
|
+
Object.defineProperty(this, "baseUrl", {
|
|
373
|
+
enumerable: true,
|
|
374
|
+
configurable: true,
|
|
375
|
+
writable: true,
|
|
376
|
+
value: baseUrl
|
|
377
|
+
});
|
|
378
|
+
Object.defineProperty(this, "subscription", {
|
|
379
|
+
enumerable: true,
|
|
380
|
+
configurable: true,
|
|
381
|
+
writable: true,
|
|
382
|
+
value: new stream.Subscription()
|
|
383
|
+
});
|
|
384
|
+
Object.defineProperty(this, "navigator", {
|
|
385
|
+
enumerable: true,
|
|
386
|
+
configurable: true,
|
|
387
|
+
writable: true,
|
|
388
|
+
value: void 0
|
|
389
|
+
});
|
|
333
390
|
this.navigator = new exports.BrowserNavigator(this.baseUrl);
|
|
334
391
|
}
|
|
335
392
|
setup(app) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"description": "A routing library based on the Viewfly framework that can be run in the browser or Nodejs background.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"keywords": [],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@tanbo/stream": "^1.2.4",
|
|
18
|
-
"@viewfly/core": "^
|
|
18
|
+
"@viewfly/core": "^2.0.0-alpha.0",
|
|
19
19
|
"url": "^0.11.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"bugs": {
|
|
38
38
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5fdcdcdca224d1eecdfd6a68abb1c3fb9c01d88a"
|
|
41
41
|
}
|