@lightningjs/blits 0.9.4 → 0.9.6
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 +52 -38
- package/docs/components/utilities.md +0 -6
- package/package.json +2 -2
- package/src/application.d.ts +25 -0
- package/src/component.d.ts +27 -1
- package/src/component.js +32 -1
- package/src/components/Circle.js +27 -30
- package/src/components/Circle.orig.js +29 -3
- package/src/components/FPScounter.js +1024 -1078
- package/src/components/FPScounter.orig.js +1024 -41
- package/src/components/Image.js +18 -21
- package/src/components/Image.orig.js +20 -2
- package/src/components/RouterView.js +17 -20
- package/src/components/RouterView.orig.js +19 -3
- package/src/components/Sprite.js +23 -27
- package/src/components/Sprite.orig.js +25 -3
- package/src/components/Text.js +53 -57
- package/src/components/Text.orig.js +55 -21
- package/src/engines/L3/element.js +27 -28
- package/src/lib/codegenerator/generator.js +8 -5
- package/src/lib/lifecycle.js +11 -1
- package/src/lib/symbols.js +1 -0
- package/src/router/router.js +26 -8
package/src/router/router.js
CHANGED
|
@@ -46,6 +46,9 @@ const normalizePath = (path) => {
|
|
|
46
46
|
.toLowerCase()
|
|
47
47
|
)
|
|
48
48
|
}
|
|
49
|
+
const isObject = (v) => typeof v === 'object' && v !== null
|
|
50
|
+
|
|
51
|
+
const isString = (v) => typeof v === 'string'
|
|
49
52
|
|
|
50
53
|
export const matchHash = (path, routes = []) => {
|
|
51
54
|
// remove trailing slashes
|
|
@@ -57,6 +60,7 @@ export const matchHash = (path, routes = []) => {
|
|
|
57
60
|
const route = routes[i]
|
|
58
61
|
route.path = normalizePath(route.path)
|
|
59
62
|
if (route.path === path) {
|
|
63
|
+
route.params = {}
|
|
60
64
|
matchingRoute = route
|
|
61
65
|
} else if (route.path.indexOf(':') > -1) {
|
|
62
66
|
// match dynamic route parts
|
|
@@ -96,6 +100,9 @@ export const matchHash = (path, routes = []) => {
|
|
|
96
100
|
|
|
97
101
|
if (matchingRoute) {
|
|
98
102
|
matchingRoute.options = { ...matchingRoute.options, ...overrideOptions }
|
|
103
|
+
if (!matchingRoute.data) {
|
|
104
|
+
matchingRoute.data = {}
|
|
105
|
+
}
|
|
99
106
|
currentRoute = matchingRoute
|
|
100
107
|
}
|
|
101
108
|
|
|
@@ -107,9 +114,20 @@ export const navigate = async function () {
|
|
|
107
114
|
if (this.parent[symbols.routes]) {
|
|
108
115
|
const previousRoute = currentRoute
|
|
109
116
|
const hash = getHash()
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
let route = matchHash(hash, this.parent[symbols.routes])
|
|
118
|
+
let beforeHookOutput
|
|
112
119
|
if (route) {
|
|
120
|
+
if (route.hooks) {
|
|
121
|
+
if (route.hooks.before) {
|
|
122
|
+
beforeHookOutput = await route.hooks.before(route, previousRoute)
|
|
123
|
+
if (isString(beforeHookOutput)) {
|
|
124
|
+
currentRoute = previousRoute
|
|
125
|
+
to(beforeHookOutput)
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
route = isObject(beforeHookOutput) ? beforeHookOutput : route
|
|
113
131
|
// add the previous route (technically still the current route at this point)
|
|
114
132
|
// into the history stack, unless navigating back or inHistory flag of route is false
|
|
115
133
|
if (navigatingBack === false && previousRoute && previousRoute.options.inHistory === true) {
|
|
@@ -134,8 +152,8 @@ export const navigate = async function () {
|
|
|
134
152
|
holder.populate({})
|
|
135
153
|
holder.set('w', '100%')
|
|
136
154
|
holder.set('h', '100%')
|
|
137
|
-
// merge props with potential route params to be injected into the component instance
|
|
138
|
-
const props = { ...this[symbols.props], ...route.params, ...navigationData }
|
|
155
|
+
// merge props with potential route params, navigation data and route data to be injected into the component instance
|
|
156
|
+
const props = { ...this[symbols.props], ...route.params, ...navigationData, ...route.data }
|
|
139
157
|
|
|
140
158
|
view = await route.component({ props }, holder, this)
|
|
141
159
|
if (view[Symbol.toStringTag] === 'Module') {
|
|
@@ -149,7 +167,7 @@ export const navigate = async function () {
|
|
|
149
167
|
view = view({ props }, holder, this)
|
|
150
168
|
}
|
|
151
169
|
} else {
|
|
152
|
-
holder = view[symbols.
|
|
170
|
+
holder = view[symbols.holder]
|
|
153
171
|
}
|
|
154
172
|
|
|
155
173
|
this[symbols.children].push(view)
|
|
@@ -223,11 +241,11 @@ const removeView = async (route, view, transition) => {
|
|
|
223
241
|
if (Array.isArray(transition)) {
|
|
224
242
|
for (let i = 0; i < transition.length; i++) {
|
|
225
243
|
i === transition.length - 1
|
|
226
|
-
? await setOrAnimate(view[symbols.
|
|
227
|
-
: setOrAnimate(view[symbols.
|
|
244
|
+
? await setOrAnimate(view[symbols.holder], transition[i])
|
|
245
|
+
: setOrAnimate(view[symbols.holder], transition[i])
|
|
228
246
|
}
|
|
229
247
|
} else {
|
|
230
|
-
await setOrAnimate(view[symbols.
|
|
248
|
+
await setOrAnimate(view[symbols.holder], transition)
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
251
|
|