@lightningjs/blits 1.5.0 → 1.5.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 +10 -2
- package/docs/plugins/language.md +1 -1
- package/package.json +3 -2
- package/src/component/setup/props.js +8 -5
- package/src/component/setup/state.js +15 -6
- package/src/component.js +20 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## v1.5.1
|
|
5
|
+
|
|
6
|
+
_7 oct 2024_
|
|
7
|
+
|
|
8
|
+
- Added export of symbols
|
|
9
|
+
- Various small performance improvements related to component creation
|
|
10
|
+
|
|
3
11
|
## v1.5.0
|
|
4
12
|
|
|
5
13
|
_1 oct 2024_
|
|
6
14
|
|
|
7
|
-
- Fixed issue with
|
|
8
|
-
- Fixed issue with (incompatible) SDF text renderer being loaded when `renderMode` is set to
|
|
15
|
+
- Fixed issue with interrupting running / scheduled transitions with a new transition on the same prop
|
|
16
|
+
- Fixed issue with (incompatible) SDF text renderer being loaded when `renderMode` is set to canvas
|
|
9
17
|
- Added support for handling key release (i.e `keyup`) events
|
|
10
18
|
|
|
11
19
|
## v1.4.3
|
package/docs/plugins/language.md
CHANGED
|
@@ -121,7 +121,7 @@ Blits.Component('MyComponent', {
|
|
|
121
121
|
|
|
122
122
|
## Getting the current language
|
|
123
123
|
|
|
124
|
-
The current language can be retrieved via the `this.$
|
|
124
|
+
The current language can be retrieved via the `this.$languagelanguage` property. It will return the currently set language code.
|
|
125
125
|
|
|
126
126
|
## Translating
|
|
127
127
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightningjs/blits",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Blits: The Lightning 3 App Development Framework",
|
|
5
5
|
"bin": "bin/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"./vite": "./vite/index.js",
|
|
9
9
|
"./transitions": "./src/router/transitions/index.js",
|
|
10
10
|
"./precompiler": "./src/lib/precompiler/precompiler.js",
|
|
11
|
-
"./plugins": "./src/plugins/index.js"
|
|
11
|
+
"./plugins": "./src/plugins/index.js",
|
|
12
|
+
"./symbols": "./src/lib/symbols.js"
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
15
|
"test": "c8 npm run test:run",
|
|
@@ -29,20 +29,23 @@ export default (component, props = []) => {
|
|
|
29
29
|
props.push('ref')
|
|
30
30
|
}
|
|
31
31
|
component[symbols.propKeys] = []
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
|
|
33
|
+
const propsLength = props.length
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < propsLength; i++) {
|
|
36
|
+
const prop = { ...baseProp, ...(typeof props[i] === 'object' ? props[i] : { key: props[i] }) }
|
|
34
37
|
component[symbols.propKeys].push(prop.key)
|
|
35
38
|
Object.defineProperty(component, prop.key, {
|
|
36
39
|
get() {
|
|
37
40
|
const value = prop.cast(
|
|
38
|
-
this[symbols.props] && prop.key in this[symbols.props]
|
|
41
|
+
this[symbols.props] !== undefined && prop.key in this[symbols.props]
|
|
39
42
|
? this[symbols.props][prop.key]
|
|
40
43
|
: 'default' in prop
|
|
41
44
|
? prop.default
|
|
42
45
|
: undefined
|
|
43
46
|
)
|
|
44
47
|
|
|
45
|
-
if (prop.required && value === undefined) {
|
|
48
|
+
if (prop.required === true && value === undefined) {
|
|
46
49
|
Log.warn(`${prop.key} is required`)
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -53,5 +56,5 @@ export default (component, props = []) => {
|
|
|
53
56
|
this[symbols.props][prop.key] = v
|
|
54
57
|
},
|
|
55
58
|
})
|
|
56
|
-
}
|
|
59
|
+
}
|
|
57
60
|
}
|
|
@@ -27,13 +27,23 @@ export default (component, state = () => {}) => {
|
|
|
27
27
|
writable: false,
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
const stateKeys = Object.keys(state.apply(component) || {})
|
|
30
|
+
const stateKeys = Object.keys(state.apply(component) || {})
|
|
31
|
+
// add built-in hasFocus key
|
|
32
|
+
stateKeys.push(['hasFocus'])
|
|
33
|
+
const stateKeysLength = stateKeys.length
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
for (let i = 0; i < stateKeysLength; i++) {
|
|
36
|
+
const key = stateKeys[i]
|
|
37
|
+
if (
|
|
38
|
+
component[symbols.propKeys] !== undefined &&
|
|
39
|
+
component[symbols.propKeys].indexOf(key) > -1
|
|
40
|
+
) {
|
|
34
41
|
Log.error(`State ${key} already exists as a prop`)
|
|
35
42
|
}
|
|
36
|
-
if (
|
|
43
|
+
if (
|
|
44
|
+
component[symbols.methodKeys] !== undefined &&
|
|
45
|
+
component[symbols.methodKeys].indexOf(key) > -1
|
|
46
|
+
) {
|
|
37
47
|
Log.error(`State ${key} already exists as a method`)
|
|
38
48
|
}
|
|
39
49
|
component[symbols.stateKeys].push(key)
|
|
@@ -44,7 +54,6 @@ export default (component, state = () => {}) => {
|
|
|
44
54
|
set(v) {
|
|
45
55
|
this[symbols.state][key] = v
|
|
46
56
|
},
|
|
47
|
-
// enumerable: true,
|
|
48
57
|
})
|
|
49
|
-
}
|
|
58
|
+
}
|
|
50
59
|
}
|
package/src/component.js
CHANGED
|
@@ -51,7 +51,7 @@ const required = (name) => {
|
|
|
51
51
|
*
|
|
52
52
|
*/
|
|
53
53
|
const Component = (name = required('name'), config = required('config')) => {
|
|
54
|
-
let base
|
|
54
|
+
let base = undefined
|
|
55
55
|
|
|
56
56
|
const component = function (opts, parentEl, parentComponent, rootComponent) {
|
|
57
57
|
// generate a human readable ID for the component instance (i.e. Blits::ComponentName1)
|
|
@@ -89,11 +89,10 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
89
89
|
|
|
90
90
|
// apply the state function (passing in the this reference to utilize configured props)
|
|
91
91
|
// and store a reference to this original state
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
92
|
+
this[symbols.originalState] =
|
|
93
|
+
(config.state && typeof config.state === 'function' && config.state.apply(this)) || {}
|
|
94
|
+
// add hasFocus key in
|
|
95
|
+
this[symbols.originalState]['hasFocus'] = false
|
|
97
96
|
|
|
98
97
|
// generate a reactive state (using the result of previously execute state function)
|
|
99
98
|
// and store it
|
|
@@ -162,7 +161,6 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
162
161
|
// reactive bindings define in the template
|
|
163
162
|
const effects = config.code.effects
|
|
164
163
|
for (let i = 0; i < effects.length; i++) {
|
|
165
|
-
// console.log(config.code.effects[i].toString())
|
|
166
164
|
effect(() => {
|
|
167
165
|
effects[i](this, this[symbols.children], config, globalComponents, rootComponent, effect)
|
|
168
166
|
})
|
|
@@ -170,12 +168,14 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
170
168
|
|
|
171
169
|
// setup watchers if the components has watchers specified
|
|
172
170
|
if (this[symbols.watchers]) {
|
|
173
|
-
Object.keys(this[symbols.watchers])
|
|
171
|
+
const watcherkeys = Object.keys(this[symbols.watchers])
|
|
172
|
+
const watcherkeysLength = watcherkeys.length
|
|
173
|
+
for (let i = 0; i < watcherkeysLength; i++) {
|
|
174
174
|
let target = this
|
|
175
|
-
let key =
|
|
175
|
+
let key = watcherkeys[i]
|
|
176
176
|
// when dot notation used, find the nested target
|
|
177
|
-
if (
|
|
178
|
-
const keys =
|
|
177
|
+
if (key.indexOf('.') > -1) {
|
|
178
|
+
const keys = key.split('.')
|
|
179
179
|
key = keys.pop()
|
|
180
180
|
for (let i = 0; i < keys.length; i++) {
|
|
181
181
|
target = target[keys[i]]
|
|
@@ -187,23 +187,13 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
187
187
|
effect((force = false) => {
|
|
188
188
|
const newValue = target[key]
|
|
189
189
|
if (old !== newValue || force === true) {
|
|
190
|
-
this[symbols.watchers][
|
|
190
|
+
this[symbols.watchers][key].apply(this, [newValue, old])
|
|
191
191
|
old = newValue
|
|
192
192
|
}
|
|
193
193
|
})
|
|
194
|
-
}
|
|
194
|
+
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
// set all symbol based properties to non-enumerable and non-configurable
|
|
198
|
-
Object.getOwnPropertySymbols(this).forEach((property) => {
|
|
199
|
-
Object.defineProperties(this, {
|
|
200
|
-
[property]: {
|
|
201
|
-
enumerable: false,
|
|
202
|
-
configurable: false,
|
|
203
|
-
},
|
|
204
|
-
})
|
|
205
|
-
})
|
|
206
|
-
|
|
207
197
|
// finaly set the lifecycle state to ready (in the next tick)
|
|
208
198
|
setTimeout(() => (this.lifecycle.state = 'ready'))
|
|
209
199
|
|
|
@@ -214,7 +204,10 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
214
204
|
const factory = (options = {}, parentEl, parentComponent, rootComponent) => {
|
|
215
205
|
if (Base[symbols['launched']] === false) {
|
|
216
206
|
// Register user defined plugins once on the Base object (after launch)
|
|
217
|
-
Object.keys(plugins)
|
|
207
|
+
const pluginKeys = Object.keys(plugins)
|
|
208
|
+
const pluginKeysLength = pluginKeys.length
|
|
209
|
+
for (let i = 0; i < pluginKeysLength; i++) {
|
|
210
|
+
const pluginName = pluginKeys[i]
|
|
218
211
|
const prefixedPluginName = `$${pluginName}`
|
|
219
212
|
if (prefixedPluginName in Base) {
|
|
220
213
|
Log.warn(
|
|
@@ -231,7 +224,7 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
231
224
|
enumerable: true,
|
|
232
225
|
configurable: false,
|
|
233
226
|
})
|
|
234
|
-
}
|
|
227
|
+
}
|
|
235
228
|
|
|
236
229
|
// register global components once
|
|
237
230
|
globalComponents = components()
|
|
@@ -241,13 +234,13 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
241
234
|
}
|
|
242
235
|
|
|
243
236
|
// setup the component once per component type, using Base as the prototype
|
|
244
|
-
if (
|
|
237
|
+
if (base === undefined) {
|
|
245
238
|
Log.debug(`Setting up ${name} component`)
|
|
246
239
|
base = setupComponent(Object.create(Base), config)
|
|
247
240
|
}
|
|
248
241
|
|
|
249
242
|
// one time code generation (only if precompilation is turned off)
|
|
250
|
-
if (
|
|
243
|
+
if (config.code === undefined) {
|
|
251
244
|
Log.debug(`Generating code for ${name} component`)
|
|
252
245
|
config.code = codegenerator.call(config, parser(config.template, name))
|
|
253
246
|
}
|