lit-ui-router 1.14.0 → 1.15.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.
Files changed (72) hide show
  1. package/README.md +8 -7
  2. package/dist/context.d.ts +275 -0
  3. package/dist/context.d.ts.map +1 -0
  4. package/dist/context.js +53 -0
  5. package/dist/context.js.map +1 -0
  6. package/dist/custom-elements.json +11 -2
  7. package/dist/development/context.js +53 -0
  8. package/dist/development/context.js.map +1 -0
  9. package/dist/development/index.js.map +1 -1
  10. package/dist/development/sref-active.js +16 -4
  11. package/dist/development/sref-active.js.map +1 -1
  12. package/dist/development/sref-href.js +3 -2
  13. package/dist/development/sref-href.js.map +1 -1
  14. package/dist/development/sref-internals.js +91 -0
  15. package/dist/development/sref-internals.js.map +1 -0
  16. package/dist/development/sref-status.js +1 -2
  17. package/dist/development/sref-status.js.map +1 -1
  18. package/dist/development/ui-router.js +10 -1
  19. package/dist/development/ui-router.js.map +1 -1
  20. package/dist/development/ui-sref-active.js +3 -43
  21. package/dist/development/ui-sref-active.js.map +1 -1
  22. package/dist/development/ui-sref.js +3 -49
  23. package/dist/development/ui-sref.js.map +1 -1
  24. package/dist/development/ui-view.js.map +1 -1
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/interface.d.ts +2 -0
  29. package/dist/interface.d.ts.map +1 -1
  30. package/dist/sref-active.d.ts +20 -4
  31. package/dist/sref-active.d.ts.map +1 -1
  32. package/dist/sref-active.js +16 -4
  33. package/dist/sref-active.js.map +1 -1
  34. package/dist/sref-href.d.ts +16 -5
  35. package/dist/sref-href.d.ts.map +1 -1
  36. package/dist/sref-href.js +3 -2
  37. package/dist/sref-href.js.map +1 -1
  38. package/dist/sref-internals.d.ts +103 -0
  39. package/dist/sref-internals.d.ts.map +1 -0
  40. package/dist/sref-internals.js +91 -0
  41. package/dist/sref-internals.js.map +1 -0
  42. package/dist/sref-status.d.ts +1 -1
  43. package/dist/sref-status.d.ts.map +1 -1
  44. package/dist/sref-status.js +1 -2
  45. package/dist/sref-status.js.map +1 -1
  46. package/dist/ui-router.d.ts +19 -0
  47. package/dist/ui-router.d.ts.map +1 -1
  48. package/dist/ui-router.js +10 -1
  49. package/dist/ui-router.js.map +1 -1
  50. package/dist/ui-sref-active.d.ts +27 -14
  51. package/dist/ui-sref-active.d.ts.map +1 -1
  52. package/dist/ui-sref-active.js +3 -43
  53. package/dist/ui-sref-active.js.map +1 -1
  54. package/dist/ui-sref.d.ts +31 -63
  55. package/dist/ui-sref.d.ts.map +1 -1
  56. package/dist/ui-sref.js +3 -49
  57. package/dist/ui-sref.js.map +1 -1
  58. package/dist/ui-view.d.ts +1 -0
  59. package/dist/ui-view.d.ts.map +1 -1
  60. package/dist/ui-view.js.map +1 -1
  61. package/package.json +22 -1
  62. package/src/context.ts +367 -0
  63. package/src/index.ts +4 -0
  64. package/src/interface.ts +2 -0
  65. package/src/sref-active.ts +38 -12
  66. package/src/sref-href.ts +19 -7
  67. package/src/sref-internals.ts +310 -0
  68. package/src/sref-status.ts +6 -3
  69. package/src/ui-router.ts +38 -1
  70. package/src/ui-sref-active.ts +30 -120
  71. package/src/ui-sref.ts +66 -182
  72. package/src/ui-view.ts +1 -0
package/README.md CHANGED
@@ -31,13 +31,14 @@ router.start();
31
31
 
32
32
  ## Entry Points
33
33
 
34
- | Import | Effect |
35
- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
36
- | `import { ... } from 'lit-ui-router'` | Full API. Any value import registers the `<ui-router>`/`<ui-view>` custom elements as a side effect. |
37
- | `import { ... } from 'lit-ui-router/pure'` | The same full API — element classes included — with no registration and no `HTMLElementTagNameMap` globals. |
38
- | `import 'lit-ui-router/register'` | Registration only: defines `<ui-router>`/`<ui-view>` and carries their `HTMLElementTagNameMap` entries. |
39
- | `import 'lit-ui-router/ui-view.register'` | Single-element registration: defines just that element with its tag-map entry (`ui-router.register` ditto). |
40
- | `import type { ... } from 'lit-ui-router'` | Types are erased at compile time — always free, from any entry. |
34
+ | Import | Effect |
35
+ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36
+ | `import { ... } from 'lit-ui-router'` | The router, the elements, the directives and the controllers. Any value import registers the `<ui-router>`/`<ui-view>` custom elements as a side effect. |
37
+ | `import { ... } from 'lit-ui-router/pure'` | The same API — element classes included — with no registration and no `HTMLElementTagNameMap` globals. |
38
+ | `import 'lit-ui-router/register'` | Registration only: defines `<ui-router>`/`<ui-view>` and carries their `HTMLElementTagNameMap` entries. |
39
+ | `import 'lit-ui-router/ui-view.register'` | Single-element registration: defines just that element with its tag-map entry (`ui-router.register` ditto). |
40
+ | `import { ... } from 'lit-ui-router/context'` | The only home of the [`context-request`](https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md) key, event and request helper, and of the tree-less router hand-off — no elements, and nothing from `lit`. |
41
+ | `import type { ... } from 'lit-ui-router'` | Types are erased at compile time — always free, from any entry. |
41
42
 
42
43
  The root entry is exactly `pure` + `register`: reach for `lit-ui-router/pure`
43
44
  when you need the APIs (or the element classes themselves, e.g. for scoped
@@ -0,0 +1,275 @@
1
+ /**
2
+ * @module
3
+ * @mergeModuleWith <project>
4
+ */
5
+ import type { UIRouter } from "@uirouter/core";
6
+ import type { UIRouterLit } from "./core.js";
7
+ /**
8
+ * A context key branded with the type of the value it references, as the
9
+ * [community context protocol](https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md)
10
+ * defines it. Structurally identical to `@lit/context`'s `Context`, so keys
11
+ * cross between the two without a cast.
12
+ *
13
+ * @category types
14
+ */
15
+ export type Context<
16
+ KeyType,
17
+ ValueType
18
+ > = KeyType & {
19
+ /** Phantom brand: the type of the value this key references. */
20
+ __context__: ValueType;
21
+ };
22
+ /**
23
+ * A context key whose value type is unknown — the protocol's `UnknownContext`.
24
+ *
25
+ * @category types
26
+ */
27
+ export type UnknownContext = Context<unknown, unknown>;
28
+ /**
29
+ * Extracts the value type a {@link Context} key carries.
30
+ *
31
+ * @category types
32
+ */
33
+ export type ContextType<T extends UnknownContext> = T extends Context<infer _KeyType, infer ValueType> ? ValueType : never;
34
+ /**
35
+ * The callback a requester hands a provider. A provider that was asked to
36
+ * `subscribe` may call it again as the value changes, passing `unsubscribe`.
37
+ *
38
+ * @category types
39
+ */
40
+ export type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
41
+ /**
42
+ * The shape a `context-request` event carries, whichever implementation
43
+ * constructed it — what a provider reads.
44
+ *
45
+ * @category types
46
+ */
47
+ export interface ContextRequest<T extends UnknownContext> {
48
+ /** The requested context key, matched by identity (`===`). */
49
+ readonly context: T;
50
+ /** Invoked with the value when a provider can satisfy the request. */
51
+ readonly callback: ContextCallback<ContextType<T>>;
52
+ /** Whether the requester wants to be called again as the value changes. */
53
+ readonly subscribe?: boolean;
54
+ }
55
+ /**
56
+ * The protocol's event name.
57
+ *
58
+ * @category core
59
+ */
60
+ export declare const contextRequestEventName: "context-request";
61
+ /**
62
+ * The identity of {@link routerContext}: a plain object, so the key is unique
63
+ * under `===` and readable in a debugger.
64
+ *
65
+ * @category types
66
+ */
67
+ export interface RouterContextKey {
68
+ /** Names the key for a debugger; identity, not this string, is what matches. */
69
+ readonly name: "lit-ui-router/context#router";
70
+ }
71
+ /**
72
+ * The router context key's type — {@link RouterContextKey} branded with
73
+ * {@link UIRouterLit}, so `@consume({ context: routerContext })` infers the
74
+ * router.
75
+ *
76
+ * @category types
77
+ */
78
+ export type RouterContext = Context<RouterContextKey, UIRouterLit>;
79
+ /**
80
+ * The context key `<ui-router>` answers for: the router instance.
81
+ *
82
+ * Speaks the community `context-request` protocol without depending on
83
+ * `@lit/context` — the key is a stable object, matched by identity, and the
84
+ * branded type is the one `createContext()` would have produced. An element
85
+ * written against `@lit/context` consumes it unchanged:
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import { consume } from '@lit/context';
90
+ * import { routerContext } from 'lit-ui-router/context';
91
+ * import type { UIRouterLit } from 'lit-ui-router';
92
+ *
93
+ * class MyElement extends LitElement {
94
+ * @consume({ context: routerContext })
95
+ * router!: UIRouterLit;
96
+ * }
97
+ * ```
98
+ *
99
+ * @see {@link requestRouter} for the dependency-free request
100
+ * @see {@link UIRouterLitElement.seekRouter} for the house `ui-router-context` event
101
+ *
102
+ * @category core
103
+ */
104
+ export declare const routerContext: RouterContext;
105
+ /**
106
+ * A `context-request` event for {@link routerContext}: bubbling, composed and
107
+ * shaped as the protocol specifies, so any provider answers it.
108
+ *
109
+ * @category core
110
+ */
111
+ export declare class RouterContextRequestEvent extends Event implements ContextRequest<RouterContext> {
112
+ /** Always {@link routerContext}. */
113
+ readonly context: RouterContext;
114
+ /** Called by the provider with the router. */
115
+ readonly callback: ContextCallback<UIRouterLit>;
116
+ /** Whether later values are wanted. */
117
+ readonly subscribe?: boolean;
118
+ /**
119
+ * @param callback - receives the router from whichever provider answers
120
+ * @param subscribe - ask the provider to call back as the router changes
121
+ */
122
+ constructor(callback: ContextCallback<UIRouterLit>, subscribe?: boolean);
123
+ }
124
+ /**
125
+ * Whether an event is a `context-request` for {@link routerContext} — the
126
+ * guard a provider runs before answering.
127
+ *
128
+ * @param event - any event a provider's listener received
129
+ *
130
+ * @category core
131
+ */
132
+ export declare const isRouterContextRequest: (event: Event) => event is Event & ContextRequest<RouterContext>;
133
+ /**
134
+ * Options for {@link requestRouter}.
135
+ *
136
+ * @category types
137
+ */
138
+ export interface RequestRouterOptions {
139
+ /**
140
+ * Ask the provider to keep calling back as the router changes; pair it with
141
+ * {@link RequestRouterOptions.callback | callback}. `<ui-router>` answers
142
+ * once and hands back a no-op unsubscribe, since it does not swap routers.
143
+ */
144
+ subscribe?: boolean;
145
+ /**
146
+ * Receives every answer, the synchronous first one included, with the
147
+ * provider's `unsubscribe` when one was offered.
148
+ */
149
+ callback?: ContextCallback<UIRouterLit>;
150
+ }
151
+ /**
152
+ * Requests the router from whichever provider answers on `target`, and returns
153
+ * the value a provider supplied synchronously.
154
+ *
155
+ * The target is any `EventTarget`, not only an element. Returns `undefined`
156
+ * when nobody answered.
157
+ *
158
+ * @param target - the event target to dispatch the request from
159
+ * @param options - subscription and callback options
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * import { requestRouter } from 'lit-ui-router/context';
164
+ *
165
+ * class MyElement extends LitElement {
166
+ * connectedCallback() {
167
+ * super.connectedCallback();
168
+ * this.router = requestRouter(this);
169
+ * }
170
+ * }
171
+ * ```
172
+ *
173
+ * @category core
174
+ */
175
+ export declare const requestRouter: (target: EventTarget, options?: RequestRouterOptions) => UIRouterLit | undefined;
176
+ /**
177
+ * Answers {@link routerContext} requests that reach `root`, so code with no
178
+ * element of its own is still handed a router.
179
+ *
180
+ * The provider is the element-free twin of `<ui-router>`: it listens for
181
+ * `context-request`, guards with {@link isRouterContextRequest}, calls
182
+ * `stopImmediatePropagation()` so an outer provider does not answer twice, and
183
+ * delivers the router synchronously. A `subscribe: true` request gets a no-op
184
+ * unsubscribe — the provider holds one router for its whole lifetime.
185
+ *
186
+ * `root` is any `EventTarget`. Under `@lit-labs/ssr` that is
187
+ * `globalThis.litServerRoot`, the bottom of the renderer's event-target stack,
188
+ * which every element event on the server reaches.
189
+ *
190
+ * Installing twice installs two listeners; the first one still wins, because it
191
+ * stops immediate propagation. Uninstalling is exact — each call's returned
192
+ * function removes only the listener that call added.
193
+ *
194
+ * The parameter is `UIRouterLit`, not `UIRouter`, because the key this answers
195
+ * is branded with `UIRouterLit`, and a provider may only answer with the value
196
+ * its key promises. The slot ({@link withRouterSync | `withRouterSync`}) takes
197
+ * either.
198
+ *
199
+ * @param root - the event target requests travel to
200
+ * @param router - the router to answer with
201
+ * @returns a function that uninstalls this provider
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * import { provideRouter } from 'lit-ui-router/context';
206
+ *
207
+ * const uninstall = provideRouter(globalThis.litServerRoot, router);
208
+ * try {
209
+ * // …render…
210
+ * } finally {
211
+ * uninstall();
212
+ * }
213
+ * ```
214
+ *
215
+ * @see {@link withRouterSync} for the slot the same render sets instead
216
+ *
217
+ * @category core
218
+ */
219
+ export declare const provideRouter: (root: EventTarget, router: UIRouterLit) => () => void;
220
+ /**
221
+ * Returns the router the innermost enclosing
222
+ * {@link withRouterSync | `withRouterSync`} call scoped, or `undefined`
223
+ * outside one.
224
+ *
225
+ * @category core
226
+ */
227
+ export declare const getScopedRouter: () => UIRouter | undefined;
228
+ /**
229
+ * Runs `run` with `router` published to {@link getScopedRouter | `getScopedRouter`},
230
+ * restoring whatever was there before — `undefined` included — when it returns
231
+ * or throws.
232
+ *
233
+ * This is the tree-less provider. A `context-request` needs a tree to bubble
234
+ * through, which is what {@link provideRouter | `provideRouter`} serves;
235
+ * `withRouterSync` publishes a router for one synchronous call instead, so code
236
+ * with no element — a server render, a test — asks `getScopedRouter()`.
237
+ *
238
+ * The `Sync` suffix names the constraint the thenable guard enforces, in the
239
+ * convention of `collectResultSync`. `@lit-labs/ssr`'s `render()` returns a
240
+ * sync generator, so a whole render happens inside `run` as long as the caller
241
+ * consumes it there: `collectResultSync(render(template))`. Nothing is detected
242
+ * and nothing is upgraded — if `run` returns a thenable the slot is restored
243
+ * and a `TypeError` is thrown, because anything that promise does later reads a
244
+ * slot that is already gone.
245
+ *
246
+ * Calls nest: an inner call sees its own router, and the outer one is restored
247
+ * on the way out.
248
+ *
249
+ * The router is any `@uirouter/core` `UIRouter`: the directives that read the
250
+ * slot want `stateService`, `stateRegistry`, `transitionService` and `globals`,
251
+ * none of which `UIRouterLit` adds, so a caller that types its router as
252
+ * `UIRouter` — the type `UIViewInjectedProps.router` declares — passes it here
253
+ * unchanged.
254
+ *
255
+ * @typeParam T - whatever `run` returns
256
+ * @param router - the router to publish for the duration of `run`
257
+ * @param run - the call the router is scoped to, consumed synchronously
258
+ * @returns whatever `run` returned
259
+ * @throws a `TypeError` if `run` returns a thenable
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * import { render } from '@lit-labs/ssr';
264
+ * import { collectResultSync } from '@lit-labs/ssr/lib/render-result.js';
265
+ * import { withRouterSync } from 'lit-ui-router/context';
266
+ *
267
+ * const markup = withRouterSync(router, () =>
268
+ * collectResultSync(render(html`<my-page></my-page>`)),
269
+ * );
270
+ * ```
271
+ *
272
+ * @category core
273
+ */
274
+ export declare const withRouterSync: <T>(router: UIRouter, run: () => T) => T;
275
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","mappings":";;;;AAKA,cAAc,gBAAgB;AAE9B,cAAc,mBAAmB;;;;;;;;;AAUjC,YAAY;CAAQ;CAAS;IAAa,UAAU;;CAElD,aAAa;AACf;;;;;;AAOA,YAAY,iBAAiB;;;;;;AAO7B,YAAY,YAAY,UAAU,kBAChC,UAAU,cAAc,gBAAgB,aAAa;;;;;;;AAQvD,YAAY,gBAAgB,cAC1B,OAAO,WACP;;;;;;;AASF,iBAAiB,eAAe,UAAU,gBAAgB;;UAE/C,SAAS;;UAET,UAAU,gBAAgB,YAAY;;UAEtC;AACX;;;;;;AAOA,OAAO,cAAM,yBAA0B;;;;;;;AAQvC,iBAAiB,iBAAiB;;UAEvB,MAAM;AACjB;;;;;;;;AASA,YAAY,gBAAgB,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BtD,OAAO,cAAM,eAAe;;;;;;;AAU5B,OAAO,cAAM,kCACH,iBACG,eAAe,eAC5B;;CAEE,SAAS,SAAS;;CAElB,SAAS,UAAU,gBAAgB;;CAEnC,SAAS;;;;;CAMT,YAAY,UAAU,gBAAgB,cAAc;AAKtD;;;;;;;;;AAUA,OAAO,cAAM,yBACX,OAAO,UACJ,SAAS,QAAQ,eAAe;;;;;;AAgBrC,iBAAiB,qBAAqB;;;;;;CAMpC;;;;;CAKA,WAAW,gBAAgB;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,OAAO,cAAM,gBACX,QAAQ,aACR,UAAU,yBACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DL,OAAO,cAAM,gBACX,MAAM,aACN,QAAQ;;;;;;;;AAqBV,OAAO,cAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDpC,OAAO,cAAM,iBAAiB,GAAG,QAAQ,UAAU,WAAW,MAAM","names":[],"ignoreList":[],"sources":["../src/context.ts"]}
@@ -0,0 +1,53 @@
1
+ export const contextRequestEventName = "context-request";
2
+ export const routerContext = Object.freeze({ name: "lit-ui-router/context#router" });
3
+ export class RouterContextRequestEvent extends Event {
4
+ constructor(callback, subscribe) {
5
+ super(contextRequestEventName, {
6
+ bubbles: true,
7
+ composed: true
8
+ });
9
+ this.context = routerContext;
10
+ this.callback = callback;
11
+ this.subscribe = subscribe;
12
+ }
13
+ }
14
+ export const isRouterContextRequest = (event) => {
15
+ const request = event;
16
+ return event.type === contextRequestEventName && request.context === routerContext && typeof request.callback === "function";
17
+ };
18
+ export const requestRouter = (target, options = {}) => {
19
+ let answer;
20
+ let answered = false;
21
+ target.dispatchEvent(new RouterContextRequestEvent((router, unsubscribe) => {
22
+ if (!answered) {
23
+ answered = true;
24
+ answer = router;
25
+ }
26
+ options.callback?.(router, unsubscribe);
27
+ }, options.subscribe));
28
+ return answer;
29
+ };
30
+ export const provideRouter = (root, router) => {
31
+ const listener = (event) => {
32
+ if (!isRouterContextRequest(event)) return;
33
+ event.stopImmediatePropagation();
34
+ event.callback(router, event.subscribe ? () => {} : void 0);
35
+ };
36
+ root.addEventListener(contextRequestEventName, listener);
37
+ return () => root.removeEventListener(contextRequestEventName, listener);
38
+ };
39
+ let scoped;
40
+ export const getScopedRouter = () => scoped;
41
+ export const withRouterSync = (router, run) => {
42
+ const previous = scoped;
43
+ scoped = router;
44
+ let result;
45
+ try {
46
+ result = run();
47
+ } finally {
48
+ scoped = previous;
49
+ }
50
+ if (typeof result?.then === "function") throw new TypeError("withRouterSync() is synchronous: `run` returned a thenable, and the router slot is already restored by the time it settles. Consume the render inside `run` — collectResultSync(render(template)) — or read the router before awaiting.");
51
+ return result;
52
+ };
53
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","mappings":"AAoEA,OAAO,MAAM,0BAA0B;AA+CvC,OAAO,MAAM,gBAA+B,OAAO,OAAO,EACxD,MAAM,+BACR,CAAC;AAQD,OAAO,MAAM,kCACH,MAEV;CAYE,YAAY,UAAwC,WAAqB;EACvE,MAAM,yBAAyB;GAAE,SAAS;GAAM,UAAU;EAAK,CAAC;iBAXhC;EAYhC,KAAK,WAAW;EAChB,KAAK,YAAY;CACnB;AACF;AAUA,OAAO,MAAM,0BAGX,UACmD;CACnD,MAAM,UAAU;CAChB,OACE,MAAM,SAAS,2BACf,QAAQ,YAAY,iBACpB,OAAO,QAAQ,aAAa;AAEhC;AA6CA,OAAO,MAAM,iBAIX,QACA,UAAgC,CAAC,MACL;CAC5B,IAAI;CACJ,IAAI,WAAW;CACf,OAAO,cACL,IAAI,2BAA2B,QAAQ,gBAAgB;EACrD,IAAI,CAAC,UAAU;GACb,WAAW;GACX,SAAS;EACX;EACA,QAAQ,WAAW,QAAQ,WAAW;CACxC,GAAG,QAAQ,SAAS,CACtB;CACA,OAAO;AACT;AA6CA,OAAO,MAAM,iBAGM,MAAmB,WAAsC;CAC1E,MAAM,YAAY,UAAuB;EACvC,IAAI,CAAC,uBAAuB,KAAK,GAAG;EACpC,MAAM,yBAAyB;EAC/B,MAAM,SAAS,QAAQ,MAAM,kBAAkB,CAAC,IAAI,MAAS;CAC/D;CACA,KAAK,iBAAiB,yBAAyB,QAAQ;CACvD,aAAa,KAAK,oBAAoB,yBAAyB,QAAQ;AACzE;AAGA,IAAI;AASJ,OAAO,MAAM,wBAEI;AAgDjB,OAAO,MAAM,kBACX,QACA,QACM;CACN,MAAM,WAAW;CACjB,SAAS;CACT,IAAI;CACJ,IAAI;EACF,SAAS,IAAI;CACf,UAAU;EACR,SAAS;CACX;CACA,IAAI,OAAQ,QAA2C,SAAS,YAC9D,MAAM,IAAI,UACR,yOACF;CAEF,OAAO;AACT","names":[],"ignoreList":[],"sources":["../src/context.ts"]}
@@ -24,6 +24,7 @@
24
24
  "text": "string"
25
25
  },
26
26
  "default": "''",
27
+ "description": "the view name this viewport fills; empty selects the `$default` view",
27
28
  "attribute": "name"
28
29
  },
29
30
  {
@@ -295,6 +296,7 @@
295
296
  "text": "string"
296
297
  },
297
298
  "default": "''",
299
+ "description": "the view name this viewport fills; empty selects the `$default` view",
298
300
  "fieldName": "name"
299
301
  }
300
302
  ],
@@ -371,13 +373,20 @@
371
373
  }
372
374
  }
373
375
  ],
374
- "description": "Discovers the UIRouterLit instance provided by the nearest\nenclosing <code>&lt;ui-router&gt;</code> element.\n\nDispatches a bubbling, composed <code>ui-router-context</code> event from\nthe candidate element; the enclosing <code>&lt;ui-router&gt;</code>\nanswers it with its router instance. Returns <code>undefined</code> when\nthe candidate is not inside a <code>&lt;ui-router&gt;</code> (e.g. not\nyet connected).\n\nThis is the dependency-injection primitive for integrating external\nreactivity systems (state stores, controllers) with the router context —\ncall it from <code>hostConnected()</code> / <code>connectedCallback()</code>\ninstead of prop-drilling the router instance."
376
+ "description": "Discovers the UIRouterLit instance provided by the nearest\nenclosing <code>&lt;ui-router&gt;</code> element.\n\nDispatches a bubbling, composed <code>ui-router-context</code> event from\nthe candidate element; the enclosing <code>&lt;ui-router&gt;</code>\nanswers it with its router instance. Returns <code>undefined</code> when\nthe candidate is not inside a <code>&lt;ui-router&gt;</code> (e.g. not\nyet connected).\n\nThis is the dependency-injection primitive for integrating external\nreactivity systems (state stores, controllers) with the router context —\ncall it from <code>hostConnected()</code> / <code>connectedCallback()</code>\ninstead of prop-drilling the router instance.\n\nWhen no <code>&lt;ui-router&gt;</code> answers, it asks again with\nrequestRouter, so an ancestor providing routerContext\nover the community protocol — a bare <code>@lit/context</code>\n<code>ContextProvider</code>, say — is found as well."
375
377
  },
376
378
  {
377
379
  "kind": "field",
378
380
  "name": "onUiRouterContextEvent",
379
381
  "privacy": "private",
380
382
  "readonly": true
383
+ },
384
+ {
385
+ "kind": "field",
386
+ "name": "onContextRequest",
387
+ "privacy": "private",
388
+ "readonly": true,
389
+ "description": "Answers a `context-request` for the router context.\n\n`subscribe` gets one call and a no-op unsubscribe: the element takes its\nrouter on connect and does not swap it afterwards."
381
390
  }
382
391
  ],
383
392
  "events": [
@@ -385,7 +394,7 @@
385
394
  "type": {
386
395
  "text": "CustomEvent"
387
396
  },
388
- "description": "<code>&lt;ui-router&gt;</code> listens to the <code>ui-router-context</code> event and provides the <code>uiRouter</code> instance.",
397
+ "description": "<code>&lt;ui-router&gt;</code> listens to the <code>ui-router-context</code> event and provides the <code>uiRouter</code> instance. It answers the community <code>context-request</code> protocol for {@link routerContext} from the same listener position, so an element built on <code>@lit/context</code> gets the router too. The two paths coexist and neither sees the other's event: {@link UIRouterLitElement.seekRouter} asks on <code>ui-router-context</code> first and falls back to {@link requestRouter}.",
389
398
  "name": "ui-router-context"
390
399
  }
391
400
  ],
@@ -0,0 +1,53 @@
1
+ export const contextRequestEventName = "context-request";
2
+ export const routerContext = Object.freeze({ name: "lit-ui-router/context#router" });
3
+ export class RouterContextRequestEvent extends Event {
4
+ constructor(callback, subscribe) {
5
+ super(contextRequestEventName, {
6
+ bubbles: true,
7
+ composed: true
8
+ });
9
+ this.context = routerContext;
10
+ this.callback = callback;
11
+ this.subscribe = subscribe;
12
+ }
13
+ }
14
+ export const isRouterContextRequest = (event) => {
15
+ const request = event;
16
+ return event.type === contextRequestEventName && request.context === routerContext && typeof request.callback === "function";
17
+ };
18
+ export const requestRouter = (target, options = {}) => {
19
+ let answer;
20
+ let answered = false;
21
+ target.dispatchEvent(new RouterContextRequestEvent((router, unsubscribe) => {
22
+ if (!answered) {
23
+ answered = true;
24
+ answer = router;
25
+ }
26
+ options.callback?.(router, unsubscribe);
27
+ }, options.subscribe));
28
+ return answer;
29
+ };
30
+ export const provideRouter = (root, router) => {
31
+ const listener = (event) => {
32
+ if (!isRouterContextRequest(event)) return;
33
+ event.stopImmediatePropagation();
34
+ event.callback(router, event.subscribe ? () => {} : void 0);
35
+ };
36
+ root.addEventListener(contextRequestEventName, listener);
37
+ return () => root.removeEventListener(contextRequestEventName, listener);
38
+ };
39
+ let scoped;
40
+ export const getScopedRouter = () => scoped;
41
+ export const withRouterSync = (router, run) => {
42
+ const previous = scoped;
43
+ scoped = router;
44
+ let result;
45
+ try {
46
+ result = run();
47
+ } finally {
48
+ scoped = previous;
49
+ }
50
+ if (typeof result?.then === "function") throw new TypeError("withRouterSync() is synchronous: `run` returned a thenable, and the router slot is already restored by the time it settles. Consume the render inside `run` — collectResultSync(render(template)) — or read the router before awaiting.");
51
+ return result;
52
+ };
53
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","mappings":"AAoEA,OAAO,MAAM,0BAA0B;AA+CvC,OAAO,MAAM,gBAA+B,OAAO,OAAO,EACxD,MAAM,+BACR,CAAC;AAQD,OAAO,MAAM,kCACH,MAEV;CAYE,YAAY,UAAwC,WAAqB;EACvE,MAAM,yBAAyB;GAAE,SAAS;GAAM,UAAU;EAAK,CAAC;iBAXhC;EAYhC,KAAK,WAAW;EAChB,KAAK,YAAY;CACnB;AACF;AAUA,OAAO,MAAM,0BAGX,UACmD;CACnD,MAAM,UAAU;CAChB,OACE,MAAM,SAAS,2BACf,QAAQ,YAAY,iBACpB,OAAO,QAAQ,aAAa;AAEhC;AA6CA,OAAO,MAAM,iBAIX,QACA,UAAgC,CAAC,MACL;CAC5B,IAAI;CACJ,IAAI,WAAW;CACf,OAAO,cACL,IAAI,2BAA2B,QAAQ,gBAAgB;EACrD,IAAI,CAAC,UAAU;GACb,WAAW;GACX,SAAS;EACX;EACA,QAAQ,WAAW,QAAQ,WAAW;CACxC,GAAG,QAAQ,SAAS,CACtB;CACA,OAAO;AACT;AA6CA,OAAO,MAAM,iBAGM,MAAmB,WAAsC;CAC1E,MAAM,YAAY,UAAuB;EACvC,IAAI,CAAC,uBAAuB,KAAK,GAAG;EACpC,MAAM,yBAAyB;EAC/B,MAAM,SAAS,QAAQ,MAAM,kBAAkB,CAAC,IAAI,MAAS;CAC/D;CACA,KAAK,iBAAiB,yBAAyB,QAAQ;CACvD,aAAa,KAAK,oBAAoB,yBAAyB,QAAQ;AACzE;AAGA,IAAI;AASJ,OAAO,MAAM,wBAEI;AAgDjB,OAAO,MAAM,kBACX,QACA,QACM;CACN,MAAM,WAAW;CACjB,SAAS;CACT,IAAI;CACJ,IAAI;EACF,SAAS,IAAI;CACf,UAAU;EACR,SAAS;CACX;CACA,IAAI,OAAQ,QAA2C,SAAS,YAC9D,MAAM,IAAI,UACR,yOACF;CAEF,OAAO;AACT","names":[],"ignoreList":[],"sources":["../../src/context.ts"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":"AACA,OAAO;AAEP,cAAc","names":[],"ignoreList":[],"sources":["../../src/index.ts"]}
1
+ {"version":3,"file":"index.js","mappings":"AAKA,OAAO;AAEP,cAAc","names":[],"ignoreList":[],"sources":["../../src/index.ts"]}
@@ -1,6 +1,7 @@
1
1
  import { noChange, nothing } from "lit";
2
2
  import { directive, PartType } from "lit/directive.js";
3
3
  import { AsyncDirective } from "lit/async-directive.js";
4
+ import { getScopedRouter } from "./context.js";
4
5
  import { warnMissingRouter } from "./dev-warn.js";
5
6
  import { resolveAriaCurrent, SrefTargets } from "./sref-status.js";
6
7
  import { UIRouterLitElement } from "./ui-router.js";
@@ -44,6 +45,16 @@ export class SrefStatusDirective extends AsyncDirective {
44
45
  if (partInfo.type !== PartType.ATTRIBUTE) throw new Error(`The \`${directiveName}\` directive must be used in an attribute`);
45
46
  this.attributeName = partInfo.name;
46
47
  }
48
+ getScopedStatus(params) {
49
+ if (this.status || this.uiRouter) return this.status;
50
+ const router = getScopedRouter();
51
+ if (!router) return this.status;
52
+ this.targets.router = router;
53
+ this.targets.params = params;
54
+ this.targets.setExplicit();
55
+ this.status = this.targets.status();
56
+ return this.status;
57
+ }
47
58
  update(part, [params]) {
48
59
  this.params = params;
49
60
  this.targets.params = params;
@@ -112,7 +123,7 @@ export class SrefActiveClassDirective extends SrefStatusDirective {
112
123
  return info;
113
124
  }
114
125
  render(params) {
115
- if (!this.status) return noChange;
126
+ if (!this.getScopedStatus(params)) return noChange;
116
127
  const info = this.classInfo(params);
117
128
  return " " + Object.keys(info).filter((name) => info[name]).join(" ") + " ";
118
129
  }
@@ -160,9 +171,10 @@ export class SrefAriaCurrentDirective extends SrefStatusDirective {
160
171
  this._wrote = true;
161
172
  return this.render(this.params);
162
173
  }
163
- render({ value = "page" }) {
164
- if (!this.status) return noChange;
165
- return resolveAriaCurrent(this.status, value);
174
+ render(params) {
175
+ const status = this.getScopedStatus(params);
176
+ if (!status) return noChange;
177
+ return resolveAriaCurrent(status, params.value);
166
178
  }
167
179
  }
168
180
  export const srefActiveClass = directive(SrefActiveClassDirective);
@@ -1 +1 @@
1
- {"version":3,"file":"sref-active.js","mappings":"AACA,SAAS,UAAU,eAA8B;AACjD,SAEE,WAEA,gBACK;AAGP,SAAS,sBAAsB;AAG/B,SAAS,yBAAyB;AAClC,SAAS,oBAAoB,mBAAmB;AAChD,SAAS,0BAA0B;AACnC,SACE,sBACA,oCAEK;AAOP,SAAS,cAAc;AAgCvB,OAAO,MAAe,4BAEZ,eAAe;CA4BvB,YACE,UACA,eACA;EACA,MAAM,QAAQ;EAFK;iBA7BK;oBAEE;iBAWc,IAAI,YAAY;uBAElC;qBACc,CAAC;qBAEjB;8BA0GC,UAAmC;GACxD,KAAK,QAAQ,OAAO,KAAK;GACzB,KAAK,QAAQ;EACf;qCAG8B,UAAuB;GACnD,IAAI,KAAK,QAAQ,cAAc,KAAK,GAClC,KAAK,QAAQ;EAEjB;+BAQ8B;GAC5B,KAAK,QAAQ,QAAQ;GACrB,KAAK,QAAQ;EACf;4BAGqB,UAA4B;GAG/C,MAAM,aAAa,KAAK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YAAY,QAC9C,MAAM,IAAI,MACR,kEACF;CAEJ;CAGA,SAA4B;EAC1B,IAAI,CAAC,KAAK,QACR,OAAO,KAAK,SAAS,UAAU;EAEjC,KAAK,SAAS;EACd,OAAO,KAAK,OAAO,KAAK,MAAO;CACjC;CAMA,OACE,QACqD;EACrD,MAAM,SAAS,KAAK,gBAAgB,MAAM;EAC1C,IAAI,CAAC,QACH,OAAO;EAET,OAAO,mBAAmB,QAAQ,OAAO,KAAK;CAChD;AACF;AAsDA,OAAO,MAAM,kBAE2C,UACtD,wBACF;AA4BA,OAAO,MAAM,kBAE2C,UACtD,wBACF","names":[],"ignoreList":[],"sources":["../../src/sref-active.ts"]}
@@ -1,9 +1,10 @@
1
1
  import { noChange, nothing } from "lit";
2
2
  import { directive, PartType } from "lit/directive.js";
3
3
  import { AsyncDirective } from "lit/async-directive.js";
4
+ import { getScopedRouter } from "./context.js";
4
5
  import { warnMissingRouter } from "./dev-warn.js";
5
6
  import { UIRouterLitElement } from "./ui-router.js";
6
- import { clickBelongsToBrowser, sameTarget, srefTransitionOptions, uiSrefTargetEvent, uiSrefTargetRemovedEvent } from "./ui-sref.js";
7
+ import { clickBelongsToBrowser, sameTarget, srefTransitionOptions, uiSrefTargetEvent, uiSrefTargetRemovedEvent } from "./sref-internals.js";
7
8
  import { UiView } from "./ui-view.js";
8
9
  export class SrefHrefDirective extends AsyncDirective {
9
10
  constructor(partInfo) {
@@ -38,7 +39,7 @@ export class SrefHrefDirective extends AsyncDirective {
38
39
  return srefTransitionOptions(this.parentView, opts);
39
40
  }
40
41
  render(state, params, options) {
41
- const $state = this.uiRouter?.stateService;
42
+ const $state = (this.uiRouter ?? getScopedRouter())?.stateService;
42
43
  if (!$state) {
43
44
  if (this._seekedRouter) this.warnMissingRouter(state);
44
45
  return noChange;
@@ -1 +1 @@
1
- {"version":3,"file":"sref-href.js","mappings":"AACA,SAAS,UAAU,eAA8B;AACjD,SAAS,WAAqB,gBAAgB;AAE9C,SAAS,sBAAs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