@brightspace-ui/labs 2.33.0 → 2.33.1

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/package.json CHANGED
@@ -114,5 +114,5 @@
114
114
  "resize-observer-polyfill": "^1",
115
115
  "webvtt-parser": "^2.1.2"
116
116
  },
117
- "version": "2.33.0"
117
+ "version": "2.33.1"
118
118
  }
@@ -1,14 +1,10 @@
1
- # @brightspace-ui/labs/utilities/lit-router
1
+ # Router
2
2
 
3
- A Lit wrapper around the [Page.js Router](https://visionmedia.github.io/page.js/).
3
+ A Lit wrapper around the [Page.js Router](https://visionmedia.github.io/page.js/), providing an easy way to define routes, lazy load the view, and react to changes to the route.
4
4
 
5
- The aim of this library is to provide an easy way to define routes, lazy load the view, and react to changes to the route.
5
+ ## Route Registration
6
6
 
7
- ## Usage
8
-
9
- ### Route Registration
10
-
11
- Registering routes defines the routing table used when determining the view to render.
7
+ To define the routing table that gets used when determining which view to render, `registerRoutes` should be executed once -- typically by the root of the application.
12
8
 
13
9
  When the URL matches a particular route's pattern, the `view` function is called and returns a Lit `html` literal to render.
14
10
 
@@ -17,36 +13,29 @@ import { registerRoutes } from '@brightspace-ui/labs/utilities/lit-router';
17
13
 
18
14
  registerRoutes([
19
15
  {
20
- pattern: '/example',
16
+ pattern: '/my-app',
21
17
  loader: () => import('./home.js'),
22
- view: () => html`<test-home></test-home>`
23
- },
24
- {
25
- pattern: '/example/:id',
26
- view: ctx => html`<test-id id=${ctx.params.id}></test-id>`
18
+ view: () => html`<my-app-home></my-app-home>`
27
19
  },
28
20
  {
29
- pattern: '/example/foo/:bar',
30
- view: ctx => html`
31
- <test-foo bar=${ctx.params.bar}>
32
- ${ctx.search.name}
33
- </test-foo>
34
- `
21
+ pattern: '/my-app/user/:id',
22
+ loader: () => import('./user.js'),
23
+ view: ctx => html`<my-app-user id="${ctx.params.id}"></my-app-user>`
35
24
  }
36
25
  ], options);
37
26
  ```
38
27
 
39
- #### Route Properties
28
+ ### Route Properties
40
29
 
41
30
  Each route has the following properties:
42
31
  - `pattern` (required): The Page.js route pattern on which to match
43
- - `loader` (optional): Allows for lazy-loading dependencies (e.g. importing view files) before rendering the view; must return a Promise
32
+ - `loader` (optional): Allows for lazy-loading dependencies (e.g. importing view files) before rendering the view; must return a `Promise`
44
33
  - `view` (optional): Function that returns a Lit `html` literal to render
45
34
  - `to` (optional): String indicating a redirect path, using Page.js `redirect(fromPath, toPath)`
46
35
 
47
- #### View Context
36
+ ### View Context
48
37
 
49
- The view is provided a context object containing:
38
+ The view delegate is provided a context object containing:
50
39
  - `params`: URL segment parameters (e.g. `:id`)
51
40
  - `search`: search query values
52
41
  - `options`: object passed by the entry-point
@@ -59,20 +48,20 @@ The view is provided a context object containing:
59
48
  Example:
60
49
  ```js
61
50
  {
62
- pattern: '/user/:id/:page' // search: ?semester=1
51
+ pattern: '/my-app/user/:id/:page' // search: ?semester=1
63
52
  view: ctx => html`
64
- <user-view
65
- id=${ctx.options.id}
66
- page=${ctx.params.page}
67
- semester=${ctx.search.semester}>
68
- </user-view>
53
+ <my-app-user
54
+ id="${ctx.options.id}"
55
+ page="${ctx.params.page}"
56
+ semester="${ctx.search.semester}">
57
+ </my-app-user>
69
58
  `
70
59
  }
71
60
  ```
72
61
 
73
- #### Options
62
+ ### Options
74
63
 
75
- Options are the second parameter passed to `registerRoutes`. The two tables below encompasses all of the attributes that the options object can use.
64
+ Options are the second parameter passed to `registerRoutes`. The two tables below encompass all the attributes that the options object can use.
76
65
 
77
66
  Page.js options:
78
67
 
@@ -139,9 +128,9 @@ export const loader () => [
139
128
  ]
140
129
  ```
141
130
 
142
- ### RouteReactor
131
+ ## Rendering the Active view using RouteReactor
143
132
 
144
- The `RouteReactor` is a [Reactive Controller](https://lit.dev/docs/composition/controllers/) responsible for re-rendering the nested view when the route changes.
133
+ The `RouteReactor` is a [Reactive Controller](https://lit.dev/docs/composition/controllers/) responsible for rendering (and re-rendering) the active view whenever the route changes.
145
134
 
146
135
  ```js
147
136
  import { RouteReactor } from '@brightspace-ui/labs/utilities/lit-router';
@@ -183,38 +172,40 @@ class FooBar extends LitElement {
183
172
  }
184
173
  ```
185
174
 
186
- ### Helpers
175
+ ## Navigating and Redirecting
187
176
 
188
- #### Navigating and Redirecting
177
+ Page.js will hook into any `<a>` tags and handle the navigation automatically.
189
178
 
190
- Page.js will hook into any `<a>` tags and handle the navigation automatically. However, to navigate manually use `navigate(path)`:
179
+ To navigate manually and add a new browser history entry, use `navigate(path)`:
191
180
 
192
181
  ```js
193
182
  import { navigate } from '@brightspace-ui/labs/utilities/lit-router';
194
183
 
195
- navigate('/');
184
+ navigate('/my-app/new-place');
196
185
  ```
197
186
 
198
- To programmatically redirect to a page and have the previous history item be replaced with the new one, use `redirect(path)`:
187
+ To redirect to a page and replace the previous browser history item the new one, use `redirect(path)`:
199
188
 
200
189
  ```js
201
190
  import { redirect } from '@brightspace-ui/labs/utilities/lit-router';
202
191
 
203
- redirect('/');
192
+ redirect('/my-app/new-place');
204
193
  ```
205
194
 
206
- ### Testing Routing in Your Application
195
+ ## Testing Routing in Your Application
207
196
 
208
197
  For testing page routing in your application, this template is recommended:
209
198
 
210
199
  ```js
200
+ import { RouterTesting } from '@brightspace-ui/labs/utilities/lit-router';
201
+
211
202
  describe('Page Routing', () => {
212
203
 
213
204
  beforeEach(async () => {
214
205
  // Initialize the routes here or import a file
215
206
  // that calls registerRoutes and expose a way to recall it
216
207
  initRouter();
217
- entryPoint = await fixture(html`<!-- Your ViewReactor component here -->`);
208
+ entryPoint = await fixture(html`<!-- Your RouteReactor component here -->`);
218
209
  navigate('/'); // Reset tests back to the index, clears the url
219
210
  });
220
211
 
@@ -259,39 +250,3 @@ registerRoutes([
259
250
  ```
260
251
 
261
252
  Note: The reason this is an opt-in fix is that a lot of existing implementations of lit-router have worked around this issue by putting the wildcard routes at the start, which would break if the issue were fixed for everyone automatically.
262
-
263
- ## Developing and Contributing
264
-
265
- After cloning the repo, run `npm install` to install dependencies.
266
-
267
- ### Testing
268
-
269
- To run the full suite of tests:
270
-
271
- ```shell
272
- npm test
273
- ```
274
-
275
- Alternatively, tests can be selectively run:
276
-
277
- ```shell
278
- # eslint
279
- npm run lint
280
-
281
- # unit tests
282
- npm run test:unit
283
- ```
284
-
285
- ### Running the demos
286
-
287
- To start a [@web/dev-server](https://modern-web.dev/docs/dev-server/overview/) that hosts the demo pages and tests:
288
-
289
- ```shell
290
- npm start
291
- ```
292
-
293
- ### Versioning and Releasing
294
-
295
- This repo is configured to use `semantic-release`. Commits prefixed with `fix:` and `feat:` will trigger patch and minor releases when merged to `main`.
296
-
297
- To learn how to create major releases and release from maintenance branches, refer to the [semantic-release GitHub Action](https://github.com/BrightspaceUI/actions/tree/main/semantic-release) documentation.
@@ -93,7 +93,7 @@ export const registerRoutes = (routes, options) => {
93
93
  if (hasRegistered) throw new Error('May not construct multiple routers.');
94
94
  hasRegistered = true;
95
95
 
96
- if (!options?.enableRouteOrderFix) console.warn('lit-router: The enableRouteOrderFix option is not enabled. This may cause issues with route handling. See here for details: https://github.com/BrightspaceUILabs/router/blob/main/README.md#route-order-inversion-issue');
96
+ if (!options?.enableRouteOrderFix) console.warn('lit-router: The enableRouteOrderFix option is not enabled. This may cause issues with route handling. See here for details: https://github.com/BrightspaceUI/labs/tree/main/src/utilities/router#route-order-inversion-issue');
97
97
 
98
98
  configure(options);
99
99