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
|
@@ -181,12 +181,20 @@
|
|
|
181
181
|
"privacy": "private",
|
|
182
182
|
"readonly": true
|
|
183
183
|
},
|
|
184
|
+
{
|
|
185
|
+
"kind": "field",
|
|
186
|
+
"name": "routerSubscribers",
|
|
187
|
+
"privacy": "private",
|
|
188
|
+
"readonly": true,
|
|
189
|
+
"default": "new RouterSubscribers()",
|
|
190
|
+
"description": "Subscribers that took a router this view may still supersede."
|
|
191
|
+
},
|
|
184
192
|
{
|
|
185
193
|
"kind": "field",
|
|
186
194
|
"name": "onContextRequest",
|
|
187
195
|
"privacy": "private",
|
|
188
196
|
"readonly": true,
|
|
189
|
-
"description": "Answers `context-request` for the router, so a `@lit/context` consumer
|
|
197
|
+
"description": "Answers `context-request` for the router, so a `@lit/context` consumer\nunder this view is served too.\n\nWhile the router this view holds is a sought one its provider may still\nreplace, a `subscribe` request is kept and called once more with the router\nthis view adopts."
|
|
190
198
|
},
|
|
191
199
|
{
|
|
192
200
|
"kind": "method",
|
|
@@ -221,6 +229,22 @@
|
|
|
221
229
|
"default": "false",
|
|
222
230
|
"description": "Set only for the synchronous span of our own re-seek."
|
|
223
231
|
},
|
|
232
|
+
{
|
|
233
|
+
"kind": "field",
|
|
234
|
+
"name": "providerSubscription",
|
|
235
|
+
"type": {
|
|
236
|
+
"text": "() => void | undefined"
|
|
237
|
+
},
|
|
238
|
+
"privacy": "private",
|
|
239
|
+
"description": "Drops this view's subscription to its provider; set while the provider may still replace its router."
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"kind": "field",
|
|
243
|
+
"name": "onProvidedRouterReplaced",
|
|
244
|
+
"privacy": "private",
|
|
245
|
+
"readonly": true,
|
|
246
|
+
"description": "The provider replaced the router this view sought: adopt it, and pass it on."
|
|
247
|
+
},
|
|
224
248
|
{
|
|
225
249
|
"kind": "method",
|
|
226
250
|
"name": "seekProvidedRouter",
|
|
@@ -469,11 +493,20 @@
|
|
|
469
493
|
"privacy": "private",
|
|
470
494
|
"readonly": true
|
|
471
495
|
},
|
|
496
|
+
{
|
|
497
|
+
"kind": "field",
|
|
498
|
+
"name": "routerSubscribers",
|
|
499
|
+
"privacy": "private",
|
|
500
|
+
"readonly": true,
|
|
501
|
+
"default": "new RouterSubscribers()",
|
|
502
|
+
"description": "Subscribers that took the placeholder, owed the app's router."
|
|
503
|
+
},
|
|
472
504
|
{
|
|
473
505
|
"kind": "field",
|
|
474
506
|
"name": "onContextRequest",
|
|
475
507
|
"privacy": "private",
|
|
476
|
-
"readonly": true
|
|
508
|
+
"readonly": true,
|
|
509
|
+
"description": "Answers a `context-request` for the router context.\n\nWhile the placeholder minted on connect stands, a `subscribe` request is\nkept and called once more with the router that replaces it, and gets an\nunsubscribe that drops it. Any other answer is final: one call and a no-op\nunsubscribe, since a later swap is unsupported and only warns."
|
|
477
510
|
},
|
|
478
511
|
{
|
|
479
512
|
"kind": "field",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isRouterContextRequest, requestRouter } from "./context.js";
|
|
2
|
+
import { uiRouterContextEventName } from "./events.js";
|
|
3
|
+
export const noUnsubscribe = () => {};
|
|
4
|
+
export class RouterSubscribers {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.pending = new Set();
|
|
7
|
+
}
|
|
8
|
+
answer(event, router, provisional) {
|
|
9
|
+
if (!router || !isRouterContextRequest(event)) return;
|
|
10
|
+
event.stopImmediatePropagation();
|
|
11
|
+
const { callback, subscribe } = event;
|
|
12
|
+
if (!subscribe) return callback(router);
|
|
13
|
+
if (!provisional) return callback(router, noUnsubscribe);
|
|
14
|
+
const deliver = (next) => callback(next, noUnsubscribe);
|
|
15
|
+
this.pending.add(deliver);
|
|
16
|
+
callback(router, () => this.pending.delete(deliver));
|
|
17
|
+
}
|
|
18
|
+
deliver(router) {
|
|
19
|
+
const failures = [];
|
|
20
|
+
for (const deliver of [...this.pending]) {
|
|
21
|
+
if (!this.pending.delete(deliver)) continue;
|
|
22
|
+
try {
|
|
23
|
+
deliver(router);
|
|
24
|
+
} catch (thrown) {
|
|
25
|
+
failures.push(thrown);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
reportFailures(failures);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const reportFailures = (failures) => {
|
|
32
|
+
if (!failures.length) return;
|
|
33
|
+
if (typeof globalThis.reportError === "function") {
|
|
34
|
+
failures.forEach((failure) => globalThis.reportError(failure));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw failures.length === 1 ? failures[0] : new AggregateError(failures, "router upgrade subscribers threw");
|
|
38
|
+
};
|
|
39
|
+
export const subscribeRouter = (target, onReplaced) => {
|
|
40
|
+
let seeking = true;
|
|
41
|
+
let unsubscribe;
|
|
42
|
+
const router = requestRouter(target, {
|
|
43
|
+
subscribe: true,
|
|
44
|
+
callback: (value, offered) => {
|
|
45
|
+
unsubscribe = offered === noUnsubscribe ? void 0 : offered;
|
|
46
|
+
if (!seeking) onReplaced(value);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
seeking = false;
|
|
50
|
+
if (router) return {
|
|
51
|
+
router,
|
|
52
|
+
unsubscribe
|
|
53
|
+
};
|
|
54
|
+
const event = new CustomEvent(uiRouterContextEventName, {
|
|
55
|
+
bubbles: true,
|
|
56
|
+
composed: true,
|
|
57
|
+
detail: {}
|
|
58
|
+
});
|
|
59
|
+
target.dispatchEvent(event);
|
|
60
|
+
return {
|
|
61
|
+
router: event.detail.uiRouter,
|
|
62
|
+
unsubscribe: void 0
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=router-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-subscription.js","mappings":"AACA,SAAS,wBAAwB,qBAAqB;AAEtD,SAAS,gCAAgC;AAIzC,OAAO,MAAM,sBAA4B,CAAC;AAQ1C,OAAO,MAAM,kBAAkB;;iBACF,IAAI,IAAmC;;CAOlE,OACE,OACA,QACA,aACM;EACN,IAAI,CAAC,UAAU,CAAC,uBAAuB,KAAK,GAC1C;EAGF,MAAM,yBAAyB;EAC/B,MAAM,EAAE,UAAU,cAAc;EAChC,IAAI,CAAC,WACH,OAAO,SAAS,MAAM;EAExB,IAAI,CAAC,aACH,OAAO,SAAS,QAAQ,aAAa;EAEvC,MAAM,WAAW,SAAsB,SAAS,MAAM,aAAa;EACnE,KAAK,QAAQ,IAAI,OAAO;EACxB,SAAS,cAAc,KAAK,QAAQ,OAAO,OAAO,CAAC;CACrD;CAQA,QAAQ,QAA2B;EACjC,MAAM,WAAsB,CAAC;EAC7B,KAAK,MAAM,WAAW,CAAC,GAAG,KAAK,OAAO,GAAG;GAEvC,IAAI,CAAC,KAAK,QAAQ,OAAO,OAAO,GAC9B;GAEF,IAAI;IACF,QAAQ,MAAM;GAChB,SAAS,QAAQ;IACf,SAAS,KAAK,MAAM;GACtB;EACF;EACA,eAAe,QAAQ;CACzB;AACF;AAOA,MAAM,kBAAkB,aAA8B;CACpD,IAAI,CAAC,SAAS,QACZ;CAEF,IAAI,OAAO,WAAW,gBAAgB,YAAY;EAChD,SAAS,SAAS,YAAY,WAAW,YAAY,OAAO,CAAC;EAC7D;CACF;CACA,MAAM,SAAS,WAAW,IACtB,SAAS,KACT,IAAI,eAAe,UAAU,kCAAkC;AACrE;AAsBA,OAAO,MAAM,mBACX,QACA,eACuB;CACvB,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,SAAS,cAAc,QAAQ;EACnC,WAAW;EACX,WAAW,OAAO,YAAY;GAC5B,cAAc,YAAY,gBAAgB,SAAY;GACtD,IAAI,CAAC,SACH,WAAW,KAAK;EAEpB;CACF,CAAC;CACD,UAAU;CACV,IAAI,QACF,OAAO;EAAE;EAAQ;CAAY;CAE/B,MAAM,QAA8B,IAAI,YACtC,0BACA;EAAE,SAAS;EAAM,UAAU;EAAM,QAAQ,CAAC;CAAE,CAC9C;CACA,OAAO,cAAc,KAAK;CAC1B,OAAO;EAAE,QAAQ,MAAM,OAAO;EAAU,aAAa;CAAU;AACjE","names":[],"ignoreList":[],"sources":["../../src/router-subscription.ts"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nothing } from "lit";
|
|
2
2
|
import { warnMissingRouter } from "./dev-warn.js";
|
|
3
|
+
import { subscribeRouter } from "./router-subscription.js";
|
|
3
4
|
import { resolveAriaCurrent, SrefTargets } from "./sref-status.js";
|
|
4
|
-
import { UIRouterLitElement } from "./ui-router.js";
|
|
5
5
|
import { UI_SREF_TARGET_EVENT, UI_SREF_TARGET_REMOVED_EVENT } from "./ui-sref.js";
|
|
6
6
|
import { UiView } from "./ui-view.js";
|
|
7
7
|
const sameShape = (a, b) => a === b || !!a && !!b && a.active === b.active && a.exact === b.exact && a.entering === b.entering && a.exiting === b.exiting && a.targetStates.length === b.targetStates.length && a.targetStates.every((target, i) => target === b.targetStates[i]);
|
|
@@ -9,8 +9,17 @@ export class SrefStatusController {
|
|
|
9
9
|
constructor(host, options = {}) {
|
|
10
10
|
this.targets = new SrefTargets();
|
|
11
11
|
this.deregisterFns = [];
|
|
12
|
+
this.routerDeregisterFns = [];
|
|
12
13
|
this.computed = false;
|
|
13
14
|
this._connection = 0;
|
|
15
|
+
this.onRouterReplaced = (router) => {
|
|
16
|
+
this.unwatch();
|
|
17
|
+
this.targets.router = router;
|
|
18
|
+
this.targets.relative = UiView.seekParentView(this.host)?.viewContext?.name;
|
|
19
|
+
this.targets.rebuild();
|
|
20
|
+
this.watch(router);
|
|
21
|
+
this.refresh();
|
|
22
|
+
};
|
|
14
23
|
this.onUiSrefTargetEvent = (event) => {
|
|
15
24
|
this.targets.onLink(event);
|
|
16
25
|
this.refresh();
|
|
@@ -81,7 +90,11 @@ export class SrefStatusController {
|
|
|
81
90
|
}
|
|
82
91
|
hostConnected() {
|
|
83
92
|
const { host } = this;
|
|
84
|
-
|
|
93
|
+
if (!this.options.router) {
|
|
94
|
+
const { router, unsubscribe } = subscribeRouter(host, this.onRouterReplaced);
|
|
95
|
+
this.targets.router = router;
|
|
96
|
+
if (unsubscribe) this.deregisterFns.push(unsubscribe);
|
|
97
|
+
}
|
|
85
98
|
this.targets.relative = UiView.seekParentView(host)?.viewContext?.name;
|
|
86
99
|
this.targets.setExplicit();
|
|
87
100
|
const scope = host.renderRoot ?? host;
|
|
@@ -92,15 +105,22 @@ export class SrefStatusController {
|
|
|
92
105
|
scope.removeEventListener(UI_SREF_TARGET_REMOVED_EVENT, this.onUiSrefTargetRemovedEvent);
|
|
93
106
|
});
|
|
94
107
|
const router = this.targets.router;
|
|
95
|
-
if (router) this.
|
|
108
|
+
if (router) this.watch(router);
|
|
96
109
|
else warnMissingRouter(host, `new SrefStatusController() on <${host.localName}>`, "will never be marked active");
|
|
97
110
|
this.refresh();
|
|
98
111
|
}
|
|
99
112
|
hostDisconnected() {
|
|
100
|
-
this.
|
|
113
|
+
this.unwatch();
|
|
101
114
|
while (this.deregisterFns.length) this.deregisterFns.shift()?.();
|
|
102
115
|
if (!this.options.router) this.targets.router = void 0;
|
|
103
116
|
}
|
|
117
|
+
watch(router) {
|
|
118
|
+
this.routerDeregisterFns.push(router.transitionService.onStart({}, this.onTransitionStart, { priority: -Infinity }), router.stateRegistry.onStatesChanged(this.onStatesChanged));
|
|
119
|
+
}
|
|
120
|
+
unwatch() {
|
|
121
|
+
this._connection++;
|
|
122
|
+
while (this.routerDeregisterFns.length) this.routerDeregisterFns.shift()?.();
|
|
123
|
+
}
|
|
104
124
|
refresh(event) {
|
|
105
125
|
if (this.compute(event)) this.host.requestUpdate();
|
|
106
126
|
}
|
|
@@ -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,SAAS,uBAAuB;AAEhC,SAAS,oBAAoB,mBAAmB;AAChD,SACE,sBACA,oCAEK;AAOP,SAAS,cAAc;AAiCvB,MAAM,aACJ,GACA,MAEA,MAAM,KACL,CAAC,CAAC,KACD,CAAC,CAAC,KACF,EAAE,WAAW,EAAE,UACf,EAAE,UAAU,EAAE,SACd,EAAE,aAAa,EAAE,YACjB,EAAE,YAAY,EAAE,WAChB,EAAE,aAAa,WAA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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"]}
|
|
@@ -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"]}
|
|
@@ -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>`;
|
|
@@ -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"]}
|
|
@@ -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) {
|
|
@@ -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,WAAW;;;cAG9B;mBAcuC;uBAWT,CAAC;wBAGb;gBAOC;+BAiDe,UAA8B;GAErE,IAAI,MAAM,aAAa,CAAC,CAAC,OAAO,MAC9B;GAGF,MAAM,gBAAgB;GACtB,MAAM,OAAO,aAAa;EAC5B;qCAQ+C,UAAiB;GAE9D,IACE,MAAM,aAAa,CAAC,CAAC,OAAO,QAC5B,CAAC,iBAAiB,OAAO,mBAAmB,GA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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"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { UIRouterLit } from "./core.js";
|
|
2
|
+
/** The unsubscribe a provider hands out when its router is final: it will not call again. */
|
|
3
|
+
export declare const noUnsubscribe: () => void;
|
|
4
|
+
/**
|
|
5
|
+
* The `subscribe: true` requests a provider answered while its router was
|
|
6
|
+
* provisional, each owed the router that replaces it.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class RouterSubscribers {
|
|
11
|
+
private readonly pending;
|
|
12
|
+
/**
|
|
13
|
+
* Answers a router `context-request`. A subscriber is kept, with an
|
|
14
|
+
* unsubscribe that drops it, only while `provisional`; otherwise it gets
|
|
15
|
+
* {@link noUnsubscribe}.
|
|
16
|
+
*/
|
|
17
|
+
answer(event: Event, router: UIRouterLit | undefined, provisional: boolean): void;
|
|
18
|
+
/**
|
|
19
|
+
* Hands every kept subscriber `router`, once, and forgets them.
|
|
20
|
+
*
|
|
21
|
+
* A subscriber that throws does not keep the router from the others; its
|
|
22
|
+
* error goes to {@link reportFailures} once all have it.
|
|
23
|
+
*/
|
|
24
|
+
deliver(router: UIRouterLit): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What {@link subscribeRouter} found: the router, and the unsubscribe to call
|
|
28
|
+
* on disconnect, absent when the provider's router is final.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export interface RouterSubscription {
|
|
33
|
+
router: UIRouterLit | undefined;
|
|
34
|
+
unsubscribe: (() => void) | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Seeks the router from `target` and subscribes to its replacement, which
|
|
38
|
+
* reaches `onReplaced`.
|
|
39
|
+
*
|
|
40
|
+
* Asks over `context-request` with `subscribe: true`, falling back to the house
|
|
41
|
+
* `ui-router-context` event, which cannot subscribe, when nobody answered.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare const subscribeRouter: (target: Element, onReplaced: (router: UIRouterLit) => void) => RouterSubscription;
|
|
46
|
+
//# sourceMappingURL=router-subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-subscription.d.ts","mappings":"AAEA,cAAc,mBAAmB;;AAKjC,OAAO,cAAM;;;;;;;AAQb,OAAO,cAAM,kBAAkB;CAC7B,iBAAiB;;;;;;CAOjB,OACE,OAAO,OACP,QAAQ,yBACR;;;;;;;CAyBF,QAAQ,QAAQ;AAelB;;;;;;;AA0BA,iBAAiB,mBAAmB;CAClC,QAAQ;CACR;AACF;;;;;;;;;;AAWA,OAAO,cAAM,kBACX,QAAQ,SACR,aAAa,QAAQ,yBACpB","names":[],"ignoreList":[],"sources":["../src/router-subscription.ts"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isRouterContextRequest, requestRouter } from "./context.js";
|
|
2
|
+
import { uiRouterContextEventName } from "./events.js";
|
|
3
|
+
export const noUnsubscribe = () => {};
|
|
4
|
+
export class RouterSubscribers {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.pending = new Set();
|
|
7
|
+
}
|
|
8
|
+
answer(event, router, provisional) {
|
|
9
|
+
if (!router || !isRouterContextRequest(event)) return;
|
|
10
|
+
event.stopImmediatePropagation();
|
|
11
|
+
const { callback, subscribe } = event;
|
|
12
|
+
if (!subscribe) return callback(router);
|
|
13
|
+
if (!provisional) return callback(router, noUnsubscribe);
|
|
14
|
+
const deliver = (next) => callback(next, noUnsubscribe);
|
|
15
|
+
this.pending.add(deliver);
|
|
16
|
+
callback(router, () => this.pending.delete(deliver));
|
|
17
|
+
}
|
|
18
|
+
deliver(router) {
|
|
19
|
+
const failures = [];
|
|
20
|
+
for (const deliver of [...this.pending]) {
|
|
21
|
+
if (!this.pending.delete(deliver)) continue;
|
|
22
|
+
try {
|
|
23
|
+
deliver(router);
|
|
24
|
+
} catch (thrown) {
|
|
25
|
+
failures.push(thrown);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
reportFailures(failures);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const reportFailures = (failures) => {
|
|
32
|
+
if (!failures.length) return;
|
|
33
|
+
if (typeof globalThis.reportError === "function") {
|
|
34
|
+
failures.forEach((failure) => globalThis.reportError(failure));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw failures.length === 1 ? failures[0] : new AggregateError(failures, "router upgrade subscribers threw");
|
|
38
|
+
};
|
|
39
|
+
export const subscribeRouter = (target, onReplaced) => {
|
|
40
|
+
let seeking = true;
|
|
41
|
+
let unsubscribe;
|
|
42
|
+
const router = requestRouter(target, {
|
|
43
|
+
subscribe: true,
|
|
44
|
+
callback: (value, offered) => {
|
|
45
|
+
unsubscribe = offered === noUnsubscribe ? void 0 : offered;
|
|
46
|
+
if (!seeking) onReplaced(value);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
seeking = false;
|
|
50
|
+
if (router) return {
|
|
51
|
+
router,
|
|
52
|
+
unsubscribe
|
|
53
|
+
};
|
|
54
|
+
const event = new CustomEvent(uiRouterContextEventName, {
|
|
55
|
+
bubbles: true,
|
|
56
|
+
composed: true,
|
|
57
|
+
detail: {}
|
|
58
|
+
});
|
|
59
|
+
target.dispatchEvent(event);
|
|
60
|
+
return {
|
|
61
|
+
router: event.detail.uiRouter,
|
|
62
|
+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,WAAW,OAAO,YAAY;GAC5B,cAAc,YAAY,gBAAgB,SAAY;GACtD,IAAI,CAAC,SACH,WAAW,KAAK;EAEpB;CACF,CAAC;CACD,UAAU;CACV,IAAI,QACF,OAAO;EAAE;EAAQ;CAAY;CAE/B,MAAM,QAA8B,IAAI,YACtC,0BACA;EAAE,SAAS;EAAM,UAAU;EAAM,QAAQ,CAAC;CAAE,CAC9C;CACA,OAAO,cAAc,KAAK;CAC1B,OAAO;EAAE,QAAQ,MAAM,OAAO;EAAU,aAAa;CAAU;AACjE","names":[],"ignoreList":[],"sources":["../src/router-subscription.ts"]}
|
|
@@ -13,8 +13,9 @@ export interface SrefStatusControllerOptions extends SrefTargetParams {
|
|
|
13
13
|
* The {@link UIRouter} instance to observe.
|
|
14
14
|
*
|
|
15
15
|
* When omitted, the controller discovers the router from an ancestor
|
|
16
|
-
* <code><ui-router></code> (or <code><ui-view></code>)
|
|
17
|
-
*
|
|
16
|
+
* <code><ui-router></code> (or <code><ui-view></code>) when the
|
|
17
|
+
* host connects, and follows the placeholder router a
|
|
18
|
+
* <code><ui-router></code> mints for itself to the one that replaces it.
|
|
18
19
|
*
|
|
19
20
|
* Passing it explicitly also moves the first status computation into the
|
|
20
21
|
* constructor, so the status is there for the very first render and needs
|
|
@@ -104,6 +105,8 @@ export declare class SrefStatusController implements ReactiveController {
|
|
|
104
105
|
private options;
|
|
105
106
|
private readonly targets;
|
|
106
107
|
private readonly deregisterFns;
|
|
108
|
+
/** the hooks on the router itself, which a replacement router moves */
|
|
109
|
+
private readonly routerDeregisterFns;
|
|
107
110
|
private _status;
|
|
108
111
|
/** whether a status has ever been computed, so the first one always renders */
|
|
109
112
|
private computed;
|
|
@@ -152,6 +155,10 @@ export declare class SrefStatusController implements ReactiveController {
|
|
|
152
155
|
hostConnected(): void;
|
|
153
156
|
/** @internal */
|
|
154
157
|
hostDisconnected(): void;
|
|
158
|
+
private watch;
|
|
159
|
+
private unwatch;
|
|
160
|
+
/** What a disconnect and reconnect would do, for the router that replaced the one found. */
|
|
161
|
+
private readonly onRouterReplaced;
|
|
155
162
|
/**
|
|
156
163
|
* Recomputes the status and re-renders the host, but only if a flag or a
|
|
157
164
|
* watched target moved.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sref-status-controller.d.ts","mappings":"AAAA,SAAS,aAAyB,gBAAgB;AAClD,SAAS,SAAS,oBAAoB,8BAA8B;
|
|
1
|
+
{"version":3,"file":"sref-status-controller.d.ts","mappings":"AAAA,SAAS,aAAyB,gBAAgB;AAClD,SAAS,SAAS,oBAAoB,8BAA8B;AAIpE,cAAc,wBAAwB;AAOtC,SACE,kBACA,mBACA,YACA,gBACK;;;;;;;AAYP,iBAAiB,oCAAoC,iBAAiB;;;;;;;;;;;;;;CAcpE,SAAS;AACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,OAAO,cAAM,gCAAgC,mBAAmB;CAC9D,iBAAiB;CAEjB,QAAQ;CAER,iBAAiB;CAEjB,iBAAiB;;CAGjB,iBAAiB;CAEjB,QAAQ;;CAGR,QAAQ;;CAGR,QAAQ;CAER,YACE,MAAM,yBAAyB,SAC/B,UAAS;;;;;;;;CAsBX,IAAI,UAAU;;;;;CAQd,IAAI,UAAU;;CAKd,IAAI;;CAKJ,IAAI;;CAKJ,IAAI;;CAKJ,IAAI;;CAKJ,IAAI,gBAAgB;;;;;;CASpB,SAAS,QAAQ;;;;;;;;;CAejB,YACE,QAAQ,mBAAmB,oBAC1B,0BAA0B;;CAK7B;;CAqDA;CAWA,QAAQ;CASR,QAAQ;;CAQR,iBAAiB;;;;;;;CAejB,QAAQ,QAAQ;;CAOhB,QAAQ;CAQR,iBAAiB;CAKjB,iBAAiB;CAMjB,iBAAiB;CAKjB,iBAAiB;AAcnB","names":[],"ignoreList":[],"sources":["../src/sref-status-controller.ts"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nothing } from "lit";
|
|
2
2
|
import { warnMissingRouter } from "./dev-warn.js";
|
|
3
|
+
import { subscribeRouter } from "./router-subscription.js";
|
|
3
4
|
import { resolveAriaCurrent, SrefTargets } from "./sref-status.js";
|
|
4
|
-
import { UIRouterLitElement } from "./ui-router.js";
|
|
5
5
|
import { UI_SREF_TARGET_EVENT, UI_SREF_TARGET_REMOVED_EVENT } from "./ui-sref.js";
|
|
6
6
|
import { UiView } from "./ui-view.js";
|
|
7
7
|
const sameShape = (a, b) => a === b || !!a && !!b && a.active === b.active && a.exact === b.exact && a.entering === b.entering && a.exiting === b.exiting && a.targetStates.length === b.targetStates.length && a.targetStates.every((target, i) => target === b.targetStates[i]);
|
|
@@ -9,8 +9,17 @@ export class SrefStatusController {
|
|
|
9
9
|
constructor(host, options = {}) {
|
|
10
10
|
this.targets = new SrefTargets();
|
|
11
11
|
this.deregisterFns = [];
|
|
12
|
+
this.routerDeregisterFns = [];
|
|
12
13
|
this.computed = false;
|
|
13
14
|
this._connection = 0;
|
|
15
|
+
this.onRouterReplaced = (router) => {
|
|
16
|
+
this.unwatch();
|
|
17
|
+
this.targets.router = router;
|
|
18
|
+
this.targets.relative = UiView.seekParentView(this.host)?.viewContext?.name;
|
|
19
|
+
this.targets.rebuild();
|
|
20
|
+
this.watch(router);
|
|
21
|
+
this.refresh();
|
|
22
|
+
};
|
|
14
23
|
this.onUiSrefTargetEvent = (event) => {
|
|
15
24
|
this.targets.onLink(event);
|
|
16
25
|
this.refresh();
|
|
@@ -81,7 +90,11 @@ export class SrefStatusController {
|
|
|
81
90
|
}
|
|
82
91
|
hostConnected() {
|
|
83
92
|
const { host } = this;
|
|
84
|
-
|
|
93
|
+
if (!this.options.router) {
|
|
94
|
+
const { router, unsubscribe } = subscribeRouter(host, this.onRouterReplaced);
|
|
95
|
+
this.targets.router = router;
|
|
96
|
+
if (unsubscribe) this.deregisterFns.push(unsubscribe);
|
|
97
|
+
}
|
|
85
98
|
this.targets.relative = UiView.seekParentView(host)?.viewContext?.name;
|
|
86
99
|
this.targets.setExplicit();
|
|
87
100
|
const scope = host.renderRoot ?? host;
|
|
@@ -92,15 +105,22 @@ export class SrefStatusController {
|
|
|
92
105
|
scope.removeEventListener(UI_SREF_TARGET_REMOVED_EVENT, this.onUiSrefTargetRemovedEvent);
|
|
93
106
|
});
|
|
94
107
|
const router = this.targets.router;
|
|
95
|
-
if (router) this.
|
|
108
|
+
if (router) this.watch(router);
|
|
96
109
|
else warnMissingRouter(host, `new SrefStatusController() on <${host.localName}>`, "will never be marked active");
|
|
97
110
|
this.refresh();
|
|
98
111
|
}
|
|
99
112
|
hostDisconnected() {
|
|
100
|
-
this.
|
|
113
|
+
this.unwatch();
|
|
101
114
|
while (this.deregisterFns.length) this.deregisterFns.shift()?.();
|
|
102
115
|
if (!this.options.router) this.targets.router = void 0;
|
|
103
116
|
}
|
|
117
|
+
watch(router) {
|
|
118
|
+
this.routerDeregisterFns.push(router.transitionService.onStart({}, this.onTransitionStart, { priority: -Infinity }), router.stateRegistry.onStatesChanged(this.onStatesChanged));
|
|
119
|
+
}
|
|
120
|
+
unwatch() {
|
|
121
|
+
this._connection++;
|
|
122
|
+
while (this.routerDeregisterFns.length) this.routerDeregisterFns.shift()?.();
|
|
123
|
+
}
|
|
104
124
|
refresh(event) {
|
|
105
125
|
if (this.compute(event)) this.host.requestUpdate();
|
|
106
126
|
}
|