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/module/classify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import css from '../module/css'
|
|
1
|
+
import * as css from '../module/css'
|
|
2
2
|
|
|
3
3
|
function classify (element, options) {
|
|
4
4
|
css.add(element, options.prefix + '-' + options.class)
|
|
@@ -34,14 +34,14 @@ function classify (element, options) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (options.style) {
|
|
37
|
-
|
|
38
|
-
for (
|
|
37
|
+
const styles = options.style.split(' ')
|
|
38
|
+
for (let i = 0; i < styles.length; i++) {
|
|
39
39
|
css.add(element, 'style-' + styles[i])
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (options.data) {
|
|
44
|
-
for (
|
|
44
|
+
for (const property in options.data) {
|
|
45
45
|
if (options.data.hasOwnProperty(property)) {
|
|
46
46
|
element.dataset[property] = options.data[property]
|
|
47
47
|
}
|
package/src/module/controller.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
var controller = {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* [register description]
|
|
10
|
-
* @param {component} component [description]
|
|
11
|
-
* @return {Object} The class instance
|
|
12
|
-
*/
|
|
1
|
+
const controller = {
|
|
13
2
|
register (instance, group) {
|
|
14
3
|
group = group || 'component'
|
|
15
4
|
this[group + 's'] = this[group + 's'] || []
|
|
@@ -24,12 +13,6 @@ var controller = {
|
|
|
24
13
|
return this
|
|
25
14
|
},
|
|
26
15
|
|
|
27
|
-
/**
|
|
28
|
-
* This method subscribes to a specific topic
|
|
29
|
-
* @param {string} topic
|
|
30
|
-
* @param {Function} callback
|
|
31
|
-
* @return {boolean} true
|
|
32
|
-
*/
|
|
33
16
|
subscribe (topic, callback) {
|
|
34
17
|
this._topics = this._topics || {}
|
|
35
18
|
|
|
@@ -42,12 +25,6 @@ var controller = {
|
|
|
42
25
|
return true
|
|
43
26
|
},
|
|
44
27
|
|
|
45
|
-
/**
|
|
46
|
-
* This method unsubscribes to a specific topic
|
|
47
|
-
* @param {string} topic
|
|
48
|
-
* @param {Function} callback
|
|
49
|
-
* @return {boolean} true
|
|
50
|
-
*/
|
|
51
28
|
unsunscribe (topic, callback) {
|
|
52
29
|
this._topics = this._topics || {}
|
|
53
30
|
// _log.debug('unsubscribe', topic);
|
|
@@ -55,7 +32,7 @@ var controller = {
|
|
|
55
32
|
return false
|
|
56
33
|
}
|
|
57
34
|
|
|
58
|
-
for (
|
|
35
|
+
for (let i = 0, len = this._topics[topic].length; i < len; i++) {
|
|
59
36
|
if (this._topics[topic][i] === callback) {
|
|
60
37
|
this._topics[topic].splice(i, 1)
|
|
61
38
|
return true
|
|
@@ -65,21 +42,17 @@ var controller = {
|
|
|
65
42
|
return false
|
|
66
43
|
},
|
|
67
44
|
|
|
68
|
-
/**
|
|
69
|
-
* [publish description]
|
|
70
|
-
* @return {?} [description]
|
|
71
|
-
*/
|
|
72
45
|
publish () {
|
|
73
46
|
this._topics = this._topics || {}
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
const args = Array.prototype.slice.call(arguments)
|
|
49
|
+
const topic = args.shift()
|
|
77
50
|
// _log.debug('publish', topic);
|
|
78
51
|
if (!this._topics.hasOwnProperty(topic)) {
|
|
79
52
|
return false
|
|
80
53
|
}
|
|
81
54
|
|
|
82
|
-
for (
|
|
55
|
+
for (let i = 0, len = this._topics[topic].length; i < len; i++) {
|
|
83
56
|
this._topics[topic][i].apply(undefined, args)
|
|
84
57
|
}
|
|
85
58
|
return true
|
package/src/module/css.js
CHANGED
|
@@ -1,51 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @since 0.0.6
|
|
5
|
-
* @module css/has
|
|
6
|
-
* @category Element
|
|
7
|
-
* @param {...Array} [arrays] The arrays to process.
|
|
8
|
-
* @param {Function} iteratee The function to combine
|
|
9
|
-
* grouped values.
|
|
10
|
-
* @returns {Array} Returns the new array of grouped elements.
|
|
11
|
-
* @see unzip, unzipWith, zip, zipObject, zipObjectDeep, zipWith
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* has(element, 'show');
|
|
15
|
-
* // => [111, 222]
|
|
16
|
-
*/
|
|
17
|
-
function has(element, className) {
|
|
18
|
-
if (!element || !className) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return !!element.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'))
|
|
1
|
+
const has = (element, className) => {
|
|
2
|
+
if (!element || !className) return false
|
|
3
|
+
return !!element.className.match(new RegExp(`(\\s|^)${className}(\\s|$)`))
|
|
23
4
|
}
|
|
24
5
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @since 0.0.6
|
|
29
|
-
* @module css/add
|
|
30
|
-
* @category css
|
|
31
|
-
* @param {HTMLElement} element Related element
|
|
32
|
-
* @param {String} className the className to add
|
|
33
|
-
* grouped values.
|
|
34
|
-
* @returns {HTMLElement} The augmented element
|
|
35
|
-
* @example
|
|
36
|
-
*
|
|
37
|
-
* add(element, 'hidden');
|
|
38
|
-
* // => <div class="element hidden">...</div>
|
|
39
|
-
*/
|
|
40
|
-
function add(element, className) {
|
|
41
|
-
if (!element || !className) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
6
|
+
const add = (element, className) => {
|
|
7
|
+
if (!element || !className) return
|
|
44
8
|
|
|
45
|
-
|
|
9
|
+
const sanitizedClassName = className.trim().replace(/\s+/g, ' ')
|
|
10
|
+
const classNames = sanitizedClassName.split(' ')
|
|
46
11
|
|
|
47
|
-
for (
|
|
48
|
-
var cn = classNames[i]
|
|
12
|
+
for (const cn of classNames) {
|
|
49
13
|
if (!has(element, cn)) {
|
|
50
14
|
element.classList.add(cn)
|
|
51
15
|
}
|
|
@@ -53,55 +17,19 @@ function add(element, className) {
|
|
|
53
17
|
return element
|
|
54
18
|
}
|
|
55
19
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
* @since 0.0.6
|
|
60
|
-
* @module css/remove
|
|
61
|
-
* @category css
|
|
62
|
-
* @param {HTMLElement} element Related element
|
|
63
|
-
* @param {String} className the className to add
|
|
64
|
-
* @returns {HTMLElement} The element with the removed className
|
|
65
|
-
* @example
|
|
66
|
-
*
|
|
67
|
-
* remove(element, 'hidden');
|
|
68
|
-
* // => <div class="element">...</div>
|
|
69
|
-
*/
|
|
70
|
-
function remove(element, className) {
|
|
71
|
-
if (!element || !className) {
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
|
|
20
|
+
const remove = (element, className) => {
|
|
21
|
+
if (!element || !className) return
|
|
75
22
|
element.classList.remove(className)
|
|
76
|
-
|
|
77
23
|
return element
|
|
78
24
|
}
|
|
79
25
|
|
|
80
|
-
|
|
81
|
-
* This function toggles className from the element's attribute class
|
|
82
|
-
*
|
|
83
|
-
* @since 0.0.6
|
|
84
|
-
* @module css/toggle
|
|
85
|
-
* @category Element
|
|
86
|
-
* @param {HTMLElement} element Related element
|
|
87
|
-
* @param {String} className the className to add
|
|
88
|
-
* grouped values.
|
|
89
|
-
* @returns {HTMLElement} The modified element
|
|
90
|
-
* @example
|
|
91
|
-
*
|
|
92
|
-
* toggle(element, 'hidden');
|
|
93
|
-
* // => <div class="element">...</div>
|
|
94
|
-
* toggle(element, 'hidden');
|
|
95
|
-
* // => <div class="element hidden">...</div>
|
|
96
|
-
*/
|
|
97
|
-
function toggle(element, className) {
|
|
26
|
+
const toggle = (element, className) => {
|
|
98
27
|
if (has(element, className)) {
|
|
99
28
|
remove(element, className)
|
|
100
29
|
} else {
|
|
101
30
|
add(element, className)
|
|
102
31
|
}
|
|
103
|
-
|
|
104
32
|
return element
|
|
105
33
|
}
|
|
106
34
|
|
|
107
|
-
export
|
|
35
|
+
export { has, add, remove, toggle }
|
package/src/module/dataset.js
CHANGED
package/src/module/dom.js
CHANGED
|
@@ -22,12 +22,12 @@ function replace (container, element) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function remove (element) {
|
|
25
|
-
|
|
25
|
+
const parent = element.parentNode
|
|
26
26
|
return parent.removeChild(element)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function dispose (element) {
|
|
30
|
-
|
|
30
|
+
const el = element
|
|
31
31
|
return (el.parentNode) ? el.parentNode.removeChild(el) : el
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -38,7 +38,12 @@ function empty (element) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function destroy (element) {
|
|
41
|
-
|
|
41
|
+
if (element && element.parentNode) {
|
|
42
|
+
return element.parentNode.removeChild(element)
|
|
43
|
+
} else {
|
|
44
|
+
// console.error('Element or its parent node is null')
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
export default { append, prepend, after, before, replace, remove, destroy, empty, dispose }
|
package/src/module/dot.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
function dot (obj) {
|
|
3
|
-
|
|
3
|
+
const res = {}
|
|
4
4
|
function recurse (obj, current) {
|
|
5
|
-
for (
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
for (const key in obj) {
|
|
6
|
+
const value = obj[key]
|
|
7
|
+
const newKey = (current ? current + '.' + key : key)
|
|
8
8
|
if (value && typeof value === 'object') {
|
|
9
9
|
recurse(value, newKey)
|
|
10
10
|
} else {
|
package/src/module/emitter.js
CHANGED
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
emit (event /* , args... */) {
|
|
15
15
|
this.event = this.event || {}
|
|
16
16
|
if (event in this.event === false) return
|
|
17
|
-
for (
|
|
17
|
+
for (let i = 0; i < this.event[event].length; i++) {
|
|
18
18
|
this.event[event][i].apply(this, Array.prototype.slice.call(arguments, 1))
|
|
19
19
|
}
|
|
20
20
|
return this
|
package/src/module/event.js
CHANGED
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
// avoid memory overhead of new anonymous functions for every event handler that's installed
|
|
10
10
|
// by using local functions
|
|
11
11
|
function listenHandler (e) {
|
|
12
|
-
|
|
12
|
+
const ret = fn.apply(this, arguments)
|
|
13
13
|
if (ret === false) {
|
|
14
14
|
e.stopPropagation()
|
|
15
15
|
e.preventDefault()
|
|
@@ -20,7 +20,7 @@ export default {
|
|
|
20
20
|
function attachHandler () {
|
|
21
21
|
// set the this pointer same as addEventListener when fn is called
|
|
22
22
|
// and make sure the event is passed to the fn also so that works the same too
|
|
23
|
-
|
|
23
|
+
const ret = fn.call(element, window.event)
|
|
24
24
|
if (ret === false) {
|
|
25
25
|
window.event.returnValue = false
|
|
26
26
|
window.event.cancelBubble = true
|
package/src/module/events.js
CHANGED
|
@@ -1,57 +1,51 @@
|
|
|
1
1
|
import extract from './extract'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
bindEvents: function (events) {
|
|
7
|
-
// console.log('bindEvents', events)
|
|
3
|
+
const attachModule = {
|
|
4
|
+
bindEvents (events) {
|
|
8
5
|
events = events || this.options.events
|
|
9
6
|
if (!events) return
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var option = def[2]
|
|
17
|
-
|
|
18
|
-
var keys = def[1].split('.')
|
|
19
|
-
|
|
8
|
+
events.map(([eventDef, funcDef, option]) => {
|
|
9
|
+
const e = extract.e(this, eventDef)
|
|
10
|
+
const isFunction = typeof funcDef === 'function'
|
|
11
|
+
const f = isFunction ? null : extract.f(this, funcDef)
|
|
12
|
+
const keys = funcDef.split('.')
|
|
20
13
|
keys.pop()
|
|
21
|
-
|
|
14
|
+
const bound = this.last(keys.join('.'))
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
if (!f) { console.log('error') }
|
|
16
|
+
let handler = null
|
|
25
17
|
|
|
18
|
+
if (isFunction && funcDef) {
|
|
19
|
+
handler = funcDef.bind(this)
|
|
20
|
+
} else if (f && bound) {
|
|
21
|
+
handler = f.bind(bound)
|
|
22
|
+
} else {
|
|
23
|
+
// console.error(`Can't bind function for ${eventDef}`)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (handler && e && e.element && e.element.addEventListener) {
|
|
26
28
|
if (option) {
|
|
27
|
-
e.element.addEventListener(e.name,
|
|
29
|
+
e.element.addEventListener(e.name, handler, option)
|
|
28
30
|
} else {
|
|
29
|
-
e.element.addEventListener(e.name,
|
|
31
|
+
e.element.addEventListener(e.name, handler)
|
|
30
32
|
}
|
|
31
|
-
} else if (e && e.element && e.element.on &&
|
|
32
|
-
e.element.on(e.name,
|
|
33
|
+
} else if (e && e.element && e.element.on && handler) {
|
|
34
|
+
e.element.on(e.name, handler)
|
|
33
35
|
} else {
|
|
34
|
-
// console.
|
|
36
|
+
// console.error(`Can't attach ${eventDef}`)
|
|
35
37
|
}
|
|
36
38
|
})
|
|
37
39
|
|
|
38
40
|
return this
|
|
39
41
|
},
|
|
40
42
|
|
|
41
|
-
last
|
|
42
|
-
// console.log('_path', str)
|
|
43
|
+
last (str) {
|
|
43
44
|
if (!str) return this
|
|
44
|
-
|
|
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]
|
|
45
|
+
if (!str.includes('.')) return this[str]
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
last = last[key]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return last
|
|
47
|
+
return str.split('.').reduce((acc, key) => acc[key], this)
|
|
56
48
|
}
|
|
57
49
|
}
|
|
50
|
+
|
|
51
|
+
export default attachModule
|
package/src/module/extract.js
CHANGED
|
@@ -13,14 +13,14 @@ function e (instance, ev) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
let iteration
|
|
17
|
+
const obj = {}
|
|
18
|
+
let element
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const keys = ev.split('.')
|
|
21
21
|
|
|
22
|
-
for (
|
|
23
|
-
|
|
22
|
+
for (let i = 0, l = keys.length; i <= l; i++) {
|
|
23
|
+
const key = keys[i]
|
|
24
24
|
iteration = iteration || instance
|
|
25
25
|
iteration = iteration[key]
|
|
26
26
|
|
|
@@ -45,11 +45,11 @@ function f (instance, func) {
|
|
|
45
45
|
if (typeof func === 'function') {
|
|
46
46
|
return func
|
|
47
47
|
} else if (!func.match(/\./)) return instance[func]
|
|
48
|
-
|
|
48
|
+
let iteration
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
for (
|
|
52
|
-
|
|
50
|
+
const keys = func.split('.')
|
|
51
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
52
|
+
const key = keys[i]
|
|
53
53
|
|
|
54
54
|
iteration = iteration || instance
|
|
55
55
|
iteration = iteration[key]
|
package/src/module/last.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
(str) => {
|
|
3
|
+
// console.log('_path', str)
|
|
4
|
+
if (!str) return this
|
|
5
|
+
else if (!str.match(/\./)) return this[str]
|
|
6
|
+
var last
|
|
7
|
+
|
|
8
|
+
var keys = str.split('.')
|
|
9
|
+
for (var i = 0, l = keys.length; i < l; i++) {
|
|
10
|
+
var key = keys[i]
|
|
11
|
+
|
|
12
|
+
last = last || this
|
|
13
|
+
last = last[key]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return last
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/module/mediator.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
const mediator = ((() => {
|
|
2
|
-
/**
|
|
3
|
-
* @description Subscribe to an event, supply a callback to be executed when that event is broadcast
|
|
4
|
-
* @param store {string}
|
|
5
|
-
* @param fn {function}
|
|
6
|
-
* @returns {subscribe} {object}
|
|
7
|
-
*/
|
|
8
2
|
const subscribe = function (store, fn) {
|
|
9
3
|
if (!mediator.stores[store]) {
|
|
10
4
|
mediator.stores[store] = []
|
|
@@ -18,19 +12,13 @@ const mediator = ((() => {
|
|
|
18
12
|
return this
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
/**
|
|
22
|
-
* @description Publish/broadcast an event to the rest of the application
|
|
23
|
-
* @param store {string}
|
|
24
|
-
* @param args {object}
|
|
25
|
-
* @returns {*||boolean}
|
|
26
|
-
*/
|
|
27
15
|
const publish = function (store, ...args) {
|
|
28
16
|
// console.log('publish', store, args)
|
|
29
17
|
if (!mediator.stores[store]) {
|
|
30
18
|
return false
|
|
31
19
|
}
|
|
32
20
|
|
|
33
|
-
for (
|
|
21
|
+
for (const value of mediator.stores[store]) {
|
|
34
22
|
const subscription = value
|
|
35
23
|
subscription.callback.apply(subscription.context, args)
|
|
36
24
|
}
|
package/src/module/object.js
CHANGED
|
@@ -7,10 +7,10 @@ function is (object) {
|
|
|
7
7
|
|
|
8
8
|
function byString (o, s) {
|
|
9
9
|
s = s.replace(/\[(\w+)\]/g, '.$1') // convert indexes to properties
|
|
10
|
-
s = s.replace(/^\./, '')
|
|
11
|
-
|
|
12
|
-
for (
|
|
13
|
-
|
|
10
|
+
s = s.replace(/^\./, '') // strip a leading dot
|
|
11
|
+
const a = s.split('.')
|
|
12
|
+
for (let i = 0, n = a.length; i < n; ++i) {
|
|
13
|
+
const k = a[i]
|
|
14
14
|
if (k in o) {
|
|
15
15
|
o = o[k]
|
|
16
16
|
} else {
|
package/src/module/observer.js
CHANGED
|
@@ -1,23 +1,50 @@
|
|
|
1
|
+
const observer = (() => {
|
|
2
|
+
const watch = function (event, fn, context = this) {
|
|
3
|
+
if (typeof event !== 'string' || typeof fn !== 'function') {
|
|
4
|
+
throw new Error('Invalid arguments. Event must be a string and callback must be a function.')
|
|
5
|
+
}
|
|
1
6
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (document.contains(element)) {
|
|
6
|
-
if (typeof cb === 'function' && !element.classList.contains('inserted')) {
|
|
7
|
-
cb()
|
|
8
|
-
}
|
|
7
|
+
if (!observer.events[event]) {
|
|
8
|
+
observer.events[event] = []
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
observer.events[event].push({
|
|
12
|
+
context,
|
|
13
|
+
callback: fn
|
|
12
14
|
})
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
return this
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const unwatch = function (event, fn) {
|
|
20
|
+
if (!observer.events[event]) return this
|
|
21
|
+
|
|
22
|
+
observer.events[event] = observer.events[event].filter(subscriber => subscriber.callback !== fn)
|
|
23
|
+
|
|
24
|
+
return this
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const notify = function (event, ...args) {
|
|
28
|
+
if (!observer.events[event]) return this
|
|
29
|
+
|
|
30
|
+
for (const { context, callback } of observer.events[event]) {
|
|
31
|
+
callback.apply(context, args)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
events: {},
|
|
39
|
+
watch,
|
|
40
|
+
unwatch,
|
|
41
|
+
notify,
|
|
42
|
+
init: function (obj) {
|
|
43
|
+
obj.watch = watch
|
|
44
|
+
obj.unwatch = unwatch
|
|
45
|
+
obj.notify = notify
|
|
46
|
+
}
|
|
20
47
|
}
|
|
21
|
-
}
|
|
48
|
+
})()
|
|
22
49
|
|
|
23
50
|
export default observer
|
package/src/module/remove.js
CHANGED
|
@@ -19,16 +19,16 @@ export default {
|
|
|
19
19
|
if (!events) return
|
|
20
20
|
|
|
21
21
|
// console.log('attach', events, this)
|
|
22
|
-
|
|
22
|
+
const instance = this
|
|
23
23
|
events.map((def) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const e = extract.e(instance, def[0])
|
|
25
|
+
const f = extract.f(instance, def[1])
|
|
26
|
+
const option = def[2]
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const keys = def[1].split('.')
|
|
29
29
|
|
|
30
30
|
keys.pop()
|
|
31
|
-
|
|
31
|
+
const bound = this.last(keys.join('.'))
|
|
32
32
|
|
|
33
33
|
if (f && bound && e && e.element && e.element.addEventListener) {
|
|
34
34
|
if (!f) { console.log('error') }
|
|
@@ -59,11 +59,11 @@ export default {
|
|
|
59
59
|
// console.log('_path', str)
|
|
60
60
|
if (!str) return this
|
|
61
61
|
else if (!str.match(/\./)) return this[str]
|
|
62
|
-
|
|
62
|
+
let last
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
for (
|
|
66
|
-
|
|
64
|
+
const keys = str.split('.')
|
|
65
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
66
|
+
const key = keys[i]
|
|
67
67
|
|
|
68
68
|
last = last || this
|
|
69
69
|
last = last[key]
|