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.
- package/README.md +1 -5
- package/dist/demo-bundle.js +2281 -2
- package/dist/demo-bundle.js.map +7 -1
- package/dist/demo.js +13 -13
- package/esbuild.js +22 -0
- package/esbuild.watch.js +25 -0
- package/form.js +27 -0
- package/index.js +59 -58
- package/list.js +35 -0
- package/package.json +8 -17
- package/src/appbar.js +7 -204
- package/src/badge.js +27 -0
- package/src/button.js +127 -177
- package/src/calendar.js +53 -55
- package/src/card.js +1 -3
- package/src/checkbox.js +5 -55
- package/src/component.js +0 -2
- package/src/container.js +0 -2
- package/src/datehour.js +38 -0
- package/src/dialog.js +104 -151
- package/src/divider.js +1 -3
- package/src/drawer.js +1 -19
- package/src/element/attribute.js +7 -10
- package/src/element/build.js +6 -7
- package/src/element/create.js +3 -6
- package/src/element/event.js +2 -2
- package/src/element/insert.js +6 -17
- package/src/element/observer.js +22 -0
- package/src/element/offset.js +2 -2
- package/src/element/style.js +12 -12
- package/src/element.js +2 -2
- package/src/field/email.js +9 -44
- package/src/field/image.js +17 -51
- package/src/{control/file.js → file.js} +15 -45
- package/src/form/build.js +7 -7
- package/src/form/controller.js +8 -8
- package/src/form/create.js +1 -1
- package/src/form/data.js +9 -9
- package/src/form/delete.js +1 -1
- package/src/form/render.js +9 -9
- package/src/form/set.js +1 -1
- package/src/form/submit.js +6 -6
- package/src/form/update.js +3 -3
- package/src/form/verify.js +6 -6
- package/src/form.js +9 -11
- package/src/icon.js +4 -6
- package/src/image.js +39 -106
- package/src/item.js +1 -3
- package/src/layout.js +14 -14
- package/src/{control/link.js → link.js} +13 -32
- package/src/list/build.js +10 -10
- package/src/list/click.js +3 -3
- package/src/list/collection.js +1 -1
- package/src/list/filter.js +11 -11
- package/src/list/image.js +3 -3
- package/src/list/render.js +15 -15
- package/src/list/request.js +8 -8
- package/src/list/search.js +12 -12
- package/src/list/select.js +18 -18
- package/src/list/status.js +1 -1
- package/src/list/update.js +6 -6
- package/src/list/virtual.js +20 -20
- package/src/list/virtual.new.js +5 -5
- package/src/list.js +29 -217
- package/src/loading.js +73 -0
- package/src/map/build.js +2 -2
- package/src/map/countries.js +8 -8
- package/src/map/display.js +13 -13
- package/src/map/focus.js +7 -7
- package/src/map/select.js +2 -2
- package/src/map/set.js +3 -3
- package/src/map/viewport.js +11 -11
- package/src/menu.js +59 -115
- package/src/mixin/control.js +3 -3
- package/src/mixin/controller.js +5 -5
- package/src/mixin/create.js +1 -1
- package/src/mixin/display.js +1 -2
- package/src/mixin/events.js +4 -16
- package/src/mixin/focus.js +1 -1
- package/src/mixin/icon.js +2 -2
- package/src/mixin/init.js +2 -2
- package/src/mixin/insert.js +7 -29
- package/src/mixin/label.js +2 -2
- package/src/mixin/settings.js +5 -5
- package/src/module/attach.js +35 -49
- package/src/{control/module → module}/attributes.js +4 -4
- package/src/module/build.js +12 -12
- package/src/module/classify.js +4 -4
- package/src/module/controller.js +5 -32
- package/src/module/css.js +12 -84
- package/src/module/dataset.js +1 -1
- package/src/module/dom.js +8 -3
- package/src/module/dot.js +4 -4
- package/src/module/emitter.js +1 -1
- package/src/module/event.js +2 -2
- package/src/module/events.js +29 -35
- package/src/module/extract.js +10 -10
- package/src/module/last.js +18 -0
- package/src/module/mediator.js +1 -13
- package/src/module/object.js +4 -4
- package/src/module/observer.js +43 -16
- package/src/module/remove.js +10 -10
- package/src/module/ripple.js +19 -24
- package/src/module/scrollbar.js +10 -14
- package/src/module/smoothscroll.js +5 -9
- package/src/module/utils.js +14 -23
- package/src/module/viewport.js +5 -5
- package/src/navigation.js +19 -0
- package/src/progress.js +1 -11
- package/src/search.js +66 -0
- package/src/select.js +58 -273
- package/src/{control/selecter.js → selecter.js} +42 -42
- package/src/selector.js +3 -3
- package/src/skin/material/component/navigation.sass +9 -0
- package/src/skin/material/control/button.sass +10 -0
- package/src/slider.js +1 -3
- package/src/snackbar.js +72 -50
- package/src/switch.js +111 -103
- package/src/{control/switcher.js → switcher.js} +28 -31
- package/src/tabs.js +4 -5
- package/src/tabview.js +26 -46
- package/src/text.js +25 -74
- package/src/textfield.js +97 -234
- package/src/toolbar.js +12 -12
- package/src/tooltip.js +7 -7
- package/src/tree.js +10 -66
- package/src/view/build.js +2 -2
- package/src/view/dataset.js +1 -1
- package/src/view.js +9 -74
- package/rollup.config.js +0 -34
- package/src/banner.js +0 -231
- package/src/control/button.js +0 -239
- package/src/control/button.new.js +0 -190
- package/src/control/datehour.js +0 -65
- package/src/control/dialog.js +0 -175
- package/src/control/image.js +0 -92
- package/src/control/list.js +0 -67
- package/src/control/loading.js +0 -128
- package/src/control/menu.js +0 -85
- package/src/control/module/addclass.js +0 -16
- package/src/control/search.js +0 -98
- package/src/control/select.js +0 -130
- package/src/control/snackbar.js +0 -91
- package/src/control/switch.js +0 -272
- package/src/control/text.js +0 -70
- package/src/control/textfield.js +0 -177
- package/src/element/ripple.js +0 -90
- package/src/tabs/setup.js +0 -0
package/src/menu.js
CHANGED
|
@@ -1,140 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
44
|
-
this.build()
|
|
45
|
-
this.setup()
|
|
26
|
+
super()
|
|
46
27
|
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
this.
|
|
28
|
+
this.init(options)
|
|
29
|
+
this.build(this.constructor)
|
|
30
|
+
this.bindEvents()
|
|
50
31
|
|
|
51
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
117
|
-
this.position(this.caller)
|
|
64
|
+
return this
|
|
118
65
|
}
|
|
119
66
|
|
|
120
|
-
position () {
|
|
121
|
-
if (!
|
|
122
|
-
|
|
67
|
+
position (target) {
|
|
68
|
+
if (!target) return
|
|
69
|
+
const offs = target.getBoundingClientRect()
|
|
123
70
|
|
|
124
|
-
|
|
71
|
+
const offsw = this.offset = this.ui.surface.getBoundingClientRect()
|
|
125
72
|
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
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
|
-
|
|
135
|
-
// console.log('
|
|
136
|
-
|
|
137
|
-
css.remove(this.mask, 'mask-show')
|
|
79
|
+
close () {
|
|
80
|
+
// console.log('close')
|
|
81
|
+
this.destroy()
|
|
138
82
|
}
|
|
139
83
|
}
|
|
140
84
|
|
package/src/mixin/control.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
package/src/mixin/controller.js
CHANGED
|
@@ -110,7 +110,7 @@ class Controller {
|
|
|
110
110
|
return false
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
for (
|
|
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
|
-
|
|
131
|
-
|
|
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 (
|
|
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
|
-
|
|
144
|
+
const controller = new Controller()
|
|
145
145
|
|
|
146
146
|
export default controller
|
package/src/mixin/create.js
CHANGED
package/src/mixin/display.js
CHANGED
package/src/mixin/events.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
+
const element = this.element
|
|
49
37
|
|
|
50
38
|
if (element.removeEventListener) {
|
|
51
39
|
element.removeEventListener(event, fn, false)
|
package/src/mixin/focus.js
CHANGED
package/src/mixin/icon.js
CHANGED
|
@@ -11,12 +11,12 @@ function icon (root, svg, options) {
|
|
|
11
11
|
return
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
let position = 'top'
|
|
15
15
|
if (options && options.type === 'text-icon') {
|
|
16
16
|
position = 'bottom'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
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
|
-
|
|
13
|
+
const modules = instance.options.modules
|
|
14
14
|
|
|
15
|
-
for (
|
|
15
|
+
for (let i = 0; i < modules.length; i++) {
|
|
16
16
|
if (typeof modules[i] === 'function') {
|
|
17
17
|
modules[i](instance)
|
|
18
18
|
} else {
|
package/src/mixin/insert.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
39
|
-
container = container.
|
|
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
|
-
|
|
53
|
-
|
|
30
|
+
const contexts = ['top', 'bottom', 'after', 'before']
|
|
31
|
+
const methods = ['prepend', 'append', 'after', 'before']
|
|
54
32
|
|
|
55
|
-
|
|
33
|
+
const index = contexts.indexOf(context)
|
|
56
34
|
if (index === -1) {
|
|
57
35
|
return
|
|
58
36
|
}
|
|
59
37
|
|
|
60
|
-
|
|
38
|
+
const method = methods[index]
|
|
61
39
|
|
|
62
40
|
// this.emit('insert');
|
|
63
41
|
|
package/src/mixin/label.js
CHANGED
|
@@ -10,9 +10,9 @@ const prefix = 'material'
|
|
|
10
10
|
function label (root, text, options) {
|
|
11
11
|
text = text || null
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const prefix = options.class || options.prefix
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const label = create('label', prefix + '-label')
|
|
16
16
|
label.textContent = text
|
|
17
17
|
label.setAttribute('for', options.name)
|
|
18
18
|
insert(label, root)
|
package/src/mixin/settings.js
CHANGED
|
@@ -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
|
-
|
|
5
|
+
const text = cookies.get(key)
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
+
const json = cookies.get(key)
|
|
24
24
|
|
|
25
25
|
if (!json) {
|
|
26
26
|
return null
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const value = JSON.parse(json)
|
|
29
29
|
|
|
30
30
|
console.log('settings' + key, value)
|
|
31
31
|
|
package/src/module/attach.js
CHANGED
|
@@ -1,72 +1,58 @@
|
|
|
1
|
+
// Assuming extract is imported or defined elsewhere
|
|
1
2
|
import extract from './extract'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
21
|
+
const bound = this.last(keys.join('.'))
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
var bound = this.last(keys.join('.'))
|
|
23
|
+
let handler = null
|
|
32
24
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
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,
|
|
36
|
+
e.element.addEventListener(e.name, handler, option)
|
|
38
37
|
} else {
|
|
39
|
-
e.element.addEventListener(e.name,
|
|
38
|
+
e.element.addEventListener(e.name, handler)
|
|
40
39
|
}
|
|
41
|
-
} else if (e && e.element && e.element.on &&
|
|
42
|
-
e.element.on(e.name,
|
|
40
|
+
} else if (e && e.element && e.element.on && handler) {
|
|
41
|
+
e.element.on(e.name, handler)
|
|
43
42
|
} else {
|
|
44
|
-
// console.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
3
|
+
function attributes (element, o) {
|
|
4
4
|
// console.log('attributes', o.attributes, element)
|
|
5
5
|
|
|
6
6
|
if (!element) return
|
|
7
7
|
|
|
8
|
-
for (
|
|
9
|
-
|
|
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
|
|
21
|
+
export default attributes
|
package/src/module/build.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|