@lightningjs/blits 0.9.5 → 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.
@@ -19,29 +19,26 @@ import Component from '../component.js'
19
19
 
20
20
  export default () =>
21
21
  Component('Image', {
22
- /* eslint-disable no-unused-vars */
23
- code: {
24
- render: function anonymous(parent, component, context) {
25
- const elms = []
22
+ /* eslint-disable no-unused-vars */
23
+ code: { render: function anonymous(parent,component,context
24
+ ) {
25
+ const elms = []
26
26
 
27
- if (!elms[0]) {
28
- elms[0] = this.element({ parent: parent || 'root' }, component)
29
- }
30
- const elementConfig0 = {}
31
-
32
- if (!elms[0].nodeId) {
33
- elms[0].populate(elementConfig0)
34
- }
27
+ if(!elms[0]) {
28
+ elms[0] = this.element({parent: parent || 'root'}, component)
29
+ }
30
+ const elementConfig0 = {}
31
+
35
32
 
36
- return elms
37
- },
38
- effects: [
39
- function anonymous(component, elms, context) {
40
- elms[0].set('imageSource', component.imageSource)
41
- },
42
- ],
43
- context: {},
44
- },
33
+ if(!elms[0].nodeId) {
34
+ elms[0].populate(elementConfig0)
35
+ }
36
+
37
+ return elms
38
+ }, effects: [function anonymous(component,elms,context
39
+ ) {
40
+ elms[0].set('imageSource', component.imageSource)
41
+ }], context: {}},
45
42
  props: ['src'],
46
43
  computed: {
47
44
  imageSource() {
@@ -19,8 +19,26 @@ import Component from '../component.js'
19
19
 
20
20
  export default () =>
21
21
  Component('Image', {
22
- template: `
23
- <Element :imageSource="$imageSource" />`,
22
+ /* eslint-disable no-unused-vars */
23
+ code: { render: function anonymous(parent,component,context
24
+ ) {
25
+ const elms = []
26
+
27
+ if(!elms[0]) {
28
+ elms[0] = this.element({parent: parent || 'root'}, component)
29
+ }
30
+ const elementConfig0 = {}
31
+
32
+
33
+ if(!elms[0].nodeId) {
34
+ elms[0].populate(elementConfig0)
35
+ }
36
+
37
+ return elms
38
+ }, effects: [function anonymous(component,elms,context
39
+ ) {
40
+ elms[0].set('imageSource', component.imageSource)
41
+ }], context: {}},
24
42
  props: ['src'],
25
43
  computed: {
26
44
  imageSource() {
@@ -22,28 +22,25 @@ let handler
22
22
 
23
23
  export default () =>
24
24
  Component('RouterView', {
25
- /* eslint-disable no-unused-vars */
26
- code: {
27
- render: function anonymous(parent, component, context) {
28
- const elms = []
25
+ /* eslint-disable no-unused-vars */
26
+ code: { render: function anonymous(parent,component,context
27
+ ) {
28
+ const elms = []
29
29
 
30
- if (!elms[0]) {
31
- elms[0] = this.element({ parent: parent || 'root' }, component)
32
- }
33
- const elementConfig0 = {}
30
+ if(!elms[0]) {
31
+ elms[0] = this.element({parent: parent || 'root'}, component)
32
+ }
33
+ const elementConfig0 = {}
34
+
35
+ elementConfig0['w'] = parent.node.width * (100 / 100)
36
+ elementConfig0['height'] = parent.node.height * (100 / 100)
34
37
 
35
- elementConfig0['w'] = parent.node.width * (100 / 100)
36
- elementConfig0['height'] = parent.node.height * (100 / 100)
37
-
38
- if (!elms[0].nodeId) {
39
- elms[0].populate(elementConfig0)
40
- }
41
-
42
- return elms
43
- },
44
- effects: [],
45
- context: {},
46
- },
38
+ if(!elms[0].nodeId) {
39
+ elms[0].populate(elementConfig0)
40
+ }
41
+
42
+ return elms
43
+ }, effects: [], context: {}},
47
44
  state() {
48
45
  return {
49
46
  activeView: null,
@@ -22,9 +22,25 @@ let handler
22
22
 
23
23
  export default () =>
24
24
  Component('RouterView', {
25
- template: `
26
- <Element w="100%" height="100%"></Element>
27
- `,
25
+ /* eslint-disable no-unused-vars */
26
+ code: { render: function anonymous(parent,component,context
27
+ ) {
28
+ const elms = []
29
+
30
+ if(!elms[0]) {
31
+ elms[0] = this.element({parent: parent || 'root'}, component)
32
+ }
33
+ const elementConfig0 = {}
34
+
35
+ elementConfig0['w'] = parent.node.width * (100 / 100)
36
+ elementConfig0['height'] = parent.node.height * (100 / 100)
37
+
38
+ if(!elms[0].nodeId) {
39
+ elms[0].populate(elementConfig0)
40
+ }
41
+
42
+ return elms
43
+ }, effects: [], context: {}},
28
44
  state() {
29
45
  return {
30
46
  activeView: null,
@@ -21,35 +21,31 @@ import symbols from '../lib/symbols.js'
21
21
 
22
22
  export default () =>
23
23
  Component('Sprite', {
24
- /* eslint-disable no-unused-vars */
25
- code: {
26
- render: function anonymous(parent, component, context) {
27
- const elms = []
24
+ /* eslint-disable no-unused-vars */
25
+ code: { render: function anonymous(parent,component,context
26
+ ) {
27
+ const elms = []
28
28
 
29
- if (!elms[0]) {
30
- elms[0] = this.element({ parent: parent || 'root' }, component)
31
- }
32
- const elementConfig0 = {}
33
-
34
- elementConfig0['w'] = parent.node.width * (100 / 100)
35
- elementConfig0['h'] = parent.node.height * (100 / 100)
36
-
37
- if (!elms[0].nodeId) {
38
- elms[0].populate(elementConfig0)
39
- }
29
+ if(!elms[0]) {
30
+ elms[0] = this.element({parent: parent || 'root'}, component)
31
+ }
32
+ const elementConfig0 = {}
33
+
34
+ elementConfig0['w'] = parent.node.width * (100 / 100)
35
+ elementConfig0['h'] = parent.node.height * (100 / 100)
40
36
 
41
- return elms
42
- },
43
- effects: [
44
- function anonymous(component, elms, context) {
45
- elms[0].set('texture', component.texture)
46
- },
47
- function anonymous(component, elms, context) {
48
- elms[0].set('color', component.color)
49
- },
50
- ],
51
- context: {},
52
- },
37
+ if(!elms[0].nodeId) {
38
+ elms[0].populate(elementConfig0)
39
+ }
40
+
41
+ return elms
42
+ }, effects: [function anonymous(component,elms,context
43
+ ) {
44
+ elms[0].set('texture', component.texture)
45
+ },function anonymous(component,elms,context
46
+ ) {
47
+ elms[0].set('color', component.color)
48
+ }], context: {}},
53
49
  props: ['image', 'map', 'frame', 'color'],
54
50
  state() {
55
51
  return {
@@ -21,9 +21,31 @@ import symbols from '../lib/symbols.js'
21
21
 
22
22
  export default () =>
23
23
  Component('Sprite', {
24
- template: `
25
- <Element w="100%" h="100%" :texture="$texture" :color="$color" />
26
- `,
24
+ /* eslint-disable no-unused-vars */
25
+ code: { render: function anonymous(parent,component,context
26
+ ) {
27
+ const elms = []
28
+
29
+ if(!elms[0]) {
30
+ elms[0] = this.element({parent: parent || 'root'}, component)
31
+ }
32
+ const elementConfig0 = {}
33
+
34
+ elementConfig0['w'] = parent.node.width * (100 / 100)
35
+ elementConfig0['h'] = parent.node.height * (100 / 100)
36
+
37
+ if(!elms[0].nodeId) {
38
+ elms[0].populate(elementConfig0)
39
+ }
40
+
41
+ return elms
42
+ }, effects: [function anonymous(component,elms,context
43
+ ) {
44
+ elms[0].set('texture', component.texture)
45
+ },function anonymous(component,elms,context
46
+ ) {
47
+ elms[0].set('color', component.color)
48
+ }], context: {}},
27
49
  props: ['image', 'map', 'frame', 'color'],
28
50
  state() {
29
51
  return {
@@ -20,65 +20,61 @@ import Settings from '../settings.js'
20
20
 
21
21
  export default () =>
22
22
  Component('Text', {
23
- /* eslint-disable no-unused-vars */
24
- code: {
25
- render: function anonymous(parent, component, context) {
26
- const elms = []
23
+ /* eslint-disable no-unused-vars */
24
+ code: { render: function anonymous(parent,component,context
25
+ ) {
26
+ const elms = []
27
27
 
28
- if (!elms[0]) {
29
- elms[0] = this.element({ parent: parent || 'root' }, component)
30
- }
31
- const elementConfig0 = {}
28
+ if(!elms[0]) {
29
+ elms[0] = this.element({parent: parent || 'root'}, component)
30
+ }
31
+ const elementConfig0 = {}
32
+
33
+ elementConfig0['__textnode'] = true
34
+ elementConfig0['fontFamily'] = component.font
35
+ elementConfig0['letterSpacing'] = component.letterspacing
36
+ elementConfig0['lineHeight'] = component._lineheight
37
+ elementConfig0['stretch'] = component.stretch
38
+ elementConfig0['contain'] = component._contain
39
+ elementConfig0['@loaded'] = component['@loaded'] && component['@loaded'].bind(component)
40
+ elementConfig0['@error'] = component['@error'] && component['@error'].bind(component)
32
41
 
33
- elementConfig0['__textnode'] = true
34
- elementConfig0['fontFamily'] = component.font
35
- elementConfig0['letterSpacing'] = component.letterspacing
36
- elementConfig0['lineHeight'] = component._lineheight
37
- elementConfig0['stretch'] = component.stretch
38
- elementConfig0['contain'] = component._contain
39
- elementConfig0['@loaded'] = component['@loaded'] && component['@loaded'].bind(component)
40
- elementConfig0['@error'] = component['@error'] && component['@error'].bind(component)
41
-
42
- if (!elms[0].nodeId) {
43
- elms[0].populate(elementConfig0)
44
- }
45
-
46
- return elms
47
- },
48
- effects: [
49
- function anonymous(component, elms, context) {
50
- elms[0].set('text', component.content)
51
- },
52
- function anonymous(component, elms, context) {
53
- elms[0].set('fontSize', component.size)
54
- },
55
- function anonymous(component, elms, context) {
56
- elms[0].set('color', component.color)
57
- },
58
- function anonymous(component, elms, context) {
59
- elms[0].set('style', component.style)
60
- },
61
- function anonymous(component, elms, context) {
62
- elms[0].set('weight', component.weight)
63
- },
64
- function anonymous(component, elms, context) {
65
- elms[0].set('wordWrap', component.wordwrap)
66
- },
67
- function anonymous(component, elms, context) {
68
- elms[0].set('maxLines', component.maxlines)
69
- },
70
- function anonymous(component, elms, context) {
71
- elms[0].set('h', component.maxheight)
72
- },
73
- function anonymous(component, elms, context) {
74
- elms[0].set('textAlign', component.align)
75
- },
76
- function anonymous(component, elms, context) {
77
- elms[0].set('overflowSuffix', component.textoverflow)
78
- },
79
- ],
80
- context: {},
81
- },
42
+ if(!elms[0].nodeId) {
43
+ elms[0].populate(elementConfig0)
44
+ }
45
+
46
+ return elms
47
+ }, effects: [function anonymous(component,elms,context
48
+ ) {
49
+ elms[0].set('text', component.content)
50
+ },function anonymous(component,elms,context
51
+ ) {
52
+ elms[0].set('fontSize', component.size)
53
+ },function anonymous(component,elms,context
54
+ ) {
55
+ elms[0].set('color', component.color)
56
+ },function anonymous(component,elms,context
57
+ ) {
58
+ elms[0].set('style', component.style)
59
+ },function anonymous(component,elms,context
60
+ ) {
61
+ elms[0].set('weight', component.weight)
62
+ },function anonymous(component,elms,context
63
+ ) {
64
+ elms[0].set('wordWrap', component.wordwrap)
65
+ },function anonymous(component,elms,context
66
+ ) {
67
+ elms[0].set('maxLines', component.maxlines)
68
+ },function anonymous(component,elms,context
69
+ ) {
70
+ elms[0].set('h', component.maxheight)
71
+ },function anonymous(component,elms,context
72
+ ) {
73
+ elms[0].set('textAlign', component.align)
74
+ },function anonymous(component,elms,context
75
+ ) {
76
+ elms[0].set('overflowSuffix', component.textoverflow)
77
+ }], context: {}},
82
78
  props: [
83
79
  'content',
84
80
  {
@@ -20,27 +20,61 @@ import Settings from '../settings.js'
20
20
 
21
21
  export default () =>
22
22
  Component('Text', {
23
- template: `
24
- <Element
25
- __textnode="true"
26
- :text="$content"
27
- fontFamily="$font"
28
- :fontSize="$size"
29
- :color="$color"
30
- :style="$style"
31
- :weight="$weight"
32
- letterSpacing="$letterspacing"
33
- lineHeight="$_lineheight"
34
- stretch="$stretch"
35
- contain="$_contain"
36
- :wordWrap="$wordwrap"
37
- :maxLines="$maxlines"
38
- :h="$maxheight"
39
- :textAlign="$align"
40
- :overflowSuffix="$textoverflow"
41
- @loaded="$@loaded"
42
- @error="$@error"
43
- />`,
23
+ /* eslint-disable no-unused-vars */
24
+ code: { render: function anonymous(parent,component,context
25
+ ) {
26
+ const elms = []
27
+
28
+ if(!elms[0]) {
29
+ elms[0] = this.element({parent: parent || 'root'}, component)
30
+ }
31
+ const elementConfig0 = {}
32
+
33
+ elementConfig0['__textnode'] = true
34
+ elementConfig0['fontFamily'] = component.font
35
+ elementConfig0['letterSpacing'] = component.letterspacing
36
+ elementConfig0['lineHeight'] = component._lineheight
37
+ elementConfig0['stretch'] = component.stretch
38
+ elementConfig0['contain'] = component._contain
39
+ elementConfig0['@loaded'] = component['@loaded'] && component['@loaded'].bind(component)
40
+ elementConfig0['@error'] = component['@error'] && component['@error'].bind(component)
41
+
42
+ if(!elms[0].nodeId) {
43
+ elms[0].populate(elementConfig0)
44
+ }
45
+
46
+ return elms
47
+ }, effects: [function anonymous(component,elms,context
48
+ ) {
49
+ elms[0].set('text', component.content)
50
+ },function anonymous(component,elms,context
51
+ ) {
52
+ elms[0].set('fontSize', component.size)
53
+ },function anonymous(component,elms,context
54
+ ) {
55
+ elms[0].set('color', component.color)
56
+ },function anonymous(component,elms,context
57
+ ) {
58
+ elms[0].set('style', component.style)
59
+ },function anonymous(component,elms,context
60
+ ) {
61
+ elms[0].set('weight', component.weight)
62
+ },function anonymous(component,elms,context
63
+ ) {
64
+ elms[0].set('wordWrap', component.wordwrap)
65
+ },function anonymous(component,elms,context
66
+ ) {
67
+ elms[0].set('maxLines', component.maxlines)
68
+ },function anonymous(component,elms,context
69
+ ) {
70
+ elms[0].set('h', component.maxheight)
71
+ },function anonymous(component,elms,context
72
+ ) {
73
+ elms[0].set('textAlign', component.align)
74
+ },function anonymous(component,elms,context
75
+ ) {
76
+ elms[0].set('overflowSuffix', component.textoverflow)
77
+ }], context: {}},
44
78
  props: [
45
79
  'content',
46
80
  {
@@ -218,7 +218,7 @@ const generateForLoopCode = function (templateObject, parent) {
218
218
  ctx.renderCode.push(`parent = ${parent}`)
219
219
  }
220
220
 
221
- const forCounter = counter
221
+ const forStartCounter = counter
222
222
 
223
223
  // reference all reactive attributes (except those referencing the iterator item),
224
224
  // to ensure that reactivity is registered, even when the initial array is empty
@@ -282,12 +282,15 @@ const generateForLoopCode = function (templateObject, parent) {
282
282
  ctx.renderCode = ctx.renderCode.concat(ctx.effectsCode)
283
283
  ctx.renderCode.push('}')
284
284
 
285
+ const forEndCounter = counter
285
286
  ctx.renderCode.push(`
286
- if(elms[${forCounter}]) {
287
- Object.keys(elms[${forCounter}]).forEach(key => {
287
+ if(elms[${forStartCounter}]) {
288
+ Object.keys(elms[${forStartCounter}]).forEach(key => {
288
289
  if(keys.indexOf(key) === -1) {
289
- elms[${forCounter}][key].destroy && elms[${forCounter}][key].destroy()
290
- delete elms[1][key]
290
+ for(let i=${forStartCounter}; i <= ${forEndCounter}; i++){
291
+ elms[i][key].destroy && elms[i][key].destroy()
292
+ delete elms[i][key]
293
+ }
291
294
  }
292
295
  })
293
296
  }
@@ -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
- const route = matchHash(hash, this.parent[symbols.routes])
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') {