material 0.7.0 → 0.7.2

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 (148) hide show
  1. package/README.md +1 -5
  2. package/dist/demo-bundle.js +2281 -2
  3. package/dist/demo-bundle.js.map +7 -1
  4. package/dist/demo.js +13 -13
  5. package/esbuild.js +22 -0
  6. package/esbuild.watch.js +25 -0
  7. package/form.js +27 -0
  8. package/index.js +59 -58
  9. package/list.js +35 -0
  10. package/package.json +8 -17
  11. package/src/appbar.js +7 -204
  12. package/src/badge.js +27 -0
  13. package/src/button.js +127 -177
  14. package/src/calendar.js +53 -55
  15. package/src/card.js +1 -3
  16. package/src/checkbox.js +5 -55
  17. package/src/component.js +0 -2
  18. package/src/container.js +0 -2
  19. package/src/datehour.js +38 -0
  20. package/src/dialog.js +104 -151
  21. package/src/divider.js +1 -3
  22. package/src/drawer.js +1 -19
  23. package/src/element/attribute.js +7 -10
  24. package/src/element/build.js +6 -7
  25. package/src/element/create.js +3 -6
  26. package/src/element/event.js +2 -2
  27. package/src/element/insert.js +6 -17
  28. package/src/element/observer.js +22 -0
  29. package/src/element/offset.js +2 -2
  30. package/src/element/style.js +12 -12
  31. package/src/element.js +2 -2
  32. package/src/field/email.js +9 -44
  33. package/src/field/image.js +17 -51
  34. package/src/{control/file.js → file.js} +15 -45
  35. package/src/form/build.js +7 -7
  36. package/src/form/controller.js +8 -8
  37. package/src/form/create.js +1 -1
  38. package/src/form/data.js +9 -9
  39. package/src/form/delete.js +1 -1
  40. package/src/form/render.js +9 -9
  41. package/src/form/set.js +1 -1
  42. package/src/form/submit.js +6 -6
  43. package/src/form/update.js +3 -3
  44. package/src/form/verify.js +6 -6
  45. package/src/form.js +9 -11
  46. package/src/icon.js +4 -6
  47. package/src/image.js +39 -106
  48. package/src/item.js +1 -3
  49. package/src/layout.js +14 -14
  50. package/src/{control/link.js → link.js} +13 -32
  51. package/src/list/build.js +10 -10
  52. package/src/list/click.js +3 -3
  53. package/src/list/collection.js +1 -1
  54. package/src/list/filter.js +11 -11
  55. package/src/list/image.js +3 -3
  56. package/src/list/render.js +15 -15
  57. package/src/list/request.js +8 -8
  58. package/src/list/search.js +12 -12
  59. package/src/list/select.js +18 -18
  60. package/src/list/status.js +1 -1
  61. package/src/list/update.js +6 -6
  62. package/src/list/virtual.js +20 -20
  63. package/src/list/virtual.new.js +5 -5
  64. package/src/list.js +29 -217
  65. package/src/loading.js +73 -0
  66. package/src/map/build.js +2 -2
  67. package/src/map/countries.js +8 -8
  68. package/src/map/display.js +13 -13
  69. package/src/map/focus.js +7 -7
  70. package/src/map/select.js +2 -2
  71. package/src/map/set.js +3 -3
  72. package/src/map/viewport.js +11 -11
  73. package/src/menu.js +59 -115
  74. package/src/mixin/control.js +3 -3
  75. package/src/mixin/controller.js +5 -5
  76. package/src/mixin/create.js +1 -1
  77. package/src/mixin/display.js +1 -2
  78. package/src/mixin/events.js +4 -16
  79. package/src/mixin/focus.js +1 -1
  80. package/src/mixin/icon.js +2 -2
  81. package/src/mixin/init.js +2 -2
  82. package/src/mixin/insert.js +7 -29
  83. package/src/mixin/label.js +2 -2
  84. package/src/mixin/settings.js +5 -5
  85. package/src/module/attach.js +35 -49
  86. package/src/{control/module → module}/attributes.js +4 -4
  87. package/src/module/build.js +12 -12
  88. package/src/module/classify.js +4 -4
  89. package/src/module/controller.js +5 -32
  90. package/src/module/css.js +12 -84
  91. package/src/module/dataset.js +1 -1
  92. package/src/module/dom.js +8 -3
  93. package/src/module/dot.js +4 -4
  94. package/src/module/emitter.js +1 -1
  95. package/src/module/event.js +2 -2
  96. package/src/module/events.js +29 -35
  97. package/src/module/extract.js +10 -10
  98. package/src/module/last.js +18 -0
  99. package/src/module/mediator.js +1 -13
  100. package/src/module/object.js +4 -4
  101. package/src/module/observer.js +43 -16
  102. package/src/module/remove.js +10 -10
  103. package/src/module/ripple.js +19 -24
  104. package/src/module/scrollbar.js +10 -14
  105. package/src/module/smoothscroll.js +5 -9
  106. package/src/module/utils.js +14 -23
  107. package/src/module/viewport.js +5 -5
  108. package/src/navigation.js +19 -0
  109. package/src/progress.js +1 -11
  110. package/src/search.js +66 -0
  111. package/src/select.js +58 -273
  112. package/src/{control/selecter.js → selecter.js} +42 -42
  113. package/src/selector.js +3 -3
  114. package/src/skin/material/component/navigation.sass +9 -0
  115. package/src/skin/material/control/button.sass +10 -0
  116. package/src/slider.js +1 -3
  117. package/src/snackbar.js +72 -50
  118. package/src/switch.js +111 -103
  119. package/src/{control/switcher.js → switcher.js} +28 -31
  120. package/src/tabs.js +4 -5
  121. package/src/tabview.js +26 -46
  122. package/src/text.js +25 -74
  123. package/src/textfield.js +97 -234
  124. package/src/toolbar.js +12 -12
  125. package/src/tooltip.js +7 -7
  126. package/src/tree.js +10 -66
  127. package/src/view/build.js +2 -2
  128. package/src/view/dataset.js +1 -1
  129. package/src/view.js +9 -74
  130. package/rollup.config.js +0 -34
  131. package/src/banner.js +0 -231
  132. package/src/control/button.js +0 -239
  133. package/src/control/button.new.js +0 -190
  134. package/src/control/datehour.js +0 -65
  135. package/src/control/dialog.js +0 -175
  136. package/src/control/image.js +0 -92
  137. package/src/control/list.js +0 -67
  138. package/src/control/loading.js +0 -128
  139. package/src/control/menu.js +0 -85
  140. package/src/control/module/addclass.js +0 -16
  141. package/src/control/search.js +0 -98
  142. package/src/control/select.js +0 -130
  143. package/src/control/snackbar.js +0 -91
  144. package/src/control/switch.js +0 -272
  145. package/src/control/text.js +0 -70
  146. package/src/control/textfield.js +0 -177
  147. package/src/element/ripple.js +0 -90
  148. package/src/tabs/setup.js +0 -0
package/src/menu.js CHANGED
@@ -1,140 +1,84 @@
1
- 'use strict'
2
-
3
- import classify from './module/classify'
4
- import css from './module/css'
5
- import events from './mixin/events'
6
- import insert from './element/insert'
7
- import offset from './element/offset'
8
-
9
- import create from './element/create'
10
-
11
- import attach from './module/attach'
12
- import emitter from './module/emitter'
13
-
14
- import List from './list'
15
- import Item from './item'
16
- import Divider from './divider'
17
-
18
- const defaults = {
19
- prefix: 'material',
20
- class: 'menu',
21
- tag: 'div',
22
- events: [
23
- ['root.click', 'hide'],
24
- ['mask.click', 'hide']
25
- ]
26
- }
1
+ import EventEmitter from './mixin/emitter'
2
+ // menu related modules
3
+ import build from './module/build'
4
+ import bindEvents from './module/events'
5
+ import display from './mixin/display'
6
+
7
+ import Element from './element'
8
+ import Button from './button'
9
+
10
+ class Menu extends EventEmitter {
11
+ static defaults = {
12
+ class: 'menu',
13
+ transition: 200,
14
+ modal: false,
15
+ layout: [
16
+ [Element, 'surface', { class: 'surface' },
17
+ [Element, 'list', { tag: 'ul', class: 'items' }]
18
+ ]
19
+ ],
20
+ events: [
21
+ ['element.click', 'close']
22
+ ]
23
+ }
27
24
 
28
- /**
29
- * This Class represents a menu.
30
- *
31
- * @return {parent} The class instance
32
- * @example new Container({
33
- * container: document.body
34
- * });
35
- */
36
- class Menu {
37
- /**
38
- * Constructor
39
- * @param {Object} options - Component options
40
- * @return {Object} Class instance
41
- */
42
25
  constructor (options) {
43
- this.init(options)
44
- this.build()
45
- this.setup()
26
+ super()
46
27
 
47
- this.attach()
48
-
49
- this.emit('ready')
28
+ this.init(options)
29
+ this.build(this.constructor)
30
+ this.bindEvents()
50
31
 
51
- return this
32
+ this.render(this.options.items)
52
33
  }
53
34
 
54
- /**
55
- * [init description]
56
- * @return {[type]} [description]
57
- */
58
35
  init (options) {
59
- this.options = Object.assign({}, defaults, options || {})
60
-
61
- Object.assign(this, emitter, events, attach, insert)
36
+ this.options = Object.assign({}, Menu.defaults, options || {})
37
+ Object.assign(this, build, bindEvents, display)
62
38
  }
63
39
 
64
- /**
65
- * Build Method
66
- * @return {Object} This class instance
67
- */
68
- build () {
69
- this.element = create(this.options.tag, this.options.css)
70
- this.mask = create(this.options.tag, this.options.class + '-mask')
71
-
72
- if (this.options.position) {
73
- this.element.style.position = this.options.position
74
- }
75
-
76
- classify(this.element, this.options)
77
-
78
- if (this.options.list) {
79
- this.list = new List({
80
- // root: this.element,
81
- list: this.options.list,
82
- target: '.material-item',
83
- height: 600,
84
- label: 'Flat',
85
- select: (item) => {
86
- this.selected = item
87
- this.hide()
88
- }
89
- }).insert(this.element)
40
+ render (items) {
41
+ if (items && Array.isArray(items)) {
42
+ for (let i = 0; i < items.length; i++) {
43
+ this.add(items[i])
44
+ }
90
45
  }
91
46
 
92
- this.emit('built', this.element)
93
-
94
47
  return this
95
48
  }
96
49
 
97
- insert () {
98
- insert(this.mask, document.body)
99
- insert(this.element, document.body)
100
- }
101
-
102
- setup () {
103
- // this.subscribe('click', () => {
104
- // console.log('click');
105
- // this.close();
106
- // });
107
- //
108
- window.addEventListener('resize', () => this.position())
109
- }
110
-
111
- show (e) {
112
- css.add(this.mask, 'mask-show')
113
-
114
- if (e) this.caller = e.target
50
+ add (obj) {
51
+ if (typeof obj !== 'object') return this
52
+ let item
53
+ if (obj.type === 'divider') {
54
+ item = new Element({ tag: 'li', class: 'divider' })
55
+ } else {
56
+ obj.container = this.ui.list
57
+ obj.class = 'item'
58
+ item = new Button(obj).on('click', (ev) => {
59
+ // console.log('select', ev.target.name)
60
+ this.emit('select', ev.target.name)
61
+ })
62
+ }
115
63
 
116
- css.add(this.element, this.options.class + '-show')
117
- this.position(this.caller)
64
+ return this
118
65
  }
119
66
 
120
- position () {
121
- if (!this.caller) return
122
- var offs = offset(this.caller)
67
+ position (target) {
68
+ if (!target) return
69
+ const offs = target.getBoundingClientRect()
123
70
 
124
- var offsw = this.offset = offset(this.element)
71
+ const offsw = this.offset = this.ui.surface.getBoundingClientRect()
125
72
 
126
- // console.log('offset')
127
- // console.log('caller', this.caller, offs, screen.width)
73
+ this.ui.surface.style.top = (offs.top - 4) + 'px'
74
+ this.ui.surface.style.left = offs.left - offsw.width + offs.width + 'px'
128
75
 
129
- this.element.style.top = offs.top + 'px'
130
- this.element.style.left = offs.left - offsw.width + offs.width + 'px'
131
- // this.element.style.right = offs.right + offs.width + offsw.width + 'px'
76
+ return this
132
77
  }
133
78
 
134
- hide () {
135
- // console.log('hide')
136
- css.remove(this.element, this.options.class + '-show')
137
- css.remove(this.mask, 'mask-show')
79
+ close () {
80
+ // console.log('close')
81
+ this.destroy()
138
82
  }
139
83
  }
140
84
 
@@ -1,5 +1,5 @@
1
1
  import create from '../element/create'
2
- import css from '../module/css'
2
+ import * as css from '../module/css'
3
3
  import insert from '../element/insert'
4
4
 
5
5
  const KEYCODE = {
@@ -7,7 +7,7 @@ const KEYCODE = {
7
7
  SPACE: 32
8
8
  }
9
9
 
10
- var control = {
10
+ const control = {
11
11
  /**
12
12
  * [toggle description]
13
13
  * @return {Object} The class instance
@@ -96,7 +96,7 @@ var control = {
96
96
  error = error || this.options.error
97
97
  if (this.options.error === null) return
98
98
 
99
- let text = this.options.error || this.options.text
99
+ const text = this.options.error || this.options.text
100
100
 
101
101
  if (!this.element.error) { this.element.error = create('error', this.options.class + '-error') }
102
102
 
@@ -110,7 +110,7 @@ class Controller {
110
110
  return false
111
111
  }
112
112
 
113
- for (var i = 0, len = this._topics[topic].length; i < len; i++) {
113
+ for (let i = 0, len = this._topics[topic].length; i < len; i++) {
114
114
  if (this._topics[topic][i] === callback) {
115
115
  this._topics[topic].splice(i, 1)
116
116
  return true
@@ -127,20 +127,20 @@ class Controller {
127
127
  publish () {
128
128
  this._topics = this._topics || {}
129
129
 
130
- var args = Array.prototype.slice.call(arguments)
131
- var topic = args.shift()
130
+ const args = Array.prototype.slice.call(arguments)
131
+ const topic = args.shift()
132
132
  // _log.debug('publish', topic);
133
133
  if (!this._topics.hasOwnProperty(topic)) {
134
134
  return false
135
135
  }
136
136
 
137
- for (var i = 0, len = this._topics[topic].length; i < len; i++) {
137
+ for (let i = 0, len = this._topics[topic].length; i < len; i++) {
138
138
  this._topics[topic][i].apply(undefined, args)
139
139
  }
140
140
  return true
141
141
  }
142
142
  }
143
143
 
144
- var controller = new Controller()
144
+ const controller = new Controller()
145
145
 
146
146
  export default controller
@@ -1,7 +1,7 @@
1
1
  import classify from '../module/classify'
2
2
 
3
3
  function create (options) {
4
- var element = document.createElement(options.tag || 'div')
4
+ const element = document.createElement(options.tag || 'div')
5
5
 
6
6
  classify(element, options)
7
7
 
@@ -70,7 +70,6 @@ export default {
70
70
  dom.destroy(this.element)
71
71
  }
72
72
 
73
-
74
- this.emit?.('destroy')
73
+ this.emit?.('destroy')
75
74
  }
76
75
  }
@@ -1,16 +1,10 @@
1
1
  export default {
2
-
3
- /**
4
- * cross browser addEvent
5
- * @param {string} event The event to add
6
- * @param {Function} fn [description]
7
- */
8
2
  addEvent (event, fn) {
9
- var element = this.element
3
+ const element = this.element
10
4
  // avoid memory overhead of new anonymous functions for every event handler that's installed
11
5
  // by using local functions
12
6
  function listenHandler (e) {
13
- var ret = fn.apply(this, arguments)
7
+ const ret = fn.apply(this, arguments)
14
8
  if (ret === false) {
15
9
  e.stopPropagation()
16
10
  e.preventDefault()
@@ -21,7 +15,7 @@ export default {
21
15
  function attachHandler () {
22
16
  // set the this pointer same as addEventListener when fn is called
23
17
  // and make sure the event is passed to the fn also so that works the same too
24
- var ret = fn.call(element, window.event)
18
+ const ret = fn.call(element, window.event)
25
19
  if (ret === false) {
26
20
  window.event.returnValue = false
27
21
  window.event.cancelBubble = true
@@ -38,14 +32,8 @@ export default {
38
32
  return this
39
33
  },
40
34
 
41
- /**
42
- * cross browser removeEvent
43
- * @param {string} event The event to remove
44
- * @param {Function} fn [description]
45
- * @return {Object} [description]
46
- */
47
35
  removeEvent (event, fn) {
48
- var element = this.element
36
+ const element = this.element
49
37
 
50
38
  if (element.removeEventListener) {
51
39
  element.removeEventListener(event, fn, false)
@@ -1,4 +1,4 @@
1
- import css from '../module/css'
1
+ import * as css from '../module/css'
2
2
 
3
3
  export default {
4
4
  /**
package/src/mixin/icon.js CHANGED
@@ -11,12 +11,12 @@ function icon (root, svg, options) {
11
11
  return
12
12
  }
13
13
 
14
- var position = 'top'
14
+ let position = 'top'
15
15
  if (options && options.type === 'text-icon') {
16
16
  position = 'bottom'
17
17
  }
18
18
 
19
- var element = create('i', options.class + '-icon')
19
+ const element = create('i', options.class + '-icon')
20
20
  insert(element, root, position)
21
21
 
22
22
  element.innerHTML = svg
package/src/mixin/init.js CHANGED
@@ -10,9 +10,9 @@ function init (instance) {
10
10
  }
11
11
 
12
12
  function modules (instance) {
13
- var modules = instance.options.modules
13
+ const modules = instance.options.modules
14
14
 
15
- for (var i = 0; i < modules.length; i++) {
15
+ for (let i = 0; i < modules.length; i++) {
16
16
  if (typeof modules[i] === 'function') {
17
17
  modules[i](instance)
18
18
  } else {
@@ -2,41 +2,19 @@
2
2
 
3
3
  import dom from '../module/dom'
4
4
 
5
- /**
6
- * Inject method insert element to the domtree using Dom methods
7
- * @param {HTMLElement} container [description]
8
- * @param {string} context - Injection context
9
- * @return {Object} This class intance
10
- */
11
5
  export default {
12
6
 
13
- /**
14
- * [insert description]
15
- * @param {?} container [description]
16
- * @param {?} context [description]
17
- * @param {?} debug [description]
18
- * @return {?} [description]
19
- */
20
7
  insert (container, context) {
21
- var element = this.element
8
+ const element = this.element
22
9
 
23
10
  this.insertElement(element, container, context)
24
11
 
25
12
  return this
26
13
  },
27
14
 
28
- /**
29
- * [insertElement description]
30
-
31
- * @param {?} element [description]
32
- * @param {?} container [description]
33
- * @param {?} context [description]
34
- * @param {?} debug [description]
35
- * @return {?} [description]
36
- */
37
15
  insertElement (element, container, context) {
38
- if (container && container.root) {
39
- container = container.root
16
+ if (container && container.element) {
17
+ container = container.element
40
18
  }
41
19
 
42
20
  this.container = container
@@ -49,15 +27,15 @@ export default {
49
27
 
50
28
  context = context || 'bottom'
51
29
 
52
- var contexts = ['top', 'bottom', 'after', 'before']
53
- var methods = ['prepend', 'append', 'after', 'before']
30
+ const contexts = ['top', 'bottom', 'after', 'before']
31
+ const methods = ['prepend', 'append', 'after', 'before']
54
32
 
55
- var index = contexts.indexOf(context)
33
+ const index = contexts.indexOf(context)
56
34
  if (index === -1) {
57
35
  return
58
36
  }
59
37
 
60
- var method = methods[index]
38
+ const method = methods[index]
61
39
 
62
40
  // this.emit('insert');
63
41
 
@@ -10,9 +10,9 @@ const prefix = 'material'
10
10
  function label (root, text, options) {
11
11
  text = text || null
12
12
 
13
- var prefix = options.class || options.prefix
13
+ const prefix = options.class || options.prefix
14
14
 
15
- var label = create('label', prefix + '-label')
15
+ const label = create('label', prefix + '-label')
16
16
  label.textContent = text
17
17
  label.setAttribute('for', options.name)
18
18
  insert(label, root)
@@ -2,9 +2,9 @@ import cookies from '../module/cookies'
2
2
  import merge from '../module/merge'
3
3
 
4
4
  function set (key, value) {
5
- var text = cookies.get(key)
5
+ const text = cookies.get(key)
6
6
 
7
- var current = {}
7
+ let current = {}
8
8
 
9
9
  if (text) {
10
10
  current = JSON.parse(text)
@@ -12,7 +12,7 @@ function set (key, value) {
12
12
 
13
13
  console.log('settings value', current, value)
14
14
  // settings = [settings, value].reduce(Object.assign, {});
15
- var settings = merge(current, value)
15
+ const settings = merge(current, value)
16
16
 
17
17
  console.log('settings ' + key, settings)
18
18
 
@@ -20,12 +20,12 @@ function set (key, value) {
20
20
  }
21
21
 
22
22
  function get (key) {
23
- var json = cookies.get(key)
23
+ const json = cookies.get(key)
24
24
 
25
25
  if (!json) {
26
26
  return null
27
27
  }
28
- var value = JSON.parse(json)
28
+ const value = JSON.parse(json)
29
29
 
30
30
  console.log('settings' + key, value)
31
31
 
@@ -1,72 +1,58 @@
1
+ // Assuming extract is imported or defined elsewhere
1
2
  import extract from './extract'
2
3
 
3
- /**
4
- * attach function to events
5
- * @module module/attach
6
- * @category module
7
- */
8
-
9
- /**
10
- * [attach description]
11
- * @param {object} component [description]
12
- * @param {[type]} events [description]
13
- * @return {[type]} [description]
14
- */
15
- export default {
16
- attach: function (events) {
17
- // console.log('attach', events)
4
+ const attachModule = {
5
+ attach (events) {
18
6
  events = events || this.options.events
19
7
  if (!events) return
20
8
 
21
- // console.log('attach', events, this)
22
- var instance = this
23
- events.map((def) => {
24
- var e = extract.e(instance, def[0])
25
- var f = extract.f(instance, def[1])
26
- var option = def[2]
9
+ events.map(([eventDef, funcDef, option]) => {
10
+ const e = extract.e(this, eventDef)
11
+ const isFunction = typeof funcDef === 'function'
12
+ let f = null
13
+ let keys = []
14
+
15
+ if (!isFunction) {
16
+ f = extract.f(this, funcDef)
17
+ keys = funcDef.split('.')
18
+ keys.pop()
19
+ }
27
20
 
28
- var keys = def[1].split('.')
21
+ const bound = this.last(keys.join('.'))
29
22
 
30
- keys.pop()
31
- var bound = this.last(keys.join('.'))
23
+ let handler = null
32
24
 
33
- if (f && bound && e && e.element && e.element.addEventListener) {
34
- if (!f) { console.log('error') }
25
+ if (isFunction) {
26
+ handler = funcDef.bind(this)
27
+ } else if (f && bound) {
28
+ handler = f.bind(bound)
29
+ } else {
30
+ // console.error(`Can't bind function for ${eventDef}`)
31
+ return
32
+ }
35
33
 
34
+ if (handler && e && e.element && e.element.addEventListener) {
36
35
  if (option) {
37
- e.element.addEventListener(e.name, f.bind(bound), option)
36
+ e.element.addEventListener(e.name, handler, option)
38
37
  } else {
39
- e.element.addEventListener(e.name, f.bind(bound))
38
+ e.element.addEventListener(e.name, handler)
40
39
  }
41
- } else if (e && e.element && e.element.on && f && bound) {
42
- e.element.on(e.name, f.bind(bound))
40
+ } else if (e && e.element && e.element.on && handler) {
41
+ e.element.on(e.name, handler)
43
42
  } else {
44
- // console.log('can\'t attach', def[0])
43
+ // console.error(`Can't attach ${eventDef}`)
45
44
  }
46
45
  })
47
46
 
48
47
  return this
49
48
  },
50
49
 
51
- /**
52
- * Return the last reference from an object
53
- * @param {string} str Object path for example key1.key2.key3
54
- * @return {value} The value of the last reference
55
- */
56
- last: function (str) {
57
- // console.log('_path', str)
50
+ last (str) {
58
51
  if (!str) return this
59
- else if (!str.match(/\./)) return this[str]
60
- var last
61
-
62
- var keys = str.split('.')
63
- for (var i = 0, l = keys.length; i < l; i++) {
64
- var key = keys[i]
52
+ if (!str.includes('.')) return this[str]
65
53
 
66
- last = last || this
67
- last = last[key]
68
- }
69
-
70
- return last
54
+ return str.split('.').reduce((acc, key) => acc[key], this)
71
55
  }
72
56
  }
57
+
58
+ export default attachModule
@@ -1,12 +1,12 @@
1
1
  const special = ['required', 'disabled', 'multiple', 'checked']
2
2
 
3
- function setAttributes (element, o) {
3
+ function attributes (element, o) {
4
4
  // console.log('attributes', o.attributes, element)
5
5
 
6
6
  if (!element) return
7
7
 
8
- for (var i = 0; i < o.attributes.length; i++) {
9
- var attribute = o.attributes[i]
8
+ for (let i = 0; i < o.attributes.length; i++) {
9
+ const attribute = o.attributes[i]
10
10
 
11
11
  if (o[attribute] && o[attribute] !== 'undefined') {
12
12
  if (special.indexOf(attribute) > -1) {
@@ -18,4 +18,4 @@ function setAttributes (element, o) {
18
18
  }
19
19
  }
20
20
 
21
- export default setAttributes
21
+ export default attributes
@@ -1,25 +1,32 @@
1
+ import * as css from './css'
1
2
  import dataset from './dataset'
3
+
2
4
  import Layout from '../layout'
3
5
 
4
6
  export default {
5
7
  build () {
6
8
  this.element = document.createElement(this.options.tag || 'div')
7
- // for backward compatibility
8
- this.element = this.element
9
9
 
10
10
  const defaults = this.constructor.defaults || {}
11
11
 
12
- this.element.classList.add(defaults.class)
12
+ if (defaults.base) css.add(this.element, defaults.base)
13
+ if (defaults.class) css.add(this.element, defaults.class)
13
14
 
14
15
  if (this.options.class !== defaults.class) {
15
- this.addClass(this.options.class)
16
+ css.add(this.element, this.options.class)
16
17
  }
17
18
 
19
+ if (defaults.class === 'account') console.log('data')
20
+
18
21
  if (this.options.data) {
19
22
  dataset(this.element, this.options.data)
20
23
  }
21
24
 
22
- this.container = this.options.container
25
+ if (this.options.base === 'view') {
26
+ this.container = this.options.container || document.body
27
+ } else {
28
+ this.container = this.options.container
29
+ }
23
30
 
24
31
  if (this.container) this.appendTo(this.container)
25
32
 
@@ -33,12 +40,5 @@ export default {
33
40
 
34
41
  appendTo (container) {
35
42
  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
  }
43
-
44
44
  }