material 0.9.10 → 0.9.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
4
4
  "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/class/view.js CHANGED
@@ -1,12 +1,32 @@
1
- import Control from './control'
1
+ import Component from './component'
2
+ import events from '../module/events'
2
3
 
3
- class View extends Control {
4
- static default = {
5
- base = 'view'
6
- }
4
+ class View extends Component {
5
+ static base = 'view'
7
6
 
8
7
  constructor (options) {
9
8
  super(options)
9
+ this.events = {}
10
+
11
+ if (this.options.events) {
12
+ events.attach(this.options.events, this)
13
+ }
14
+ }
15
+
16
+ on (event, listener) {
17
+ if (!this.events[event]) {
18
+ this.events[event] = []
19
+ }
20
+ this.events[event].push(listener)
21
+
22
+ return this
23
+ }
24
+
25
+ emit (event, ...args) {
26
+ if (this.events[event]) {
27
+ this.events[event].forEach(listener => listener.apply(this, args))
28
+ }
29
+ return this
10
30
  }
11
31
  }
12
32
 
@@ -104,7 +104,7 @@ export default {
104
104
  * [showSearch description]
105
105
  * @return {[type]} [description]
106
106
  */
107
- showSearch () {
107
+ showSearch (doNotEmpty) {
108
108
  if (this.hideFilter) {
109
109
  this.hideFilter()
110
110
  }
@@ -123,7 +123,7 @@ export default {
123
123
  this.ui['search-input'].focus()
124
124
  }
125
125
 
126
- this.ui.body.innerHTML = ''
126
+ if (!doNotEmpty) this.ui.body.innerHTML = ''
127
127
 
128
128
  // this.ui['search-list'].classList.add('show')
129
129
  // this.ui.body.classList.add('hide')
@@ -198,6 +198,21 @@ VirtualList.prototype.reset = function () {
198
198
  this.scroller.style.height = 0
199
199
  }
200
200
 
201
+ VirtualList.prototype.setCount = function (count) {
202
+ console.log('setCount', count)
203
+ this.count = count
204
+ const height = this.itemHeight * this.count
205
+
206
+ console.log('scroller height', height)
207
+ this.scroller.style.height = height + 'px'
208
+ }
209
+
210
+ VirtualList.prototype.getCount = function () {
211
+ // console.log('getCount')
212
+
213
+ return this.count
214
+ }
215
+
201
216
  VirtualList.prototype.setOffset = function (info) {
202
217
  // console.log('setOffset', info)
203
218
 
@@ -220,12 +235,6 @@ VirtualList.prototype.setOffset = function (info) {
220
235
  return size
221
236
  }
222
237
 
223
- VirtualList.prototype.getCount = function () {
224
- // console.log('getCount')
225
-
226
- return this.count
227
- }
228
-
229
238
  VirtualList.createScroller = function () {
230
239
  const scroller = document.createElement('div')
231
240
  scroller.classList.add('scroller')
@@ -0,0 +1,15 @@
1
+ // Recursively freeze an object to prevent mutation
2
+
3
+ const isObject = item => {
4
+ return item && typeof item === 'object' && !Array.isArray(item)
5
+ }
6
+
7
+ const freeze = obj => {
8
+ if (isObject(obj)) {
9
+ Object.freeze(obj)
10
+ Object.keys(obj).forEach(key => freeze(obj[key]))
11
+ }
12
+ return obj
13
+ }
14
+
15
+ export default freeze
@@ -1,4 +1,3 @@
1
-
2
1
  const is = (object) => {
3
2
  return object &&
4
3
  typeof object === 'object' &&
@@ -34,7 +34,6 @@
34
34
  // overscroll-behavior: none
35
35
  // height: 100%
36
36
  .item
37
- user-select: none
38
37
  width: 100%
39
38
  display: flex
40
39
  flex-direction: row
package/src/snackbar.js CHANGED
@@ -1,17 +1,13 @@
1
- // base class
2
- import EventEmitter from './mixin/emitter'
3
- // related modules
4
- import build from './mixin/build'
5
- import events from './module/events'
1
+ import Control from './class/control'
6
2
  import display from './mixin/display'
7
- // ui element
8
3
  import Element from './element'
9
4
  import Text from './text'
10
5
  import Button from './button'
11
6
 
12
- class Snackbar extends EventEmitter {
7
+ class Snackbar extends Control {
13
8
  static defaults = {
14
9
  class: 'snackbar',
10
+ mixins: [display],
15
11
  transition: 225,
16
12
  duration: 4000,
17
13
  stack: false,
@@ -30,12 +26,9 @@ class Snackbar extends EventEmitter {
30
26
  }
31
27
 
32
28
  constructor (options) {
33
- super()
34
-
29
+ super(options)
35
30
  this.init(options)
36
- this.build(this.constructor)
37
31
  this.render()
38
- events.attach(this.options.events, this)
39
32
  this.show()
40
33
 
41
34
  if (this.options.duration) {
@@ -46,19 +39,12 @@ class Snackbar extends EventEmitter {
46
39
  }
47
40
 
48
41
  init (options) {
49
- this.options = Object.assign({}, Snackbar.defaults, options || {})
50
- Object.assign(this, build, display)
51
-
52
42
  this.buildSnackbarContainer(this.options.container)
53
43
  }
54
44
 
55
45
  buildSnackbarContainer (container = document.body) {
56
- // console.log('buildSnackbarContainer', container)
57
-
58
46
  const snackbarContainer = container.querySelector('.snackbars')
59
47
 
60
- // console.log('snackbarContainer', snackbarContainer)
61
-
62
48
  if (!snackbarContainer) {
63
49
  this.options.container = document.createElement('div')
64
50
  this.options.container.classList.add('snackbars')
@@ -67,31 +53,46 @@ class Snackbar extends EventEmitter {
67
53
  if (this.options.stack === false) snackbarContainer.innerHTML = ''
68
54
  this.options.container = snackbarContainer
69
55
  }
56
+
57
+ this.options.container.appendChild(this.element)
70
58
  }
71
59
 
72
60
  render () {
73
- this.ui.message.set(this.options.message)
61
+ if (!this.ui) {
62
+ console.error('UI elements not initialized properly.')
63
+ return
64
+ }
65
+
66
+ const { message, callback, close, action } = this.ui
67
+
68
+ if (message) {
69
+ message.set(this.options.message)
70
+ } else {
71
+ console.error('Message UI element not initialized.')
72
+ }
74
73
 
75
- if (this.options.action) {
76
- this.ui.callback.set(this.options.action)
77
- this.ui.callback.element.classList.add('show')
78
- this.ui.action.classList.add('show')
74
+ if (this.options.action && callback && callback.element) {
75
+ callback.set(this.options.action)
76
+ callback.element.classList.add('show')
77
+ if (action) {
78
+ action.classList.add('show')
79
+ }
79
80
  }
80
81
 
81
- if (this.options.close) {
82
- this.ui.close.element.classList.add('show')
83
- this.ui.action.classList.add('show')
82
+ if (this.options.close && close && close.element) {
83
+ close.element.classList.add('show')
84
+ if (action) {
85
+ action.classList.add('show')
86
+ }
84
87
  }
85
88
  }
86
89
 
87
90
  action () {
88
- // console.log('action')
89
91
  this.emit('action')
90
92
  this.destroy()
91
93
  }
92
94
 
93
95
  close () {
94
- // console.log('close')
95
96
  this.destroy()
96
97
  }
97
98
  }
package/src/switch.js CHANGED
@@ -110,7 +110,7 @@ class Switch extends EventEmitter {
110
110
  }
111
111
  break
112
112
  default:
113
- this.setValue(prop, value)
113
+ this.setValue(prop, silent)
114
114
  }
115
115
 
116
116
  return this