@lightningjs/blits 1.37.0 → 1.38.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/CHANGELOG.md +13 -0
- package/index.d.ts +33 -9
- package/package.json +3 -2
- package/src/component/base/events.js +2 -0
- package/src/component/base/methods.js +3 -0
- package/src/router/router.js +40 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.38.1
|
|
4
|
+
|
|
5
|
+
_28 Aug 2025_
|
|
6
|
+
|
|
7
|
+
- Added guard around emiting events and selecting elements after Component destroy
|
|
8
|
+
- Fixed issue with `navigatingBack`
|
|
9
|
+
|
|
10
|
+
## v1.38.0
|
|
11
|
+
|
|
12
|
+
_26 Aug 2025_
|
|
13
|
+
|
|
14
|
+
- Added `reuseComponent` to route options to enable navigating to the same page and reusing the same page component instance
|
|
15
|
+
|
|
3
16
|
## v1.37.0
|
|
4
17
|
|
|
5
18
|
_22 Aug 2025_
|
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.1",
|
|
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": {
|
|
@@ -31,6 +31,8 @@ export default {
|
|
|
31
31
|
*/
|
|
32
32
|
$emit: {
|
|
33
33
|
value: function (event, params, byReference = true) {
|
|
34
|
+
// early exit when component is marked as end of life
|
|
35
|
+
if (this.eol === true) return
|
|
34
36
|
// returning if all listeners executed
|
|
35
37
|
return eventListeners.executeListeners(event, params, byReference)
|
|
36
38
|
},
|
|
@@ -153,6 +153,9 @@ export default {
|
|
|
153
153
|
* @this {import('../../component').BlitsComponent}
|
|
154
154
|
*/
|
|
155
155
|
value: function (ref) {
|
|
156
|
+
// early exit when component is marked as end of life
|
|
157
|
+
if (this.eol === true) return
|
|
158
|
+
|
|
156
159
|
let selected = null
|
|
157
160
|
this[symbols.children].forEach((child) => {
|
|
158
161
|
if (Array.isArray(child)) {
|
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,12 +385,12 @@ 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()
|
|
366
392
|
if (oldView) {
|
|
367
|
-
removeView(previousRoute, oldView, route.transition.out)
|
|
393
|
+
removeView(previousRoute, oldView, route.transition.out, navigatingBack)
|
|
368
394
|
}
|
|
369
395
|
}
|
|
370
396
|
|
|
@@ -406,7 +432,7 @@ export const navigate = async function () {
|
|
|
406
432
|
* @param {BlitsComponent} view
|
|
407
433
|
* @param {Object} transition
|
|
408
434
|
*/
|
|
409
|
-
const removeView = async (route, view, transition) => {
|
|
435
|
+
const removeView = async (route, view, transition, navigatingBack) => {
|
|
410
436
|
// apply out transition
|
|
411
437
|
if (transition) {
|
|
412
438
|
if (Array.isArray(transition)) {
|
|
@@ -453,9 +479,10 @@ const setOrAnimate = (node, transition, shouldAnimate = true) => {
|
|
|
453
479
|
existingEndCallback = null
|
|
454
480
|
resolve()
|
|
455
481
|
}
|
|
456
|
-
node.set(transition.prop, { transition })
|
|
482
|
+
if (node !== undefined) node.set(transition.prop, { transition })
|
|
483
|
+
else resolve()
|
|
457
484
|
} else {
|
|
458
|
-
node.set(transition.prop, transition.value)
|
|
485
|
+
node !== undefined && node.set(transition.prop, transition.value)
|
|
459
486
|
resolve()
|
|
460
487
|
}
|
|
461
488
|
})
|