@lightningjs/blits 1.3.1 → 1.4.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 +21 -1
- package/docs/_sidebar.md +3 -0
- package/docs/components/utility_methods.md +280 -0
- package/docs/plugins/global_app_state.md +77 -0
- package/docs/plugins/theme.md +176 -0
- package/docs/sidebar.json +12 -0
- package/package.json +2 -2
- package/src/component/base/events.js +4 -3
- package/src/component/base/methods.js +31 -4
- package/src/component.d.ts +15 -1
- package/src/component.js +17 -4
- package/src/components/Layout.js +1 -1
- package/src/components/Layout.orig.js +1 -1
- package/src/components/RouterView.js +1 -1
- package/src/components/RouterView.orig.js +1 -1
- package/src/engines/L3/element.js +27 -0
- package/src/engines/L3/element.test.js +112 -0
- package/src/engines/L3/launch.js +13 -11
- package/src/lib/codegenerator/generator.js +9 -0
- package/src/lib/eventListeners.js +42 -16
- package/src/lib/eventListeners.test.js +185 -0
- package/src/plugin.js +3 -4
- package/src/plugins/appstate.js +25 -0
- package/src/plugins/index.js +2 -0
- package/src/plugins/theme.js +88 -0
- package/docs/components/utilities.md +0 -3
package/src/plugin.js
CHANGED
|
@@ -7,21 +7,20 @@ export const plugins = {
|
|
|
7
7
|
|
|
8
8
|
const registerPlugin = (plugin, nameOrOptions = '', options = {}) => {
|
|
9
9
|
// map name and options depending on the arguments provided
|
|
10
|
-
let name
|
|
10
|
+
let name = undefined
|
|
11
11
|
if (typeof nameOrOptions === 'object') {
|
|
12
12
|
options = nameOrOptions
|
|
13
|
-
name = ''
|
|
14
13
|
} else {
|
|
15
14
|
name = nameOrOptions
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
if (typeof plugin === 'function') {
|
|
19
|
-
if (name ===
|
|
18
|
+
if (name === undefined) {
|
|
20
19
|
throw Error('Error registering plugin: name is required for plugin')
|
|
21
20
|
}
|
|
22
21
|
plugins[name] = { plugin, options }
|
|
23
22
|
} else if (plugin.plugin) {
|
|
24
|
-
registerPlugin(plugin.plugin, plugin.name, options)
|
|
23
|
+
registerPlugin(plugin.plugin, name || plugin.name, options)
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Comcast Cable Communications Management, LLC
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { reactive } from '../lib/reactivity/reactive'
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
name: 'appState',
|
|
22
|
+
plugin(state = {}) {
|
|
23
|
+
return reactive(state)
|
|
24
|
+
},
|
|
25
|
+
}
|
package/src/plugins/index.js
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Comcast Cable Communications Management, LLC
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Log } from '../lib/log'
|
|
19
|
+
import { reactive } from '../lib/reactivity/reactive.js'
|
|
20
|
+
|
|
21
|
+
const getValueByDotNotation = (obj, base, path) => {
|
|
22
|
+
const keys = path.split('.')
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < keys.length; i++) {
|
|
25
|
+
const key = keys[i]
|
|
26
|
+
|
|
27
|
+
if (obj !== null && key in obj === true) {
|
|
28
|
+
obj = obj[key]
|
|
29
|
+
base = base !== null && key in base === true ? base[key] : null
|
|
30
|
+
}
|
|
31
|
+
// see if the key is present in the base object
|
|
32
|
+
else if (base !== null && key in base === true) {
|
|
33
|
+
base = base[key]
|
|
34
|
+
obj = base
|
|
35
|
+
} else {
|
|
36
|
+
obj = undefined
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return obj
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default {
|
|
45
|
+
name: 'theme',
|
|
46
|
+
plugin(config = {}) {
|
|
47
|
+
let themeMap = {}
|
|
48
|
+
|
|
49
|
+
const state = reactive({
|
|
50
|
+
current: 'default',
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
let themes = {}
|
|
54
|
+
let base = null
|
|
55
|
+
if ('themes' in config === true) {
|
|
56
|
+
themes = config.themes
|
|
57
|
+
state.current = config.current || 'default'
|
|
58
|
+
base = config.base || 'default'
|
|
59
|
+
} else {
|
|
60
|
+
themes = { default: config }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
get(key, fallback) {
|
|
65
|
+
// reference state.current, to trigger reactive effects for
|
|
66
|
+
// theme get function when current theme is modified
|
|
67
|
+
state.current
|
|
68
|
+
if (themeMap[key] !== undefined) return themeMap[key]
|
|
69
|
+
const value = getValueByDotNotation(themes[state.current], themes[base], key)
|
|
70
|
+
if (value !== undefined) {
|
|
71
|
+
// store the value for next time
|
|
72
|
+
themeMap[key] = value
|
|
73
|
+
return value
|
|
74
|
+
}
|
|
75
|
+
return fallback
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
set(theme) {
|
|
79
|
+
if (theme in themes) {
|
|
80
|
+
themeMap = {}
|
|
81
|
+
state.current = theme
|
|
82
|
+
} else {
|
|
83
|
+
Log.warn(`Theme ${theme} not found`)
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
}
|