lit-ui-router 1.2.4 → 1.2.5

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/README.md CHANGED
@@ -7,4 +7,34 @@
7
7
  [![Website](https://img.shields.io/website?url=https%3A%2F%2Flit-ui-router.dev)](https://lit-ui-router.dev)
8
8
  [![codecov](https://codecov.io/gh/simshanith/lit-ui-router/graph/badge.svg?component=lit-ui-router)](https://app.codecov.io/gh/simshanith/lit-ui-router?components%5B0%5D=lit-ui-router)
9
9
 
10
- A UI Router implementation for Lit.
10
+ A [UI-Router](https://ui-router.github.io/) implementation for [Lit](https://lit.dev/).
11
+
12
+ ## Quick Start
13
+
14
+ ```ts
15
+ import { UIRouterLit } from 'lit-ui-router';
16
+ import { hashLocationPlugin } from '@uirouter/core';
17
+ import { html } from 'lit';
18
+
19
+ const router = new UIRouterLit();
20
+ router.plugin(hashLocationPlugin);
21
+
22
+ router.stateRegistry.register([
23
+ { name: 'home', url: '/', component: () => html`<h1>Home</h1>` },
24
+ { name: 'about', url: '/about', component: () => html`<h1>About</h1>` },
25
+ ]);
26
+
27
+ router.start();
28
+ ```
29
+
30
+ ## Component Styles
31
+
32
+ | Style | Best For | Example |
33
+ | ------------------- | ----------------------------- | -------------------------- |
34
+ | Template function | Simple views, prototyping | `` () => html`...` `` |
35
+ | Template with props | Views needing params/resolves | `` (props) => html`...` `` |
36
+ | LitElement class | Complex views with lifecycle | `MyComponent` |
37
+
38
+ ## Documentation
39
+
40
+ Visit [lit-ui-router.dev](https://lit-ui-router.dev) for full documentation, tutorials, and API reference.
@@ -166,21 +166,31 @@ export interface UIViewInjectedProps<T extends DefaultResolvesType = DefaultReso
166
166
  /**
167
167
  * A function that returns a Lit TemplateResult for rendering in a `<ui-view>`.
168
168
  *
169
- * This is one of the component types that can be used in state declarations.
170
- * The function receives [[UIViewInjectedProps]] as its argument.
171
- * [[NormalizedLitViewDeclaration.component]] uses this signature.
169
+ * This is the **simplest way** to define route components - no LitElement class needed.
170
+ * The function optionally receives [[UIViewInjectedProps]] as its argument.
172
171
  *
173
- * @example
172
+ * @example Simple template (no props needed)
174
173
  * ```ts
175
- * const HomeView: RoutedLitTemplate = (props) => {
176
- * return html`<h1>Welcome Home</h1>`;
177
- * };
174
+ * const HomeView: RoutedLitTemplate = () => html`<h1>Welcome Home</h1>`;
178
175
  *
179
- * router.stateRegistry.register({
180
- * name: 'home',
181
- * url: '/home',
182
- * component: HomeView
183
- * });
176
+ * // Or use directly inline in a state declaration:
177
+ * { name: 'home', url: '/', component: () => html`<h1>Home</h1>` }
178
+ * ```
179
+ *
180
+ * @example With route parameters
181
+ * ```ts
182
+ * const UserView: RoutedLitTemplate = (props) => html`
183
+ * <h1>User: ${props?.transition?.params().id}</h1>
184
+ * `;
185
+ * ```
186
+ *
187
+ * @example With resolved data (typed)
188
+ * ```ts
189
+ * interface UserResolves { user: { name: string } }
190
+ *
191
+ * const UserDetail: RoutedLitTemplate<UserResolves> = (props) => html`
192
+ * <h1>${props?.resolves?.user?.name}</h1>
193
+ * `;
184
194
  * ```
185
195
  *
186
196
  * @category types
@@ -266,38 +276,51 @@ export type LitViewDeclaration<T extends DefaultResolvesType = DefaultResolvesTy
266
276
  * State declaration interface for Lit applications.
267
277
  *
268
278
  * Extends the core [[StateDeclaration]] with Lit-specific component support.
279
+ * The `component` property accepts template functions, LitElement classes, or both.
269
280
  *
270
- * @example Basic state with template function
281
+ * @example Simplest: inline template function
271
282
  * ```ts
272
- * const homeState: LitStateDeclaration = {
273
- * name: 'home',
274
- * url: '/home',
275
- * component: () => html`<h1>Home</h1>`
276
- * };
283
+ * { name: 'home', url: '/', component: () => html`<h1>Home</h1>` }
284
+ * ```
285
+ *
286
+ * @example Template with route parameters
287
+ * ```ts
288
+ * {
289
+ * name: 'user',
290
+ * url: '/user/:id',
291
+ * component: (props) => html`<h1>User ${props?.transition?.params().id}</h1>`
292
+ * }
277
293
  * ```
278
294
  *
279
- * @example State with LitElement class
295
+ * @example Template with resolved data
280
296
  * ```ts
281
- * const usersState: LitStateDeclaration = {
297
+ * {
282
298
  * name: 'users',
283
299
  * url: '/users',
284
- * component: UserListElement,
285
- * resolve: [
286
- * { token: 'users', resolveFn: () => fetch('/api/users').then(r => r.json()) }
287
- * ]
288
- * };
300
+ * component: (props) => html`
301
+ * <ul>${props?.resolves?.users?.map(u => html`<li>${u.name}</li>`)}</ul>
302
+ * `,
303
+ * resolve: [{ token: 'users', resolveFn: () => fetch('/api/users').then(r => r.json()) }]
304
+ * }
305
+ * ```
306
+ *
307
+ * @example LitElement class (for complex components)
308
+ * ```ts
309
+ * { name: 'dashboard', url: '/dashboard', component: DashboardElement }
289
310
  * ```
290
311
  *
291
312
  * @example Nested states
292
313
  * ```ts
293
314
  * const states: LitStateDeclaration[] = [
294
315
  * { name: 'app', abstract: true, component: AppShell },
295
- * { name: 'app.home', url: '/home', component: HomeView },
316
+ * { name: 'app.home', url: '/home', component: () => html`<h1>Home</h1>` },
296
317
  * { name: 'app.users', url: '/users', component: UsersView }
297
318
  * ];
298
319
  * ```
299
320
  *
300
321
  * @see [[StateDeclaration]]
322
+ * @see {@link RoutedLitTemplate}
323
+ * @see {@link RoutedLitElement}
301
324
  *
302
325
  * @category types
303
326
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lit-ui-router",
3
3
  "description": "State-based routing for Lit",
4
- "version": "1.2.4",
4
+ "version": "1.2.5",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "homepage": "https://lit-ui-router.dev",