lit-ui-router 1.16.0 → 1.16.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/custom-elements.json +35 -2
- package/dist/development/router-subscription.js +65 -0
- package/dist/development/router-subscription.js.map +1 -0
- package/dist/development/sref-status-controller.js +24 -4
- package/dist/development/sref-status-controller.js.map +1 -1
- package/dist/development/transition-controller.js +22 -3
- package/dist/development/transition-controller.js.map +1 -1
- package/dist/development/ui-router.js +5 -10
- package/dist/development/ui-router.js.map +1 -1
- package/dist/development/ui-view.js +15 -3
- package/dist/development/ui-view.js.map +1 -1
- package/dist/router-subscription.d.ts +46 -0
- package/dist/router-subscription.d.ts.map +1 -0
- package/dist/router-subscription.js +65 -0
- package/dist/router-subscription.js.map +1 -0
- package/dist/sref-status-controller.d.ts +9 -2
- package/dist/sref-status-controller.d.ts.map +1 -1
- package/dist/sref-status-controller.js +24 -4
- package/dist/sref-status-controller.js.map +1 -1
- package/dist/transition-controller.d.ts +10 -2
- package/dist/transition-controller.d.ts.map +1 -1
- package/dist/transition-controller.js +22 -3
- package/dist/transition-controller.js.map +1 -1
- package/dist/ui-router.d.ts +6 -5
- package/dist/ui-router.d.ts.map +1 -1
- package/dist/ui-router.js +5 -10
- package/dist/ui-router.js.map +1 -1
- package/dist/ui-view.d.ts +14 -1
- package/dist/ui-view.d.ts.map +1 -1
- package/dist/ui-view.js +15 -3
- package/dist/ui-view.js.map +1 -1
- package/package.json +1 -1
- package/src/router-subscription.ts +132 -0
- package/src/sref-status-controller.ts +45 -12
- package/src/transition-controller.ts +37 -7
- package/src/ui-router.ts +18 -24
- package/src/ui-view.ts +37 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sref-status-controller.js","mappings":"AACA,SAAS,eAA2D;AAEpE,SAAS,yBAAyB;
|
|
1
|
+
{"version":3,"file":"sref-status-controller.js","mappings":"AACA,SAAS,eAA2D;AAEpE,SAAS,yBAAyB;AAClC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ACP;EACF,CAAC;EAED,MAAM,SAAS,KAAK,QAAQ;EAC5B,IAAI,QACF,KAAK,MAAM,MAAM;OAEjB,kBACE,MACA,kCAAkC,KAAK,UAAU,IACjD,6BACF;EAGF,KAAK,QAAQ;CACf;CAGA,mBAAyB;EACvB,KAAK,QAAQ;EACb,OAAO,KAAK,cAAc,QACxB,KAAK,cAAc,MAAM,CAAC,GAAG;EAE/B,IAAI,CAAC,KAAK,QAAQ,QAEhB,KAAK,QAAQ,SAAS;CAE1B;CAEA,MAAc,QAAwB;EACpC,KAAK,oBAAoB,KACvB,OAAO,kBAAkB,QAAQ,CAAC,GAAG,KAAK,mBAAmB,EAC3D,UAAU,UACZ,CAAC,GACD,OAAO,cAAc,gBAAgB,KAAK,eAAe,CAC3D;CACF;CAEA,UAAwB;EACtB,KAAK;EACL,OAAO,KAAK,oBAAoB,QAC9B,KAAK,oBAAoB,MAAM,CAAC,GAAG;CAEvC;CAkBA,QAAQ,OAAwB;EAC9B,IAAI,KAAK,QAAQ,KAAK,GACpB,KAAK,KAAK,cAAc;CAE5B;CAGA,QAAgB,OAA2B;EACzC,MAAM,SAAS,KAAK;EACpB,KAAK,UAAU,KAAK,QAAQ,OAAO,KAAK;EACxC,MAAM,QAAQ,CAAC,KAAK;EACpB,KAAK,WAAW;EAChB,OAAO,SAAS,CAAC,UAAU,QAAQ,KAAK,OAAO;CACjD;AAgCF","names":[],"ignoreList":[],"sources":["../src/sref-status-controller.ts"]}
|
|
@@ -47,8 +47,10 @@ export interface TransitionControllerOptions {
|
|
|
47
47
|
* The {@link UIRouter} instance to observe.
|
|
48
48
|
*
|
|
49
49
|
* When omitted, the controller discovers the router from an ancestor
|
|
50
|
-
* <code><ui-router></code> (or <code><ui-view></code>)
|
|
51
|
-
*
|
|
50
|
+
* <code><ui-router></code> (or <code><ui-view></code>) each time
|
|
51
|
+
* the host connects, and follows the placeholder router a
|
|
52
|
+
* <code><ui-router></code> mints for itself to the one that replaces
|
|
53
|
+
* it, synchronizing again with the `'hostConnected'` reason.
|
|
52
54
|
*/
|
|
53
55
|
router?: UIRouter;
|
|
54
56
|
/**
|
|
@@ -120,6 +122,8 @@ export declare class TransitionController implements ReactiveController {
|
|
|
120
122
|
private readonly host;
|
|
121
123
|
private readonly options;
|
|
122
124
|
private readonly deregisterFns;
|
|
125
|
+
/** drops the subscription to a provider that may still replace its router */
|
|
126
|
+
private unsubscribe?;
|
|
123
127
|
private _router?;
|
|
124
128
|
private _transition?;
|
|
125
129
|
constructor(host: ReactiveControllerHost & Element, options?: TransitionControllerOptions);
|
|
@@ -152,6 +156,10 @@ export declare class TransitionController implements ReactiveController {
|
|
|
152
156
|
hostConnected(): void;
|
|
153
157
|
/** @internal */
|
|
154
158
|
hostDisconnected(): void;
|
|
159
|
+
private watch;
|
|
160
|
+
private unwatch;
|
|
161
|
+
/** What a disconnect and reconnect would do, for the router that replaced the one found. */
|
|
162
|
+
private readonly onRouterReplaced;
|
|
155
163
|
private notify;
|
|
156
164
|
}
|
|
157
165
|
//# sourceMappingURL=transition-controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition-controller.d.ts","mappings":"AAAA,SACE,mBAEA,WACA,kBACA,aACA,YACA,UACA,uBACK;AACP,SAAS,oBAAoB,8BAA8B;;;;;;;;;;AAgB3D,YAAY,sBACR,aACA,YACA,cACA;;;;;;;;;;AAWJ,YAAY,2BAA2B,sBAAsB;;;;;;;;;;;;;;;;;AAkB7D,YAAY,sBACV,YAAY,wBACZ,QAAQ;;;;;;AAQV,iBAAiB,4BAA4B
|
|
1
|
+
{"version":3,"file":"transition-controller.d.ts","mappings":"AAAA,SACE,mBAEA,WACA,kBACA,aACA,YACA,UACA,uBACK;AACP,SAAS,oBAAoB,8BAA8B;;;;;;;;;;AAgB3D,YAAY,sBACR,aACA,YACA,cACA;;;;;;;;;;AAWJ,YAAY,2BAA2B,sBAAsB;;;;;;;;;;;;;;;;;AAkB7D,YAAY,sBACV,YAAY,wBACZ,QAAQ;;;;;;AAQV,iBAAiB,4BAA4B;;;;;;;;;;CAU3C,SAAS;;;;;;;CAQT,WAAW;;;;;;CAOX,SAAS;;;;;CAMT,WAAW;AACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,OAAO,cAAM,gCAAgC,mBAAmB;CAC9D,iBAAiB;CAEjB,iBAAiB;CAEjB,iBAAiB;;CAGjB,QAAQ;CAER,QAAQ;CAER,QAAQ;CAER,YACE,MAAM,yBAAyB,SAC/B,UAAS;;;;;;;CAcX,IAAI,UAAU;;CAKd,IAAI,WAAW;;CAKf,IAAI,UAAU;;CAKd,IAAI,WAAW;;;;;CAQf,IAAI,cAAc;;;;;;;CAUlB,SAAS,aAAa,aAAa,SAAS;;CAK5C;;CAcA;CAMA,QAAQ;CA0BR,QAAQ;;CAOR,iBAAiB;CAQjB,QAAQ;AASV","names":[],"ignoreList":[],"sources":["../src/transition-controller.ts"]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subscribeRouter } from "./router-subscription.js";
|
|
2
2
|
export class TransitionController {
|
|
3
3
|
constructor(host, options = {}) {
|
|
4
4
|
this.deregisterFns = [];
|
|
5
|
+
this.onRouterReplaced = (router) => {
|
|
6
|
+
this.unsubscribe = void 0;
|
|
7
|
+
this.unwatch();
|
|
8
|
+
this._router = router;
|
|
9
|
+
this._transition = void 0;
|
|
10
|
+
this.watch();
|
|
11
|
+
};
|
|
5
12
|
this.host = host;
|
|
6
13
|
this.options = options;
|
|
7
14
|
this._router = options.router;
|
|
@@ -26,7 +33,19 @@ export class TransitionController {
|
|
|
26
33
|
return this._router?.stateService.includes(stateOrName, params) ?? false;
|
|
27
34
|
}
|
|
28
35
|
hostConnected() {
|
|
29
|
-
|
|
36
|
+
if (!this.options.router) {
|
|
37
|
+
const { router, unsubscribe } = subscribeRouter(this.host, this.onRouterReplaced);
|
|
38
|
+
this._router = router ?? this._router;
|
|
39
|
+
this.unsubscribe = unsubscribe;
|
|
40
|
+
}
|
|
41
|
+
this.watch();
|
|
42
|
+
}
|
|
43
|
+
hostDisconnected() {
|
|
44
|
+
this.unsubscribe?.();
|
|
45
|
+
this.unsubscribe = void 0;
|
|
46
|
+
this.unwatch();
|
|
47
|
+
}
|
|
48
|
+
watch() {
|
|
30
49
|
const router = this._router;
|
|
31
50
|
if (!router) return;
|
|
32
51
|
const criteria = this.options.criteria ?? {};
|
|
@@ -34,7 +53,7 @@ export class TransitionController {
|
|
|
34
53
|
for (const event of events) this.deregisterFns.push(router.transitionService[event](criteria, (transition) => this.notify(transition, event)));
|
|
35
54
|
this.notify(router.globals.successfulTransitions.peekTail(), "hostConnected");
|
|
36
55
|
}
|
|
37
|
-
|
|
56
|
+
unwatch() {
|
|
38
57
|
while (this.deregisterFns.length) this.deregisterFns.shift()?.();
|
|
39
58
|
}
|
|
40
59
|
notify(transition, reason) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition-controller.js","mappings":"AAYA,SAAS,
|
|
1
|
+
{"version":3,"file":"transition-controller.js","mappings":"AAYA,SAAS,uBAAuB;AAyIhC,OAAO,MAAM,qBAAmD;CAc9D,YACE,MACA,UAAuC,CAAC,GACxC;uBAZ+C,CAAC;2BAoHb,WAA2B;GAC9D,KAAK,cAAc;GACnB,KAAK,QAAQ;GACb,KAAK,UAAU;GACf,KAAK,cAAc;GACnB,KAAK,MAAM;EACb;EA7GE,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,KAAK,UAAU,QAAQ;EACvB,KAAK,cAAc,IAAI;CACzB;CAQA,IAAI,SAA+B;EACjC,OAAO,KAAK;CACd;CAGA,IAAI,UAAuC;EACzC,OAAO,KAAK,SAAS;CACvB;CAGA,IAAI,SAAoB;EACtB,OAAO,KAAK,SAAS,UAAU,CAAC;CAClC;CAGA,IAAI,UAAwC;EAC1C,OAAO,KAAK,SAAS;CACvB;CAMA,IAAI,aAAqC;EACvC,OAAO,KAAK;CACd;CAQA,SAAS,aAA0B,QAA6B;EAC9D,OAAO,KAAK,SAAS,aAAa,SAAS,aAAa,MAAM,KAAK;CACrE;CAGA,gBAAsB;EACpB,IAAI,CAAC,KAAK,QAAQ,QAAQ;GACxB,MAAM,EAAE,QAAQ,gBAAgB,gBAC9B,KAAK,MACL,KAAK,gBACP;GAEA,KAAK,UAAU,UAAU,KAAK;GAC9B,KAAK,cAAc;EACrB;EACA,KAAK,MAAM;CACb;CAGA,mBAAyB;EACvB,KAAK,cAAc;EACnB,KAAK,cAAc;EACnB,KAAK,QAAQ;CACf;CAEA,QAAsB;EACpB,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QACH;EAGF,MAAM,WAAW,KAAK,QAAQ,YAAY,CAAC;EAC3C,MAAM,SAAS,KAAK,QAAQ,UAAU,CAAC,WAAW;EAElD,KAAK,MAAM,SAAS,QAClB,KAAK,cAAc,KACjB,OAAO,kBAAkB,MAAM,CAC7B,WACC,eAAe,KAAK,OAAO,YAAY,KAAK,CAC/C,CACF;EAKF,KAAK,OACH,OAAO,QAAQ,sBAAsB,SAAS,GAC9C,eACF;CACF;CAEA,UAAwB;EACtB,OAAO,KAAK,cAAc,QACxB,KAAK,cAAc,MAAM,CAAC,GAAG;CAEjC;CAWA,OACE,YACA,QACS;EACT,KAAK,cAAc,cAAc,KAAK;EACtC,MAAM,SAAS,KAAK,QAAQ,WAAW,YAAY,MAAM;EACzD,KAAK,KAAK,cAAc;EACxB,OAAO;CACT;AACF","names":[],"ignoreList":[],"sources":["../src/transition-controller.ts"]}
|
package/dist/ui-router.d.ts
CHANGED
|
@@ -63,15 +63,16 @@ export declare class UIRouterLitElement extends LitElement {
|
|
|
63
63
|
/** @internal */
|
|
64
64
|
static onUiRouterContextEvent(uiRouter?: UIRouterLit): (event: UiRouterContextEvent) => void;
|
|
65
65
|
private readonly onUiRouterContextEvent;
|
|
66
|
+
/** Subscribers that took the placeholder, owed the app's router. */
|
|
67
|
+
private readonly routerSubscribers;
|
|
66
68
|
/**
|
|
67
69
|
* Answers a `context-request` for the router context.
|
|
68
70
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
71
|
+
* While the placeholder minted on connect stands, a `subscribe` request is
|
|
72
|
+
* kept and called once more with the router that replaces it, and gets an
|
|
73
|
+
* unsubscribe that drops it. Any other answer is final: one call and a no-op
|
|
74
|
+
* unsubscribe, since a later swap is unsupported and only warns.
|
|
73
75
|
*/
|
|
74
|
-
static onContextRequest(uiRouter?: UIRouterLit): (event: Event) => void;
|
|
75
76
|
private readonly onContextRequest;
|
|
76
77
|
/**
|
|
77
78
|
* Answers the parent-view seek of every `<ui-view>` below, declining to name
|
package/dist/ui-router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-router.d.ts","mappings":"AAAA,SAAe,kBAAkB;AACjC,cAAc,gBAAgB,sBAAsB;
|
|
1
|
+
{"version":3,"file":"ui-router.d.ts","mappings":"AAAA,SAAe,kBAAkB;AACjC,cAAc,gBAAgB,sBAAsB;AAIpD,SAAS,mBAAmB;AAG5B,cAAc,4BAAgD;AAG9D,cAAc,sBAAsB,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;AA0B9D,OAAO,cAAM,2BAA2B,WAAW;;;;;CAKjD,AACA,UAAU;;CAGV,OAAO;;CAGP,OAAO;;CAGP,OAAO,qBAAqB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;CA8BrD,OAAO,WAAW,WAAW,UAAU;;CAOvC,OAAO,uBACL,WAAW,eACT,OAAO;CAOX,iBAAiB;;CAKjB,iBAAiB;;;;;;;;;CAUjB,iBAAiB;;;;;;;;;;CAiBjB,iBAAiB;;CAMjB;;CAqBA,QAAQ;;CAGR,UAAU,WAAW,SAAS;;CAiB9B,UAAU;AAGZ;AAEA,iBAAiB,mBAAmB;;CAElC,oBAAoB;AACtB","names":[],"ignoreList":[],"sources":["../src/ui-router.ts"]}
|
package/dist/ui-router.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { html, LitElement } from "lit";
|
|
2
2
|
import { property } from "lit/decorators.js";
|
|
3
|
-
import { contextRequestEventName,
|
|
3
|
+
import { contextRequestEventName, requestRouter } from "./context.js";
|
|
4
4
|
import { UIRouterLit } from "./core.js";
|
|
5
5
|
import { warnRouterSwapped } from "./dev-warn.js";
|
|
6
6
|
import { uiRouterContextEventName, uiViewContextEventName } from "./events.js";
|
|
7
|
+
import { RouterSubscribers } from "./router-subscription.js";
|
|
7
8
|
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
8
|
-
const noUnsubscribe = () => {};
|
|
9
9
|
export class UIRouterLitElement extends LitElement {
|
|
10
10
|
constructor(..._args) {
|
|
11
11
|
super(..._args);
|
|
12
12
|
this.onUiRouterContextEvent = (event) => {
|
|
13
13
|
this.constructor.onUiRouterContextEvent(this.uiRouter)(event);
|
|
14
14
|
};
|
|
15
|
+
this.routerSubscribers = new RouterSubscribers();
|
|
15
16
|
this.onContextRequest = (event) => {
|
|
16
|
-
this.
|
|
17
|
+
this.routerSubscribers.answer(event, this.uiRouter, !!this.ownRouter && this.uiRouter === this.ownRouter);
|
|
17
18
|
};
|
|
18
19
|
this.onUiViewContextEvent = (event) => {
|
|
19
20
|
event.stopPropagation();
|
|
@@ -44,13 +45,6 @@ export class UIRouterLitElement extends LitElement {
|
|
|
44
45
|
event.detail.uiRouter = uiRouter;
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
|
-
static onContextRequest(uiRouter) {
|
|
48
|
-
return (event) => {
|
|
49
|
-
if (!uiRouter || !isRouterContextRequest(event)) return;
|
|
50
|
-
event.stopImmediatePropagation();
|
|
51
|
-
event.callback(uiRouter, event.subscribe ? noUnsubscribe : void 0);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
48
|
connectedCallback() {
|
|
55
49
|
super.connectedCallback();
|
|
56
50
|
if (!this.uiRouter) {
|
|
@@ -65,6 +59,7 @@ export class UIRouterLitElement extends LitElement {
|
|
|
65
59
|
willUpdate(changed) {
|
|
66
60
|
super.willUpdate(changed);
|
|
67
61
|
if (this.hasUpdated && changed.has("uiRouter") && changed.get("uiRouter") !== this.ownRouter) warnRouterSwapped(this);
|
|
62
|
+
if (this.uiRouter && this.uiRouter !== this.ownRouter) this.routerSubscribers.deliver(this.uiRouter);
|
|
68
63
|
}
|
|
69
64
|
render() {
|
|
70
65
|
return html`<slot></slot>`;
|
package/dist/ui-router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-router.js","mappings":"AAAA,SAAS,MAAM,kBAAkB;AAEjC,SAAS,gBAAgB;AAEzB,
|
|
1
|
+
{"version":3,"file":"ui-router.js","mappings":"AAAA,SAAS,MAAM,kBAAkB;AAEjC,SAAS,gBAAgB;AAEzB,SAAS,yBAAyB,qBAAqB;AACvD,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,0BAA0B,8BAA8B;AAEjE,SAAS,yBAAyB;;AA4BlC,OAAO,MAAM,2BAA2B,WAAW;;;iCA6DN,UAAgC;GACzE,KAAK,YAAY,uBAAuB,KAAK,QAAQ,CAAC,CAAC,KAAK;EAC9D;2BAGqC,IAAI,kBAAkB;2BAUtB,UAAiB;GACpD,KAAK,kBAAkB,OACrB,OACA,KAAK,UACL,CAAC,CAAC,KAAK,aAAa,KAAK,aAAa,KAAK,SAC7C;EACF;+BAWyC,UAA8B;GACrE,MAAM,gBAAgB;GACtB,MAAM,OAAO,aAAa;EAC5B;;;kCAvF0C;;;gCAGF;;CAGxC,OAAO,qBAAqB,UAA8C;EACxE,OAAO,IAAI,YAAY,KAAK,0BAA0B;GACpD,SAAS;GACT,UAAU;GACV,QAAQ,EACN,SACF;EACF,CAAC;CACH;CAsBA,OAAO,WAAW,WAA6C;EAC7D,MAAM,uBAAuB,KAAK,qBAAqB;EACvD,UAAU,cAAc,oBAAoB;EAC5C,OAAO,qBAAqB,OAAO,YAAY,cAAc,SAAS;CACxE;CAGA,OAAO,uBACL,UACuC;EACvC,QAAQ,UAAgC;GACtC,MAAM,gBAAgB;GACtB,MAAM,OAAO,WAAW;EAC1B;CACF;CAwCA,oBAA0B;EACxB,MAAM,kBAAkB;EACxB,IAAI,CAAC,KAAK,UAAU;GAClB,KAAK,YAAY,IAAI,YAAY;GACjC,KAAK,WAAW,KAAK;EACvB;EAEA,KAAK,iBACH,KAAK,YAAY,0BACjB,KAAK,sBACP;EACA,KAAK,iBAAiB,yBAAyB,KAAK,gBAAgB;EACpE,KAAK,iBACH,KAAK,YAAY,wBACjB,KAAK,oBACP;EAEA,KAAK,cAAc,KAAK,YAAY,qBAAqB,KAAK,QAAQ,CAAC;CACzE;CAMA,WAAqB,SAAqC;EACxD,MAAM,WAAW,OAAO;EAExB,IACE,KAAK,cACL,QAAQ,IAAI,UAAU,KACtB,QAAQ,IAAI,UAAU,MAAM,KAAK,WAEjC,kBAAkB,IAAI;EAGxB,IAAI,KAAK,YAAY,KAAK,aAAa,KAAK,WAC1C,KAAK,kBAAkB,QAAQ,KAAK,QAAQ;CAEhD;CAGA,SAAyB;EACvB,OAAO,IAAI;CACb;AACF;WA1IG,SAAS,EAAE,WAAW,MAAM,CAAC","names":[],"ignoreList":[],"sources":["../src/ui-router.ts"]}
|
package/dist/ui-view.d.ts
CHANGED
|
@@ -93,7 +93,16 @@ export declare class UiView extends LitElement {
|
|
|
93
93
|
static seekParentView(candidate: Element): ParentView | null;
|
|
94
94
|
private seekParentView;
|
|
95
95
|
private readonly onUiRouterContextEvent;
|
|
96
|
-
/**
|
|
96
|
+
/** Subscribers that took a router this view may still supersede. */
|
|
97
|
+
private readonly routerSubscribers;
|
|
98
|
+
/**
|
|
99
|
+
* Answers `context-request` for the router, so a `@lit/context` consumer
|
|
100
|
+
* under this view is served too.
|
|
101
|
+
*
|
|
102
|
+
* While the router this view holds is a sought one its provider may still
|
|
103
|
+
* replace, a `subscribe` request is kept and called once more with the router
|
|
104
|
+
* this view adopts.
|
|
105
|
+
*/
|
|
97
106
|
private readonly onContextRequest;
|
|
98
107
|
private seekRouter;
|
|
99
108
|
/**
|
|
@@ -109,6 +118,10 @@ export declare class UiView extends LitElement {
|
|
|
109
118
|
private registeredRouter?;
|
|
110
119
|
/** Set only for the synchronous span of our own re-seek. */
|
|
111
120
|
private seekingProvidedRouter;
|
|
121
|
+
/** Drops this view's subscription to its provider; set while the provider may still replace its router. */
|
|
122
|
+
private providerSubscription?;
|
|
123
|
+
/** The provider replaced the router this view sought: adopt it, and pass it on. */
|
|
124
|
+
private readonly onProvidedRouterReplaced;
|
|
112
125
|
/**
|
|
113
126
|
* Seeks the provider's router, past our own answer.
|
|
114
127
|
*
|
package/dist/ui-view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-view.d.ts","mappings":"AAAA,SAAS,YAAkB,eAAe;AAC1C,cAAc,gBAAgB,sBAAsB;AAEpD,SAME,kBASA,aACA,mBACK;AASP,SAAwB,mBAAuC;AAI/D,cACE,kBAGK;;
|
|
1
|
+
{"version":3,"file":"ui-view.d.ts","mappings":"AAAA,SAAS,YAAkB,eAAe;AAC1C,cAAc,gBAAgB,sBAAsB;AAEpD,SAME,kBASA,aACA,mBACK;AASP,SAAwB,mBAAuC;AAI/D,cACE,kBAGK;;AA8BP,iBAAiB,cAAc;CAC7B,SAAS,cAAc;CACvB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,OAAO,cAAM,eAAe,WAAW;;CAErC,AACA;;;;;CAMA,AACA,UAAW;CAEX,QACQ;;CAGR,QACQ;;;;;;;CAQR,QAAQ;;CAGR,QAAQ;;CAGR,QAAQ;;CAGR;CAIA,iBAAiB;CAEjB,QAAQ;CAER,QAAQ;CAER,QAAQ;CAoBR,QAAQ;CAoBR,QACQ;CAER,iBAAiB;;;;;;;CAgBjB,iBAAiB;;CAajB;CAoBA,wBAAwB;CAGxB,eAAe;;CAWf,OAAO,eAAe,WAAW,UAAU;CAM3C,QAAQ;CAIR,iBAAiB;;CASjB,iBAAiB;;;;;;;;;CAUjB,iBAAiB;CAWjB,QAAQ;;;;;;;;;CAoBR,QAAQ;;CAGR,QAAQ;;CAGR,QAAQ;;CAGR,QAAQ;;CAGR,iBAAiB;;;;;;;;CAYjB,QAAQ;;;;;;;;;;;;;;;;;;;;;;CAoCR,UAAU;CAqBV,QAAQ;;CAQR,QAAQ;;;;;;CAOR,QAAQ;;;;;;;;;;;;;CAqBR,UAAU;;;;;;;;;;;;;CAsBV,UAAU;;CAeV,YAAY;;;;;;;;CAWZ,QAAQ;CAcR,iBAAiB;CAEjB,QAAQ;;CA4CR;;;;;;;;;CAwBA,QAAQ;;CAeR,cAAc,GAAG,MAAM,WAAW,WAAW;;;;CAW7C,QAAQ;;CA2DR,IAAW;;CAKX,IAAW,eAAe;;CAK1B,IAAW,SAAS;;;;;;;;;;;CAcpB,UAAU,WAAW,SAAS;;;;;;;;;;;;CAmB9B,UAAU,aAAa,SAAS;;;;;CAWhC,UAAU,wBAAwB;AAuBpC;AAEA,iBAAiB,OAAO;;CAEtB,oBAAoB;AACtB","names":[],"ignoreList":[],"sources":["../src/ui-view.ts"]}
|
package/dist/ui-view.js
CHANGED
|
@@ -6,6 +6,7 @@ import { routedLitElementRenderer } from "./routed-element.js";
|
|
|
6
6
|
import { warnMissingRouter } from "./dev-warn.js";
|
|
7
7
|
import { UIRouterLitElement } from "./ui-router.js";
|
|
8
8
|
import { contextRequestEventName, isContextRequest, parentUiViewContext } from "./context.js";
|
|
9
|
+
import { RouterSubscribers, subscribeRouter } from "./router-subscription.js";
|
|
9
10
|
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
10
11
|
let viewIdCounter = 0;
|
|
11
12
|
const COMMENT_NODE = 8;
|
|
@@ -37,11 +38,16 @@ export class UiView extends LitElement {
|
|
|
37
38
|
if (this.seekingProvidedRouter) return;
|
|
38
39
|
UIRouterLitElement.onUiRouterContextEvent(this.uiRouter)(event);
|
|
39
40
|
};
|
|
41
|
+
this.routerSubscribers = new RouterSubscribers();
|
|
40
42
|
this.onContextRequest = (event) => {
|
|
41
43
|
if (this.seekingProvidedRouter) return;
|
|
42
|
-
|
|
44
|
+
this.routerSubscribers.answer(event, this.uiRouter, !!this.providerSubscription && this.uiRouter === this.soughtRouter);
|
|
43
45
|
};
|
|
44
46
|
this.seekingProvidedRouter = false;
|
|
47
|
+
this.onProvidedRouterReplaced = () => {
|
|
48
|
+
this.providerSubscription = void 0;
|
|
49
|
+
this.adoptProvidedRouter();
|
|
50
|
+
};
|
|
45
51
|
this.captured = false;
|
|
46
52
|
this.disconnectedHandlers = [];
|
|
47
53
|
}
|
|
@@ -98,16 +104,19 @@ export class UiView extends LitElement {
|
|
|
98
104
|
}
|
|
99
105
|
seekRouter() {
|
|
100
106
|
if (!this.uiRouter) {
|
|
101
|
-
this.soughtRouter =
|
|
107
|
+
this.soughtRouter = this.seekProvidedRouter();
|
|
102
108
|
this.uiRouter = this.soughtRouter;
|
|
103
109
|
}
|
|
104
110
|
this.addEventListener(UIRouterLitElement.uiRouterContextEventName, this.onUiRouterContextEvent);
|
|
105
111
|
this.addEventListener(contextRequestEventName, this.onContextRequest);
|
|
106
112
|
}
|
|
107
113
|
seekProvidedRouter() {
|
|
114
|
+
this.providerSubscription?.();
|
|
108
115
|
this.seekingProvidedRouter = true;
|
|
109
116
|
try {
|
|
110
|
-
|
|
117
|
+
const { router, unsubscribe } = subscribeRouter(this, this.onProvidedRouterReplaced);
|
|
118
|
+
this.providerSubscription = unsubscribe;
|
|
119
|
+
return router;
|
|
111
120
|
} finally {
|
|
112
121
|
this.seekingProvidedRouter = false;
|
|
113
122
|
}
|
|
@@ -121,6 +130,7 @@ export class UiView extends LitElement {
|
|
|
121
130
|
this.deregisterAll();
|
|
122
131
|
this.uiRouter = router;
|
|
123
132
|
this.setupUiView();
|
|
133
|
+
this.routerSubscribers.deliver(router);
|
|
124
134
|
}
|
|
125
135
|
deregisterAll() {
|
|
126
136
|
while (this.disconnectedHandlers.length) this.disconnectedHandlers.shift()?.();
|
|
@@ -189,6 +199,8 @@ export class UiView extends LitElement {
|
|
|
189
199
|
super.disconnectedCallback();
|
|
190
200
|
this.removeEventListener(this.constructor.uiViewContextEventName, this.onUiViewContextEvent);
|
|
191
201
|
this.removeEventListener(contextRequestEventName, this.onParentViewContextRequest);
|
|
202
|
+
this.providerSubscription?.();
|
|
203
|
+
this.providerSubscription = void 0;
|
|
192
204
|
this.deregisterAll();
|
|
193
205
|
}
|
|
194
206
|
_invokeUiCanExitHook(trans) {
|
package/dist/ui-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-view.js","mappings":"AAAA,SAAS,YAAY,MAAM,eAAe;AAE1C,SAAS,UAAU,aAAa;AAChC,SAEE,gBACA,YAEA,YAGA,OAEA,YACA,UACA,SAEA,cAGK;AASP,SAAS,eAA4B,0BAA0B;AAC/D,SAAS,gCAAgC;AACzC,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAMnC,SACE,yBACA,kBACA,2BACK;;
|
|
1
|
+
{"version":3,"file":"ui-view.js","mappings":"AAAA,SAAS,YAAY,MAAM,eAAe;AAE1C,SAAS,UAAU,aAAa;AAChC,SAEE,gBACA,YAEA,YAGA,OAEA,YACA,UACA,SAEA,cAGK;AASP,SAAS,eAA4B,0BAA0B;AAC/D,SAAS,gCAAgC;AACzC,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAMnC,SACE,yBACA,kBACA,2BACK;AACP,SAAS,mBAAmB,uBAAuB;;AAGnD,IAAI,gBAAgB;AAMpB,MAAM,eAAe;AAMrB,MAAM,kBAAkB,SAAoC;CAC1D,IAAI,CAAC,QAAQ,KAAK,aAAa,cAC7B,OAAO;CAET,MAAM,EAAE,SAAS;CACjB,OAAO,SAAS,MAAM,KAAK,SAAS,UAAU;AAChD;AAWA,MAAM,gCAAgC,CAAC;AAyCvC,OAAO,MAAM,eAAe,WAA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,SAA0C;EACxC,IAAI,KAAK,eAEP,OAAO,KAAK,WAAW,UAAU,IAAI;EAGvC,MAAM,EAAE,UAAU,QAAQ,cAAc;EACxC,MAAM,WAAW,KAAK,eAAe,SAAS;EAc9C,OAAO,UAAW;GAFmB;GAAQ,UAXzB,KAAK,eACtB,UAAU,CAAC,CACX,QAAQ,UAAU,SAAS,KAAK,CAAC,CAAC,CAClC,KAAK,UAAU,KAAK,eAAe,cAAc,KAAK,CAAC,CAAC,CACxD,QAAQ,MAAM,EAAE,QAEQ,CAAC,CACzB,KAAK,EAAE,YAAY,CAAC,OAAiB,SAAS,IAAI,KAAK,CAAY,CAAC,CAAC,CACrE,OAAO,YAAY,CAAC,CAG6B;GAAG,YAFpC,SAAS,IAAI,UAEgC;EAE1C,CAAC;CACzB;AACF;WA3mBG,SAAS;WAOT,SAAS,EAAE,WAAW,MAAM,CAAC;WAG7B,MAAM;WAIN,MAAM;WAoEN,MAAM","names":[],"ignoreList":[],"sources":["../src/ui-view.ts"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// The subscribe half of the router context: a provider's provisional router, and the one upgrade it may make.
|
|
2
|
+
import { isRouterContextRequest, requestRouter } from './context.js';
|
|
3
|
+
import type { UIRouterLit } from './core.js';
|
|
4
|
+
import { uiRouterContextEventName } from './events.js';
|
|
5
|
+
import type { UiRouterContextEvent } from './events.js';
|
|
6
|
+
|
|
7
|
+
/** The unsubscribe a provider hands out when its router is final: it will not call again. */
|
|
8
|
+
export const noUnsubscribe = (): void => {};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The `subscribe: true` requests a provider answered while its router was
|
|
12
|
+
* provisional, each owed the router that replaces it.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export class RouterSubscribers {
|
|
17
|
+
private readonly pending = new Set<(router: UIRouterLit) => void>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Answers a router `context-request`. A subscriber is kept, with an
|
|
21
|
+
* unsubscribe that drops it, only while `provisional`; otherwise it gets
|
|
22
|
+
* {@link noUnsubscribe}.
|
|
23
|
+
*/
|
|
24
|
+
answer(
|
|
25
|
+
event: Event,
|
|
26
|
+
router: UIRouterLit | undefined,
|
|
27
|
+
provisional: boolean,
|
|
28
|
+
): void {
|
|
29
|
+
if (!router || !isRouterContextRequest(event)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// stopped first: a throwing consumer must not leak the request outward
|
|
33
|
+
event.stopImmediatePropagation();
|
|
34
|
+
const { callback, subscribe } = event;
|
|
35
|
+
if (!subscribe) {
|
|
36
|
+
return callback(router);
|
|
37
|
+
}
|
|
38
|
+
if (!provisional) {
|
|
39
|
+
return callback(router, noUnsubscribe);
|
|
40
|
+
}
|
|
41
|
+
const deliver = (next: UIRouterLit) => callback(next, noUnsubscribe);
|
|
42
|
+
this.pending.add(deliver);
|
|
43
|
+
callback(router, () => this.pending.delete(deliver));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Hands every kept subscriber `router`, once, and forgets them.
|
|
48
|
+
*
|
|
49
|
+
* A subscriber that throws does not keep the router from the others; its
|
|
50
|
+
* error goes to {@link reportFailures} once all have it.
|
|
51
|
+
*/
|
|
52
|
+
deliver(router: UIRouterLit): void {
|
|
53
|
+
const failures: unknown[] = [];
|
|
54
|
+
for (const deliver of [...this.pending]) {
|
|
55
|
+
// An earlier subscriber may have disconnected this one, unsubscribing it.
|
|
56
|
+
if (!this.pending.delete(deliver)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
deliver(router);
|
|
61
|
+
} catch (thrown) {
|
|
62
|
+
failures.push(thrown);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
reportFailures(failures);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reports each failure through `reportError`, as the platform reports a
|
|
71
|
+
* throwing event listener. Without it (Node, DOM emulators) throws instead:
|
|
72
|
+
* the one error, or an `AggregateError` of several.
|
|
73
|
+
*/
|
|
74
|
+
const reportFailures = (failures: unknown[]): void => {
|
|
75
|
+
if (!failures.length) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (typeof globalThis.reportError === 'function') {
|
|
79
|
+
failures.forEach((failure) => globalThis.reportError(failure));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
throw failures.length === 1
|
|
83
|
+
? failures[0]
|
|
84
|
+
: new AggregateError(failures, 'router upgrade subscribers threw');
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* What {@link subscribeRouter} found: the router, and the unsubscribe to call
|
|
89
|
+
* on disconnect, absent when the provider's router is final.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
export interface RouterSubscription {
|
|
94
|
+
router: UIRouterLit | undefined;
|
|
95
|
+
unsubscribe: (() => void) | undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Seeks the router from `target` and subscribes to its replacement, which
|
|
100
|
+
* reaches `onReplaced`.
|
|
101
|
+
*
|
|
102
|
+
* Asks over `context-request` with `subscribe: true`, falling back to the house
|
|
103
|
+
* `ui-router-context` event, which cannot subscribe, when nobody answered.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export const subscribeRouter = (
|
|
108
|
+
target: Element,
|
|
109
|
+
onReplaced: (router: UIRouterLit) => void,
|
|
110
|
+
): RouterSubscription => {
|
|
111
|
+
let seeking = true;
|
|
112
|
+
let unsubscribe: (() => void) | undefined;
|
|
113
|
+
const router = requestRouter(target, {
|
|
114
|
+
subscribe: true,
|
|
115
|
+
callback: (value, offered) => {
|
|
116
|
+
unsubscribe = offered === noUnsubscribe ? undefined : offered;
|
|
117
|
+
if (!seeking) {
|
|
118
|
+
onReplaced(value);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
seeking = false;
|
|
123
|
+
if (router) {
|
|
124
|
+
return { router, unsubscribe };
|
|
125
|
+
}
|
|
126
|
+
const event: UiRouterContextEvent = new CustomEvent(
|
|
127
|
+
uiRouterContextEventName,
|
|
128
|
+
{ bubbles: true, composed: true, detail: {} },
|
|
129
|
+
);
|
|
130
|
+
target.dispatchEvent(event);
|
|
131
|
+
return { router: event.detail.uiRouter, unsubscribe: undefined };
|
|
132
|
+
};
|
|
@@ -2,9 +2,9 @@ import { TargetState, Transition, UIRouter } from '@uirouter/core';
|
|
|
2
2
|
import { nothing, ReactiveController, ReactiveControllerHost } from 'lit';
|
|
3
3
|
|
|
4
4
|
import { warnMissingRouter } from './dev-warn.js';
|
|
5
|
+
import { subscribeRouter } from './router-subscription.js';
|
|
5
6
|
import type { SrefTargetParams } from './sref-active.js';
|
|
6
7
|
import { resolveAriaCurrent, SrefTargets } from './sref-status.js';
|
|
7
|
-
import { UIRouterLitElement } from './ui-router.js';
|
|
8
8
|
import {
|
|
9
9
|
UI_SREF_TARGET_EVENT,
|
|
10
10
|
UI_SREF_TARGET_REMOVED_EVENT,
|
|
@@ -32,8 +32,9 @@ export interface SrefStatusControllerOptions extends SrefTargetParams {
|
|
|
32
32
|
* The {@link UIRouter} instance to observe.
|
|
33
33
|
*
|
|
34
34
|
* When omitted, the controller discovers the router from an ancestor
|
|
35
|
-
* <code><ui-router></code> (or <code><ui-view></code>)
|
|
36
|
-
*
|
|
35
|
+
* <code><ui-router></code> (or <code><ui-view></code>) when the
|
|
36
|
+
* host connects, and follows the placeholder router a
|
|
37
|
+
* <code><ui-router></code> mints for itself to the one that replaces it.
|
|
37
38
|
*
|
|
38
39
|
* Passing it explicitly also moves the first status computation into the
|
|
39
40
|
* constructor, so the status is there for the very first render and needs
|
|
@@ -147,6 +148,9 @@ export class SrefStatusController implements ReactiveController {
|
|
|
147
148
|
|
|
148
149
|
private readonly deregisterFns: DeregisterFn[] = [];
|
|
149
150
|
|
|
151
|
+
/** the hooks on the router itself, which a replacement router moves */
|
|
152
|
+
private readonly routerDeregisterFns: DeregisterFn[] = [];
|
|
153
|
+
|
|
150
154
|
private _status: SrefStatus | undefined;
|
|
151
155
|
|
|
152
156
|
/** whether a status has ever been computed, so the first one always renders */
|
|
@@ -245,8 +249,16 @@ export class SrefStatusController implements ReactiveController {
|
|
|
245
249
|
/** @internal */
|
|
246
250
|
hostConnected(): void {
|
|
247
251
|
const { host } = this;
|
|
248
|
-
this.
|
|
249
|
-
|
|
252
|
+
if (!this.options.router) {
|
|
253
|
+
const { router, unsubscribe } = subscribeRouter(
|
|
254
|
+
host,
|
|
255
|
+
this.onRouterReplaced,
|
|
256
|
+
);
|
|
257
|
+
this.targets.router = router;
|
|
258
|
+
if (unsubscribe) {
|
|
259
|
+
this.deregisterFns.push(unsubscribe);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
250
262
|
this.targets.relative = UiView.seekParentView(host)?.viewContext?.name;
|
|
251
263
|
this.targets.setExplicit();
|
|
252
264
|
|
|
@@ -275,12 +287,7 @@ export class SrefStatusController implements ReactiveController {
|
|
|
275
287
|
|
|
276
288
|
const router = this.targets.router;
|
|
277
289
|
if (router) {
|
|
278
|
-
this.
|
|
279
|
-
router.transitionService.onStart({}, this.onTransitionStart, {
|
|
280
|
-
priority: -Infinity,
|
|
281
|
-
}) as DeregisterFn,
|
|
282
|
-
router.stateRegistry.onStatesChanged(this.onStatesChanged),
|
|
283
|
-
);
|
|
290
|
+
this.watch(router);
|
|
284
291
|
} else {
|
|
285
292
|
warnMissingRouter(
|
|
286
293
|
host,
|
|
@@ -294,7 +301,7 @@ export class SrefStatusController implements ReactiveController {
|
|
|
294
301
|
|
|
295
302
|
/** @internal */
|
|
296
303
|
hostDisconnected(): void {
|
|
297
|
-
this.
|
|
304
|
+
this.unwatch();
|
|
298
305
|
while (this.deregisterFns.length) {
|
|
299
306
|
this.deregisterFns.shift()?.();
|
|
300
307
|
}
|
|
@@ -304,6 +311,32 @@ export class SrefStatusController implements ReactiveController {
|
|
|
304
311
|
}
|
|
305
312
|
}
|
|
306
313
|
|
|
314
|
+
private watch(router: UIRouter): void {
|
|
315
|
+
this.routerDeregisterFns.push(
|
|
316
|
+
router.transitionService.onStart({}, this.onTransitionStart, {
|
|
317
|
+
priority: -Infinity,
|
|
318
|
+
}) as DeregisterFn,
|
|
319
|
+
router.stateRegistry.onStatesChanged(this.onStatesChanged),
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private unwatch(): void {
|
|
324
|
+
this._connection++;
|
|
325
|
+
while (this.routerDeregisterFns.length) {
|
|
326
|
+
this.routerDeregisterFns.shift()?.();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** What a disconnect and reconnect would do, for the router that replaced the one found. */
|
|
331
|
+
private readonly onRouterReplaced = (router: UIRouter): void => {
|
|
332
|
+
this.unwatch();
|
|
333
|
+
this.targets.router = router;
|
|
334
|
+
this.targets.relative = UiView.seekParentView(this.host)?.viewContext?.name;
|
|
335
|
+
this.targets.rebuild();
|
|
336
|
+
this.watch(router);
|
|
337
|
+
this.refresh();
|
|
338
|
+
};
|
|
339
|
+
|
|
307
340
|
/**
|
|
308
341
|
* Recomputes the status and re-renders the host, but only if a flag or a
|
|
309
342
|
* watched target moved.
|