@lightningjs/blits 1.37.0 → 1.38.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.
- package/CHANGELOG.md +6 -0
- package/index.d.ts +33 -9
- package/package.json +3 -2
- package/src/router/router.js +35 -9
package/CHANGELOG.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -185,15 +185,31 @@ declare module '@lightningjs/blits' {
|
|
|
185
185
|
[key: string]: any
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Router Options that can be used at the same time.
|
|
190
|
+
*/
|
|
191
|
+
interface ConcurrentRouteOpts {
|
|
190
192
|
/**
|
|
191
193
|
* Whether the page navigation should be added to the history stack
|
|
192
194
|
* used when navigating back using `this.$router.back()`
|
|
193
195
|
*
|
|
194
196
|
* @default true
|
|
195
197
|
*/
|
|
196
|
-
inHistory?:
|
|
198
|
+
inHistory?: boolean,
|
|
199
|
+
passFocus?: boolean,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Route Options that can't be true at the same time
|
|
204
|
+
*/
|
|
205
|
+
type MutualExclusiveRouteOpts = {
|
|
206
|
+
/**
|
|
207
|
+
* Whether the router should reuse the current page component instance (when matching with the Component
|
|
208
|
+
* specified for the route that we're routing to).
|
|
209
|
+
*
|
|
210
|
+
* @default true
|
|
211
|
+
*/
|
|
212
|
+
reuseComponent?: true,
|
|
197
213
|
/**
|
|
198
214
|
* Whether the page should be kept alive when navigating away. Can be useful
|
|
199
215
|
* for a homepage where the state should be fully retained when navigating back
|
|
@@ -201,17 +217,25 @@ declare module '@lightningjs/blits' {
|
|
|
201
217
|
*
|
|
202
218
|
* @default false
|
|
203
219
|
*/
|
|
204
|
-
keepAlive?:
|
|
220
|
+
keepAlive?: false
|
|
221
|
+
} | {
|
|
205
222
|
/**
|
|
206
|
-
* Whether the
|
|
207
|
-
*
|
|
208
|
-
* RouterView, where the widget should maintain the focus (instead of the new page, which
|
|
209
|
-
* is the default behaviour)
|
|
223
|
+
* Whether the router should reuse the current page component instance (when matching with the Component
|
|
224
|
+
* specified for the route that we're routing to).
|
|
210
225
|
*
|
|
211
226
|
* @default true
|
|
212
227
|
*/
|
|
213
|
-
|
|
228
|
+
reuseComponent?: false,
|
|
229
|
+
/**
|
|
230
|
+
* Whether the page should be kept alive when navigating away. Can be useful
|
|
231
|
+
* for a homepage where the state should be fully retained when navigating back
|
|
232
|
+
* from a details page
|
|
233
|
+
*
|
|
234
|
+
* @default false
|
|
235
|
+
*/
|
|
236
|
+
keepAlive?: true
|
|
214
237
|
}
|
|
238
|
+
export type RouteOptions = ConcurrentRouteOpts & MutualExclusiveRouteOpts;
|
|
215
239
|
|
|
216
240
|
export interface Router {
|
|
217
241
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightningjs/blits",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
4
4
|
"description": "Blits: The Lightning 3 App Development Framework",
|
|
5
5
|
"bin": "bin/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"prepublishOnly": "node scripts/prepublishOnly.js",
|
|
22
22
|
"postpublish": "node scripts/postpublish.js",
|
|
23
23
|
"prepare": "husky",
|
|
24
|
-
"pack-preview": "npm pack --dry-run"
|
|
24
|
+
"pack-preview": "npm pack --dry-run",
|
|
25
|
+
"release": "npm publish --access public"
|
|
25
26
|
},
|
|
26
27
|
"types": "./index.d.ts",
|
|
27
28
|
"lint-staged": {
|
package/src/router/router.js
CHANGED
|
@@ -176,7 +176,7 @@ export const matchHash = (path, routes = []) => {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
if (matchingRoute) {
|
|
179
|
-
matchingRoute.options = { ...matchingRoute.options, ...overrideOptions }
|
|
179
|
+
matchingRoute.options = { ...defaultOptions, ...matchingRoute.options, ...overrideOptions }
|
|
180
180
|
if (!matchingRoute.data) {
|
|
181
181
|
matchingRoute.data = {}
|
|
182
182
|
}
|
|
@@ -186,6 +186,17 @@ export const matchHash = (path, routes = []) => {
|
|
|
186
186
|
return matchingRoute
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Default Route options
|
|
191
|
+
*
|
|
192
|
+
*/
|
|
193
|
+
const defaultOptions = {
|
|
194
|
+
inHistory: true,
|
|
195
|
+
keepAlive: false,
|
|
196
|
+
passFocus: true,
|
|
197
|
+
reuseComponent: false,
|
|
198
|
+
}
|
|
199
|
+
|
|
189
200
|
/**
|
|
190
201
|
* Navigate to a route
|
|
191
202
|
*
|
|
@@ -202,12 +213,14 @@ export const navigate = async function () {
|
|
|
202
213
|
Announcer.stop()
|
|
203
214
|
Announcer.clear()
|
|
204
215
|
state.navigating = true
|
|
216
|
+
let reuse = false
|
|
205
217
|
if (this.parent[symbols.routes]) {
|
|
206
218
|
let previousRoute = currentRoute //? Object.assign({}, currentRoute) : undefined
|
|
207
219
|
const { hash, path, queryParams } = getHash()
|
|
208
220
|
let route = matchHash(path, this.parent[symbols.routes])
|
|
209
221
|
|
|
210
222
|
currentRoute = route
|
|
223
|
+
|
|
211
224
|
if (route) {
|
|
212
225
|
const queryParamsData = {}
|
|
213
226
|
const queryParamsEntries = [...queryParams.entries()]
|
|
@@ -271,6 +284,26 @@ export const navigate = async function () {
|
|
|
271
284
|
|
|
272
285
|
let { view, focus } = cacheMap.get(route.hash) || {}
|
|
273
286
|
|
|
287
|
+
// merge props with potential route params, navigation data and route data to be injected into the component instance
|
|
288
|
+
const props = {
|
|
289
|
+
...this[symbols.props],
|
|
290
|
+
...route.params,
|
|
291
|
+
...route.data,
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (
|
|
295
|
+
previousRoute &&
|
|
296
|
+
route.component === previousRoute.component &&
|
|
297
|
+
route.options.reuseComponent === true &&
|
|
298
|
+
route.options.keepAlive !== true
|
|
299
|
+
) {
|
|
300
|
+
reuse = true
|
|
301
|
+
view = this[symbols.children][this[symbols.children].length - 1]
|
|
302
|
+
for (const prop in props) {
|
|
303
|
+
view[symbols.props][prop] = props[prop]
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
274
307
|
// Announce route change if a message has been specified for this route
|
|
275
308
|
if (route.announce) {
|
|
276
309
|
if (typeof route.announce === 'string') {
|
|
@@ -288,13 +321,6 @@ export const navigate = async function () {
|
|
|
288
321
|
holder.set('w', '100%')
|
|
289
322
|
holder.set('h', '100%')
|
|
290
323
|
|
|
291
|
-
// merge props with potential route params, navigation data and route data to be injected into the component instance
|
|
292
|
-
const props = {
|
|
293
|
-
...this[symbols.props],
|
|
294
|
-
...route.params,
|
|
295
|
-
...route.data,
|
|
296
|
-
}
|
|
297
|
-
|
|
298
324
|
view = await route.component({ props }, holder, this)
|
|
299
325
|
|
|
300
326
|
if (view[Symbol.toStringTag] === 'Module') {
|
|
@@ -359,7 +385,7 @@ export const navigate = async function () {
|
|
|
359
385
|
let shouldAnimate = false
|
|
360
386
|
|
|
361
387
|
// apply out out transition on previous view
|
|
362
|
-
if (previousRoute) {
|
|
388
|
+
if (previousRoute && reuse === false) {
|
|
363
389
|
// only animate when there is a previous route
|
|
364
390
|
shouldAnimate = true
|
|
365
391
|
const oldView = this[symbols.children].splice(1, 1).pop()
|