material 0.6.1 → 0.7.0

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.
Files changed (87) hide show
  1. package/index.js +11 -2
  2. package/package.json +1 -1
  3. package/src/appbar.js +28 -28
  4. package/src/banner.js +20 -20
  5. package/src/button.js +18 -19
  6. package/src/calendar.js +8 -8
  7. package/src/card.js +4 -4
  8. package/src/checkbox.js +8 -8
  9. package/src/component.js +4 -4
  10. package/src/container.js +4 -4
  11. package/src/control/button.js +64 -88
  12. package/src/control/button.new.js +25 -25
  13. package/src/control/datehour.js +4 -4
  14. package/src/control/dialog.js +12 -11
  15. package/src/control/file.js +8 -8
  16. package/src/control/image.js +6 -6
  17. package/src/control/link.js +9 -9
  18. package/src/control/list.js +25 -35
  19. package/src/control/loading.js +10 -10
  20. package/src/control/menu.js +85 -0
  21. package/src/control/search.js +9 -9
  22. package/src/control/select.js +6 -6
  23. package/src/control/selecter.js +15 -15
  24. package/src/control/snackbar.js +91 -0
  25. package/src/control/switch.js +18 -18
  26. package/src/control/switcher.js +16 -16
  27. package/src/control/text.js +11 -7
  28. package/src/control/textfield.js +12 -12
  29. package/src/dialog.js +19 -19
  30. package/src/divider.js +4 -4
  31. package/src/drawer.js +11 -11
  32. package/src/element.js +6 -31
  33. package/src/field/email.js +5 -5
  34. package/src/field/image.js +4 -4
  35. package/src/form/build.js +7 -7
  36. package/src/form.js +6 -6
  37. package/src/icon.js +8 -8
  38. package/src/image.js +14 -14
  39. package/src/item.js +7 -7
  40. package/src/layout.js +10 -10
  41. package/src/list/add.js +1 -1
  42. package/src/list/build.js +7 -7
  43. package/src/list/display.js +10 -10
  44. package/src/list/search.js +2 -2
  45. package/src/list.js +13 -13
  46. package/src/map/build.js +6 -6
  47. package/src/map/display.js +8 -8
  48. package/src/menu.js +15 -15
  49. package/src/{component → mixin}/control.js +10 -10
  50. package/src/{component → mixin}/create.js +1 -1
  51. package/src/mixin/display.js +76 -0
  52. package/src/mixin/emitter.js +23 -0
  53. package/src/{component → mixin}/events.js +2 -2
  54. package/src/{component → mixin}/focus.js +2 -3
  55. package/src/{component → mixin}/insert.js +1 -1
  56. package/src/module/build.js +44 -0
  57. package/src/{component → module}/classify.js +0 -13
  58. package/src/module/dataset.js +12 -0
  59. package/src/module/dom.js +1 -57
  60. package/src/module/events.js +57 -0
  61. package/src/module/jsontohtml.js +20 -0
  62. package/src/module/last.js +0 -0
  63. package/src/{component → module}/ripple.js +15 -42
  64. package/src/progress.js +7 -7
  65. package/src/select.js +16 -16
  66. package/src/selector.js +32 -32
  67. package/src/skin/material/control/menu.sass +29 -0
  68. package/src/skin/material/control/snackbar.sass +65 -0
  69. package/src/slider.js +32 -32
  70. package/src/snackbar.js +8 -8
  71. package/src/switch.js +9 -9
  72. package/src/tabs.js +8 -8
  73. package/src/tabview.js +8 -8
  74. package/src/text.js +5 -5
  75. package/src/textfield.js +16 -16
  76. package/src/toolbar.js +28 -28
  77. package/src/tooltip.js +11 -11
  78. package/src/tree.js +12 -16
  79. package/src/view/build.js +7 -7
  80. package/src/view/display.js +16 -16
  81. package/src/view.js +5 -5
  82. package/src/component/click.js +0 -17
  83. /package/src/{component → mixin}/controller.js +0 -0
  84. /package/src/{component → mixin}/icon.js +0 -0
  85. /package/src/{component → mixin}/init.js +0 -0
  86. /package/src/{component → mixin}/label.js +0 -0
  87. /package/src/{component → mixin}/settings.js +0 -0
@@ -0,0 +1,76 @@
1
+ import dom from '../module/dom'
2
+
3
+ export default {
4
+ toggle () {
5
+ this.visible ? this.hide() : this.show()
6
+
7
+ this.emit?.('toggle')
8
+ return this
9
+ },
10
+
11
+ show () {
12
+ // console.log('show', this.visible)
13
+
14
+ // if (this.options.transition) {
15
+ // this.element.style.display = 'initial'
16
+ // }
17
+
18
+ this.element.getBoundingClientRect()
19
+
20
+ this.element.classList.add('show')
21
+ this.visible = true
22
+
23
+ if (this.underlay) {
24
+ this.underlay.classList.add('show')
25
+ }
26
+
27
+ this.emit?.('show')
28
+ return this
29
+ },
30
+
31
+ hide () {
32
+ // console.log('hide')
33
+ // if (this.element.style.display === 'none') return
34
+ // clearTimeout(this.displayTimeout)
35
+ // this._display = getComputedStyle(this.element).display
36
+
37
+ if (!this.element) return
38
+
39
+ this.element.classList.remove('show')
40
+ this.visible = false
41
+
42
+ if (this.underlay) {
43
+ this.underlay.classList.remove('show')
44
+ }
45
+
46
+ // if (this.options.transition) {
47
+ // this.displayTimeout = setTimeout(() => {
48
+ // console.log('display: none', this._display)
49
+ // this.element.style.display = 'none'
50
+ // }, this.options.transition)
51
+ // }
52
+
53
+ this.emit?.('hide')
54
+ return this
55
+ },
56
+
57
+ destroy () {
58
+ // console.log('destroy', this.options.transition, this.element)
59
+ if (this.options.transition && this.element) {
60
+ this.element.classList.remove('show')
61
+
62
+ if (this.underlay) {
63
+ this.underlay.classList.remove('show')
64
+ }
65
+
66
+ setTimeout(() => {
67
+ dom.destroy(this.element)
68
+ }, this.options.transition)
69
+ } else {
70
+ dom.destroy(this.element)
71
+ }
72
+
73
+
74
+ this.emit?.('destroy')
75
+ }
76
+ }
@@ -0,0 +1,23 @@
1
+ class EventEmitter {
2
+ constructor () {
3
+ this.events = {}
4
+ }
5
+
6
+ on (event, listener) {
7
+ if (!this.events[event]) {
8
+ this.events[event] = []
9
+ }
10
+ this.events[event].push(listener)
11
+
12
+ return this
13
+ }
14
+
15
+ emit (event, ...args) {
16
+ if (this.events[event]) {
17
+ this.events[event].forEach(listener => listener.apply(this, args))
18
+ }
19
+ return this
20
+ }
21
+ }
22
+
23
+ export default EventEmitter
@@ -6,7 +6,7 @@ export default {
6
6
  * @param {Function} fn [description]
7
7
  */
8
8
  addEvent (event, fn) {
9
- var element = this.root
9
+ var element = this.element
10
10
  // avoid memory overhead of new anonymous functions for every event handler that's installed
11
11
  // by using local functions
12
12
  function listenHandler (e) {
@@ -45,7 +45,7 @@ export default {
45
45
  * @return {Object} [description]
46
46
  */
47
47
  removeEvent (event, fn) {
48
- var element = this.root
48
+ var element = this.element
49
49
 
50
50
  if (element.removeEventListener) {
51
51
  element.removeEventListener(event, fn, false)
@@ -8,7 +8,7 @@ export default {
8
8
  focus () {
9
9
  if (this.disabled === true) return this
10
10
 
11
- css.add(this.root, 'is-focused')
11
+ css.add(this.element, 'is-focused')
12
12
  if (this.element.input !== document.activeElement) { this.element.input.focus() }
13
13
  return this
14
14
  },
@@ -18,8 +18,7 @@ export default {
18
18
  * @return {?} [description]
19
19
  */
20
20
  blur () {
21
- css.remove(this.root, 'is-focused')
21
+ css.remove(this.element, 'is-focused')
22
22
  return this
23
23
  }
24
24
  }
25
-
@@ -18,7 +18,7 @@ export default {
18
18
  * @return {?} [description]
19
19
  */
20
20
  insert (container, context) {
21
- var element = this.root
21
+ var element = this.element
22
22
 
23
23
  this.insertElement(element, container, context)
24
24
 
@@ -0,0 +1,44 @@
1
+ import dataset from './dataset'
2
+ import Layout from '../layout'
3
+
4
+ export default {
5
+ build () {
6
+ this.element = document.createElement(this.options.tag || 'div')
7
+ // for backward compatibility
8
+ this.element = this.element
9
+
10
+ const defaults = this.constructor.defaults || {}
11
+
12
+ this.element.classList.add(defaults.class)
13
+
14
+ if (this.options.class !== defaults.class) {
15
+ this.addClass(this.options.class)
16
+ }
17
+
18
+ if (this.options.data) {
19
+ dataset(this.element, this.options.data)
20
+ }
21
+
22
+ this.container = this.options.container
23
+
24
+ if (this.container) this.appendTo(this.container)
25
+
26
+ if (this.options.layout) {
27
+ this.layout = new Layout(this.options.layout, this.element)
28
+ this.ui = this.layout.component
29
+ }
30
+
31
+ if (this.options.show === true && this.show) this.show()
32
+ },
33
+
34
+ appendTo (container) {
35
+ container.appendChild(this.element)
36
+ },
37
+
38
+ addClass (clss) {
39
+ const c = clss.replace(/\s+/g, ' ').trim()
40
+ const list = c.split(' ')
41
+ list.forEach(item => this.element.classList.add(item))
42
+ }
43
+
44
+ }
@@ -1,18 +1,5 @@
1
1
  import css from '../module/css'
2
2
 
3
- /**
4
- * Classify component related functions
5
- * @module component/classify
6
- * @category component
7
- */
8
-
9
- /**
10
- * Init component class
11
- * @param {element} element The component root element
12
- * @param {object} options component class options
13
- * @return {Instance} The Class instance
14
- *
15
- */
16
3
  function classify (element, options) {
17
4
  css.add(element, options.prefix + '-' + options.class)
18
5
 
@@ -0,0 +1,12 @@
1
+
2
+ function dataset (element, data) {
3
+ if (data) {
4
+ for (var property in data) {
5
+ if (data.hasOwnProperty(property)) {
6
+ element.dataset[property] = data[property]
7
+ }
8
+ }
9
+ }
10
+ }
11
+
12
+ export default dataset
package/src/module/dom.js CHANGED
@@ -1,98 +1,42 @@
1
- 'use strict'
1
+ // DOM manipulation function
2
2
 
3
- /**
4
- * Element insertion related methods
5
- * @module module/dom
6
- */
7
-
8
- /**
9
- * Inserts content specified by the container argument at the end of HTMLElement
10
- *
11
- * @param {HTMLElement} container
12
- * @param {String|HTMLElement} html
13
- * @return {HTMLElement} inserted element
14
- */
15
3
  function append (container, element) {
16
4
  container.appendChild(element)
17
5
  return element
18
6
  }
19
7
 
20
- /**
21
- * Inserts content specified by the html argument at the beginning of HTMLElement
22
- *
23
- * @param {HTMLElement} container
24
- * @param {string|HTMLElement} html
25
- * @returns {HTMLElement} inserted container
26
- */
27
8
  function prepend (container, element) {
28
9
  return container.insertBefore(element, container.firstChild)
29
10
  }
30
11
 
31
- /**
32
- * Inserts content specified by the html argument after the HTMLElement
33
- *
34
- * @param {HTMLElement} container
35
- * @returns {HTMLElement} inserted container
36
- */
37
12
  function after (container, element) {
38
13
  return container.parentNode.insertBefore(element, container.nextSibling)
39
14
  }
40
15
 
41
- /**
42
- * Inserts content specified by the html argument before the HTMLElement
43
- *
44
- * @param {HTMLElement} container
45
- * @returns {HTMLElement} inserted container
46
- */
47
16
  function before (container, element) {
48
17
  return container.insertBefore(element, container)
49
18
  }
50
19
 
51
- /**
52
- * Replaces given html container with content specified in html parameter
53
- *
54
- * @param {HTMLElement} container
55
- * @param {string|HTMLElement} html
56
- * @returns {HTMLElement} inserted container
57
- */
58
20
  function replace (container, element) {
59
21
  return container.parentNode.replaceChild(element, container)
60
22
  }
61
23
 
62
- /**
63
- * Removes HTMLElement from dom tree
64
- *
65
- * @param {HTMLElement} container
66
- * @returns {HTMLElement} removed container
67
- */
68
24
  function remove (element) {
69
25
  var parent = element.parentNode
70
26
  return parent.removeChild(element)
71
27
  }
72
28
 
73
- /**
74
- * [dispose description]
75
- * @return {Object} The class instance
76
- */
77
29
  function dispose (element) {
78
30
  var el = element
79
31
  return (el.parentNode) ? el.parentNode.removeChild(el) : el
80
32
  }
81
33
 
82
- /**
83
- * empty
84
- * @return {void}
85
- */
86
34
  function empty (element) {
87
35
  while (element.firstChild) {
88
36
  element.removeChild(element.firstChild)
89
37
  }
90
38
  }
91
39
 
92
- /**
93
- * [destroy description]
94
- * @return {Object} this class
95
- */
96
40
  function destroy (element) {
97
41
  return element.parentNode.removeChild(element)
98
42
  }
@@ -0,0 +1,57 @@
1
+ import extract from './extract'
2
+
3
+ function last (str) {}
4
+
5
+ export default {
6
+ bindEvents: function (events) {
7
+ // console.log('bindEvents', events)
8
+ events = events || this.options.events
9
+ if (!events) return
10
+
11
+ // console.log('attach', events, this)
12
+ var instance = this
13
+ events.map((def) => {
14
+ var e = extract.e(instance, def[0])
15
+ var f = extract.f(instance, def[1])
16
+ var option = def[2]
17
+
18
+ var keys = def[1].split('.')
19
+
20
+ keys.pop()
21
+ var bound = this.last(keys.join('.'))
22
+
23
+ if (f && bound && e && e.element && e.element.addEventListener) {
24
+ if (!f) { console.log('error') }
25
+
26
+ if (option) {
27
+ e.element.addEventListener(e.name, f.bind(bound), option)
28
+ } else {
29
+ e.element.addEventListener(e.name, f.bind(bound))
30
+ }
31
+ } else if (e && e.element && e.element.on && f && bound) {
32
+ e.element.on(e.name, f.bind(bound))
33
+ } else {
34
+ // console.log('can\'t attach', def[0])
35
+ }
36
+ })
37
+
38
+ return this
39
+ },
40
+
41
+ last: function (str) {
42
+ // console.log('_path', str)
43
+ if (!str) return this
44
+ else if (!str.match(/\./)) return this[str]
45
+ var last
46
+
47
+ var keys = str.split('.')
48
+ for (var i = 0, l = keys.length; i < l; i++) {
49
+ var key = keys[i]
50
+
51
+ last = last || this
52
+ last = last[key]
53
+ }
54
+
55
+ return last
56
+ }
57
+ }
@@ -0,0 +1,20 @@
1
+ export default function jsonToHTML (obj) {
2
+ // Start an HTML string
3
+ let html = '<div>'
4
+
5
+ // Loop through each property of the object
6
+ for (const [key, value] of Object.entries(obj)) {
7
+ // If the value is an object, call the function recursively
8
+ if (typeof value === 'object' && value !== null) {
9
+ html += `<div class="${key}">${key}${jsonToHTML(value)}</div>`
10
+ } else if (Array.isArray(value)) {
11
+ html += `<div class="${key}">${key}<ul>${value.map(item => `<li>${item}</li>`).join('')}</ul></div>`
12
+ } else {
13
+ html += `<p>${key}: ${value || 'N/A'}</p>`
14
+ }
15
+ }
16
+
17
+ // Close the HTML string
18
+ html += '</div>'
19
+ return html
20
+ }
File without changes
@@ -6,40 +6,21 @@ const defaults = {
6
6
  opacity: ['1', '.3']
7
7
  }
8
8
 
9
- /**
10
- * init ripple
11
- * @param {?} container [description]
12
- * @return {?} [description]
13
- */
14
- function init (instance) {
15
- instance.on('built', (container) => {
16
- set(container)
17
- })
18
- }
19
-
20
- /**
21
- * this function set the event listener
22
- * @param {HTMLElement} container [description]
23
- */
24
- function set (container) {
9
+ function init (container) {
10
+ console.log('set', container)
25
11
  container.addEventListener('mousedown', (e) => {
12
+ console.log('mousedown')
26
13
  show(e)
27
14
  })
28
15
  }
29
16
 
30
- /**
31
- * show method
32
- * @param {event} e The event related to the the touch
33
- * @param {Object} coord
34
- * @return {void}
35
- */
36
17
  function show (e) {
37
- // console.log('show', e);
18
+ console.log('show', e)
38
19
  var container = e.target
39
20
  var offs = offset(container)
40
21
 
41
22
  let ripple = document.createElement('div')
42
- ripple.classList.add('material-ripple')
23
+ ripple.classList.add('ripple')
43
24
  let end = coordinate(offs)
44
25
  let initial = {
45
26
  left: (e.offsetX || offs.width / 2) + 'px',
@@ -67,24 +48,6 @@ function show (e) {
67
48
  }
68
49
  }
69
50
 
70
- /**
71
- * this method hides the given ripple
72
- * @return {Object} Size and position
73
- */
74
- function destroy (ripple) {
75
- if (ripple.parentNode) { ripple.style.opacity = '0' }
76
-
77
- document.body.onmouseup = null
78
-
79
- setTimeout(() => {
80
- if (ripple.parentNode) { ripple.parentNode.removeChild(ripple) }
81
- }, 1000)
82
- }
83
-
84
- /**
85
- * Get ripple final coordinates
86
- * @return {Object} Size and position
87
- */
88
51
  function coordinate (o) {
89
52
  var size = o.height
90
53
  var top = -o.height / 2
@@ -101,4 +64,14 @@ function coordinate (o) {
101
64
  }
102
65
  }
103
66
 
67
+ function destroy (ripple) {
68
+ if (ripple.parentNode) { ripple.style.opacity = '0' }
69
+
70
+ document.body.onmouseup = null
71
+
72
+ setTimeout(() => {
73
+ if (ripple.parentNode) { ripple.parentNode.removeChild(ripple) }
74
+ }, 1000)
75
+ }
76
+
104
77
  export default init
package/src/progress.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // import Component from './component';
4
4
  import create from './element/create'
5
- import classify from './component/classify'
5
+ import classify from './module/classify'
6
6
  import css from './module/css'
7
7
  import insert from './element/insert'
8
8
 
@@ -55,23 +55,23 @@ class Spinner {
55
55
  * @return {Object} This class instance
56
56
  */
57
57
  build (options) {
58
- this.root = create(this.options.tag)
59
- classify(this.root, this.options)
58
+ this.element = create(this.options.tag)
59
+ classify(this.element, this.options)
60
60
 
61
61
  if (this.options.type === 'circular') {
62
- this.root.innerHTML = this.options.circular
62
+ this.element.innerHTML = this.options.circular
63
63
  } if (this.options.type === 'indeterminate') {
64
64
  this.bar = create('div', 'bar')
65
- insert(this.bar, this.root)
65
+ insert(this.bar, this.element)
66
66
  } else {
67
67
  this.bar = create('div', 'bar')
68
- insert(this.bar, this.root)
68
+ insert(this.bar, this.element)
69
69
 
70
70
  this.set(this.options.progress)
71
71
  }
72
72
 
73
73
  if (this.options.container) {
74
- insert(this.root, this.options.container)
74
+ insert(this.element, this.options.container)
75
75
  }
76
76
 
77
77
  return this
package/src/select.js CHANGED
@@ -65,28 +65,28 @@ class Select {
65
65
  build () {
66
66
  // create a new div as input element
67
67
  var tag = this.options.tag || 'div'
68
- this.root = document.createElement(tag)
69
- this.root.classList.add(this.options.prefix + '-' + this.options.class)
68
+ this.element = document.createElement(tag)
69
+ this.element.classList.add(this.options.prefix + '-' + this.options.class)
70
70
 
71
71
  this.buildLabel()
72
72
  this.buildInput()
73
73
  this.buildUnderline()
74
74
 
75
75
  if (this.disabled) {
76
- css.add(this.root, 'is-disabled')
76
+ css.add(this.element, 'is-disabled')
77
77
  }
78
78
 
79
79
  // insert if container this.options is given
80
80
  if (this.options.container) {
81
81
  // console.log(this.name, opts.container);
82
- insert(this.root, this.options.container)
82
+ insert(this.element, this.options.container)
83
83
  }
84
84
  }
85
85
 
86
86
  buildLabel () {
87
87
  this.label = document.createElement('label')
88
88
  this.label.classList.add(this.options.class + '-label')
89
- this.root.appendChild(this.label)
89
+ this.element.appendChild(this.label)
90
90
 
91
91
  if (this.options.label !== false) {
92
92
  this.setLabel()
@@ -101,14 +101,14 @@ class Select {
101
101
  this.input = document.createElement('select')
102
102
  this.input.classList.add(this.options.class + '-input')
103
103
  // this.input.setAttribute('type', 'text')
104
- this.root.appendChild(this.input)
104
+ this.element.appendChild(this.input)
105
105
 
106
106
  if (this.options.options) {
107
107
  this.setOptions(this.options.options)
108
108
  }
109
109
 
110
110
  // if (!this.options.value) {
111
- // this.root.classList.add('is-empty')
111
+ // this.element.classList.add('is-empty')
112
112
  // }
113
113
 
114
114
  if (this.readonly) {
@@ -132,7 +132,7 @@ class Select {
132
132
  buildUnderline () {
133
133
  this.underline = document.createElement('span')
134
134
  this.underline.classList.add(this.options.class + '-underline')
135
- this.root.appendChild(this.underline)
135
+ this.element.appendChild(this.underline)
136
136
  }
137
137
 
138
138
  /**
@@ -185,7 +185,7 @@ class Select {
185
185
  this.disabled = true
186
186
 
187
187
  this.input.setAttribute('disabled', 'disabled')
188
- this.root.classList.add('is-disabled')
188
+ this.element.classList.add('is-disabled')
189
189
  return this
190
190
  }
191
191
 
@@ -193,7 +193,7 @@ class Select {
193
193
  this.disabled = false
194
194
 
195
195
  this.element.input.removeAttribute('disabled')
196
- this.root.classList.remove('is-disabled')
196
+ this.element.classList.remove('is-disabled')
197
197
  return this
198
198
  }
199
199
 
@@ -237,9 +237,9 @@ class Select {
237
237
  this.input.value = value
238
238
 
239
239
  if (value) {
240
- this.root.classList.remove('is-empty')
240
+ this.element.classList.remove('is-empty')
241
241
  } else {
242
- this.root.classList.add('is-empty')
242
+ this.element.classList.add('is-empty')
243
243
  }
244
244
 
245
245
  this.emit('change', value)
@@ -272,9 +272,9 @@ class Select {
272
272
  // console.log('_handleInputKeyPress', e);
273
273
 
274
274
  if (this.get('value') === '') {
275
- this.root.classList.add('is-empty')
275
+ this.element.classList.add('is-empty')
276
276
  } else {
277
- this.root.classList.remove('is-empty')
277
+ this.element.classList.remove('is-empty')
278
278
  }
279
279
 
280
280
  this.emit('change', this.getValue())
@@ -293,7 +293,7 @@ class Select {
293
293
  focus () {
294
294
  if (this.disabled === true) return this
295
295
 
296
- this.root.classList.add('is-focused')
296
+ this.element.classList.add('is-focused')
297
297
  if (this.input !== document.activeElement) { this.input.focus() }
298
298
  return this
299
299
  }
@@ -303,7 +303,7 @@ class Select {
303
303
  * @return {?} [description]
304
304
  */
305
305
  blur () {
306
- this.root.classList.remove('is-focused')
306
+ this.element.classList.remove('is-focused')
307
307
  return this
308
308
  }
309
309
  /**