@lightningjs/blits 0.5.8 → 0.5.9

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 CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  # v0.5.8
4
4
 
5
+ _21 dec 2023_
6
+
7
+ - Changed transition-end callback to receive real prop value from node
8
+ - Implemented symbol for `wrapper` on Component (freeing up the name wrapper to be used in Component state)
9
+ - Added functionality to prevent a route ending up in the history stack (route option: `inHistory: false`)
10
+ - Improved router backtracking logic
11
+ - Added functionality to override route options during navigation
12
+ - Upgraded to latest version of the renderer (0.6.1) which contains a fix for animations not finishing correctly
13
+
14
+ # v0.5.8
15
+
5
16
  _15 dec 2023_
6
17
 
7
18
  - Internal refactor of the `Element`
@@ -31,6 +31,6 @@
31
31
  "vite": "^4.0.4"
32
32
  },
33
33
  "dependencies": {
34
- "@lightningjs/blits": "^0.5.8"
34
+ "@lightningjs/blits": "^0.5.9"
35
35
  }
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.cjs",
6
6
  "exports": {
@@ -42,7 +42,7 @@
42
42
  "tape": "^5.5.0"
43
43
  },
44
44
  "dependencies": {
45
- "@lightningjs/renderer": "^0.6.0",
45
+ "@lightningjs/renderer": "^0.6.1",
46
46
  "@lightningjs/vite-plugin-import-chunk-url": "^0.3.0"
47
47
  }
48
48
  }
package/src/component.js CHANGED
@@ -121,7 +121,7 @@ const Component = (name = required('name'), config = required('config')) => {
121
121
  }
122
122
 
123
123
  this.parent = parentComponent
124
- this.wrapper = parentEl
124
+ this[symbols.wrapper] = parentEl
125
125
 
126
126
  Object.defineProperties(this, {
127
127
  type: {
package/src/element.js CHANGED
@@ -317,7 +317,7 @@ const Element = {
317
317
  // fire transition end callback if specified
318
318
  transition.end &&
319
319
  typeof transition.end === 'function' &&
320
- transition.end.call(this.component, this, prop, props[prop])
320
+ transition.end.call(this.component, this, prop, this.node[prop])
321
321
  })
322
322
  .then(resolve)
323
323
  } catch (e) {
@@ -21,6 +21,17 @@ export default (component, routes) => {
21
21
  component.prototype[symbols.routes] = []
22
22
  Object.keys(routes).forEach((key) => {
23
23
  // todo: validate routes[key] for expected format etc.
24
- component.prototype[symbols.routes][key] = routes[key]
24
+ component.prototype[symbols.routes][key] = {
25
+ ...routes[key],
26
+ ...{
27
+ // merge default route options with route specific options
28
+ options: {
29
+ ...{
30
+ inHistory: true,
31
+ },
32
+ ...routes[key].options,
33
+ },
34
+ },
35
+ }
25
36
  })
26
37
  }
@@ -23,6 +23,7 @@ export default {
23
23
  type: Symbol('type'),
24
24
  watchers: Symbol('watchers'),
25
25
  watchKeys: Symbol('watchKeys'),
26
+ wrapper: Symbol('wrapper'),
26
27
 
27
28
  /* Utilizing the global Symbol registry for the following purposes */
28
29
 
@@ -27,6 +27,8 @@ export let navigating = false
27
27
 
28
28
  const cacheMap = new WeakMap()
29
29
  const history = []
30
+ let overrideOptions = {}
31
+ let navigatingBack = false
30
32
 
31
33
  export const getHash = () => {
32
34
  return (document.location.hash || '/').replace(/^#/, '')
@@ -38,7 +40,10 @@ export const matchHash = (path, routes = []) => {
38
40
  return r.path === path
39
41
  })
40
42
  .pop()
41
- if (route) currentRoute = route
43
+ if (route) {
44
+ route.options = { ...route.options, ...overrideOptions }
45
+ currentRoute = route
46
+ }
42
47
  return route
43
48
  }
44
49
 
@@ -50,7 +55,11 @@ export const navigate = async function () {
50
55
  const route = matchHash(hash, this.parent[symbols.routes])
51
56
 
52
57
  if (route) {
53
- if (history[history.length - 1] !== hash) history.push(hash)
58
+ // add the previous route (tecnhically still the current route at this point)
59
+ // into the history stack, unless navigating back or inHistory flag of route is false
60
+ if (navigatingBack === false && previousRoute && previousRoute.options.inHistory === true) {
61
+ history.push(previousRoute)
62
+ }
54
63
  // apply default transition if none specified
55
64
  if (!('transition' in route)) {
56
65
  route.transition = fadeInFadeOutTransition
@@ -82,7 +91,7 @@ export const navigate = async function () {
82
91
  view = view(this[symbols.props], holder, this)
83
92
  }
84
93
  } else {
85
- holder = view.wrapper
94
+ holder = view[symbols.wrapper]
86
95
  }
87
96
 
88
97
  this[symbols.children].push(view)
@@ -130,6 +139,9 @@ export const navigate = async function () {
130
139
  Log.error(`Route ${hash} not found`)
131
140
  }
132
141
  }
142
+
143
+ // reset navigating indicators
144
+ navigatingBack = false
133
145
  navigating = false
134
146
  }
135
147
 
@@ -139,11 +151,11 @@ const removeView = async (route, view, transition) => {
139
151
  if (Array.isArray(transition)) {
140
152
  for (let i = 0; i < transition.length; i++) {
141
153
  i === transition.length - 1
142
- ? await setOrAnimate(view.wrapper, transition[i])
143
- : setOrAnimate(view.wrapper, transition[i])
154
+ ? await setOrAnimate(view[symbols.wrapper], transition[i])
155
+ : setOrAnimate(view[symbols.wrapper], transition[i])
144
156
  }
145
157
  } else {
146
- await setOrAnimate(view.wrapper, transition)
158
+ await setOrAnimate(view[symbols.wrapper], transition)
147
159
  }
148
160
  }
149
161
 
@@ -169,14 +181,17 @@ const setOrAnimate = (node, transition, shouldAnimate = true) => {
169
181
  : node.set(transition.prop, transition.value)
170
182
  }
171
183
 
172
- export const to = (location) => {
184
+ export const to = (location, options = {}) => {
185
+ overrideOptions = options
173
186
  window.location.hash = `#${location}`
174
187
  }
175
188
 
176
189
  export const back = () => {
177
- if (history.length > 1) {
178
- to(history[history.length - 2])
179
- history.splice(-2, 2)
190
+ const route = history.pop()
191
+ if (route) {
192
+ // set indicator that we are navigating back (to prevent adding page to history stack)
193
+ navigatingBack = true
194
+ to(route.path)
180
195
  return true
181
196
  } else {
182
197
  return false