material 0.9.20 → 0.9.22

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 (51) hide show
  1. package/index.js +1 -0
  2. package/package.json +1 -1
  3. package/src/class/app.js +10 -0
  4. package/src/class/component.js +16 -13
  5. package/src/class/control.js +24 -16
  6. package/src/class/form.js +7 -22
  7. package/src/class/view.js +18 -19
  8. package/src/colorpicker.js +356 -0
  9. package/src/datehour.js +17 -12
  10. package/src/form/cancel.js +1 -2
  11. package/src/form/controller.js +10 -18
  12. package/src/form/data.js +175 -47
  13. package/src/form/fetch.js +18 -25
  14. package/src/form/render.js +2 -2
  15. package/src/form/submit.js +9 -3
  16. package/src/form/update.js +27 -30
  17. package/src/list/build.js +6 -1
  18. package/src/list/status.js +5 -0
  19. package/src/list/update.js +2 -0
  20. package/src/list/virtual.js +1 -1
  21. package/src/module/dom.js +0 -1
  22. package/src/module/emitter.js +45 -13
  23. package/src/module/extract.js +2 -2
  24. package/src/module/layout.js +1 -1
  25. package/src/module/request.js +49 -16
  26. package/src/selector.js +1 -1
  27. package/src/skin/material/control/colorpicker.sass +188 -0
  28. package/src/switch.js +6 -8
  29. package/src/switcher.js +21 -12
  30. package/src/text.js +1 -1
  31. package/src/textfield.js +6 -1
  32. package/src/list.new/build.js +0 -139
  33. package/src/list.new/click.js +0 -40
  34. package/src/list.new/collection.js +0 -30
  35. package/src/list.new/create.js +0 -45
  36. package/src/list.new/data.js +0 -16
  37. package/src/list.new/display.js +0 -78
  38. package/src/list.new/empty.js +0 -9
  39. package/src/list.new/filter.js +0 -114
  40. package/src/list.new/image.js +0 -19
  41. package/src/list.new/init.js +0 -6
  42. package/src/list.new/load.js +0 -9
  43. package/src/list.new/remove.js +0 -22
  44. package/src/list.new/render.js +0 -142
  45. package/src/list.new/request.js +0 -216
  46. package/src/list.new/search.js +0 -155
  47. package/src/list.new/select.js +0 -221
  48. package/src/list.new/status.js +0 -21
  49. package/src/list.new/update.js +0 -75
  50. package/src/list.new/virtual.js +0 -186
  51. package/src/list.new/virtual.new.js +0 -213
@@ -1,78 +0,0 @@
1
-
2
- export default {
3
- toggle () {
4
- this.visible ? this.hide() : this.show()
5
-
6
- this.emit('toggle')
7
- return this
8
- },
9
-
10
- show () {
11
- // console.log('show', this.visible)
12
-
13
- this.element.getBoundingClientRect()
14
-
15
- this.element.classList.add('show')
16
- this.visible = true
17
-
18
- if (this.underlay) {
19
- this.underlay.classList.add('show')
20
- }
21
-
22
- this.virtual.setOffset('onShow')
23
-
24
- this.emit('show')
25
- return this
26
- },
27
-
28
- hide () {
29
- // console.log('hide', this.element.style.display)
30
-
31
- if (!this.element) return
32
-
33
- this.element.classList.remove('show')
34
- this.visible = false
35
-
36
- if (this.underlay) {
37
- this.underlay.classList.remove('show')
38
- }
39
-
40
- this.emit('hide')
41
- return this
42
- },
43
-
44
- destroy () {
45
- // console.log('destroy', this.options.transition)
46
- if (this.options.transition && this.element) {
47
- this.element.classList.remove('show')
48
-
49
- if (this.underlay) {
50
- this.underlay.classList.remove('show')
51
- }
52
-
53
- setTimeout(() => {
54
- this.removeChild()
55
- }, this.options.transition)
56
- } else {
57
- this.removeChild()
58
- }
59
-
60
- this.emit('destroy')
61
-
62
- return this
63
- },
64
-
65
- removeChild () {
66
- if (this.element && this.element.parentNode) {
67
- this.element.parentNode.removeChild(this.element)
68
- this.element = null
69
- }
70
-
71
- if (this.underlay && this.underlay.parentNode) {
72
- this.underlay.parentNode.removeChild(this.underlay)
73
- }
74
-
75
- this.emit('remove')
76
- return this
77
- }
78
- }
@@ -1,9 +0,0 @@
1
- export default {
2
- empty () {
3
- // console.log('empty')
4
- this.ui.body.innerHTML = ''
5
- this.data = []
6
- this.dataList = []
7
- this.dataStore = {}
8
- }
9
- }
@@ -1,114 +0,0 @@
1
-
2
- export default {
3
- initFilter () {
4
- this.filter = this.extractFilter(this.ui)
5
-
6
- for (const name in this.filter) {
7
- if (this.filter.hasOwnProperty(name)) {
8
- this.filter[name].on('change', () => {
9
- this.request()
10
- })
11
- }
12
- }
13
-
14
- this.ui['filter-clear'].on('click', () => {
15
- this.clearFilter()
16
- })
17
-
18
- this.ui.filter.on('click', () => {
19
- this.toggleFilter()
20
- })
21
- },
22
-
23
- getFilter () {
24
- console.log('getFilter')
25
- let filter = null
26
- for (const name in this.filter) {
27
- if (this.filter.hasOwnProperty(name)) {
28
- console.log('--', typeof this.filter[name].get(), this.filter[name].get())
29
- if (this.filter[name].get() !== ''/* && this.filter[name].get() !== [] */) {
30
- if (filter) {
31
- filter = filter + '&' + name + '=' + this.filter[name].get()
32
- } else {
33
- filter = name + '=' + this.filter[name].get()
34
- }
35
- }
36
- }
37
- }
38
-
39
- // console.log('filter', filter)
40
-
41
- return filter
42
- },
43
-
44
- toggleFilter () {
45
- // console.log('toggleFilter', this.ui['filter-input'])
46
-
47
- if (this.ui['filter-input'].classList.contains('show')) {
48
- this.hideFilter()
49
- } else {
50
- this.showFilter()
51
- }
52
- },
53
-
54
- /**
55
- * [showSearch description]
56
- * @return {[type]} [description]
57
- */
58
- showFilter () {
59
- if (this.hideSearch) {
60
- this.hideSearch()
61
- }
62
-
63
- // console.log('showSearch')
64
- this.ui.filter.element.classList.add('selected')
65
- this.ui['filter-input'].classList.add('show')
66
-
67
- // this.ui['search-list'].classList.add('show')
68
- // this.ui.body.classList.add('hide')
69
- },
70
-
71
- /**
72
- * [hideSearch description]
73
- * @return {[type]} [description]
74
- */
75
- hideFilter () {
76
- // console.log('hideSearch')
77
- this.ui.filter.element.classList.remove('selected')
78
- this.ui['filter-input'].classList.remove('show')
79
- // this.ui['search-list'].classList.remove('show')
80
- // this.ui.body.classList.remove('hide')
81
- this.clearFilter()
82
- this.request()
83
- },
84
-
85
- clearFilter () {
86
- for (const name in this.filter) {
87
- if (this.filter.hasOwnProperty(name)) {
88
- this.filter[name].set('')
89
- }
90
- }
91
-
92
- this.request()
93
- },
94
-
95
- extractFilter (object) {
96
- // console.log('extractField', object)
97
-
98
- const filter = {}
99
-
100
- for (const property in object) {
101
- if (object.hasOwnProperty(property)) {
102
- const str = property.split(/\./)
103
-
104
- if (str[0] === 'filter' && str[1] !== undefined) {
105
- const name = property.substr(7, property.length)
106
-
107
- filter[name] = object[property]
108
- }
109
- }
110
- }
111
-
112
- return filter
113
- }
114
- }
@@ -1,19 +0,0 @@
1
- export default {
2
- image (info, layout) {
3
- if (info.image) {
4
- let format = 'thumb'
5
- if (this.options.image && this.options.image.format) {
6
- format = this.options.image.format || format + '/'
7
- } else {
8
- format = ''
9
- }
10
-
11
- const r = Math.floor(Math.random() * 100000) + 1
12
-
13
- if (info.image.filename) {
14
- const image = info.image.url + format + info.image.filename
15
- layout.get('image').style.backgroundImage = 'url("' + image + '?' + r + '")'
16
- }
17
- }
18
- }
19
- }
@@ -1,6 +0,0 @@
1
- export default {
2
- init () {
3
- this.build()
4
- events.attach(this.options.events, this)
5
- }
6
- }
@@ -1,9 +0,0 @@
1
-
2
- export default {
3
- load () {
4
- console.error('load', this.page)
5
- this.page = this.page || 2
6
- this.page++
7
- this.request(this.page)
8
- }
9
- }
@@ -1,22 +0,0 @@
1
- export default {
2
- remove (id) {
3
- // console.log('remove', id, this.dataList)
4
- // console.log('datalist', this.dataList)
5
-
6
- if (!id) return
7
-
8
- if (!this.dataStore[id]) {
9
- // console.log('not in the list')
10
- return
11
- }
12
-
13
- this.dataList.splice(this.dataList.indexOf(id), 1)
14
-
15
- // remove id from the list
16
- this.data = this.data.filter((info) => { return info[this.dataId] !== id })
17
-
18
- // console.log('data', this.data)
19
-
20
- this.virtual.update(this.data)
21
- }
22
- }
@@ -1,142 +0,0 @@
1
- import Element from '../element'
2
- import { create } from '../module/layout'
3
-
4
- import dot from '../module/dot'
5
-
6
- export default {
7
-
8
- render (list, page, size) {
9
- // console.log('render', list)
10
- this.virtual.set(list, { page, size })
11
-
12
- if (this.status && this.options.count !== true) {
13
- this.status('count', list.length)
14
- }
15
- },
16
-
17
- /**
18
- * [add description]
19
- * @param {[type]} info [description]
20
- * @param {[type]} context [description]
21
- */
22
- renderItem (info, context) {
23
- // console.log('renderItem', info)
24
- info = info || {}
25
-
26
- const container = this.ui.body
27
-
28
- if (context === 'create') {
29
- container.scrolltop = 0
30
- }
31
-
32
- // if (context === 'search') {
33
- // container = this.ui['search-list']
34
- // }
35
-
36
- const element = new Element({
37
- tag: 'li',
38
- class: 'item'
39
- })
40
-
41
- if (this.id && this.id === info[this.dataId]) {
42
- element.classList.add('selected')
43
- }
44
-
45
- element.dataset.id = info[this.dataId]
46
- element.dataset.info = this.options.info
47
-
48
- let layout = null
49
-
50
- if (this.options.itemSwitch) {
51
- const item = info[this.options.itemSwitch]
52
-
53
- if (this.options.layout.item[item]) {
54
- layout = create(this.options.layout.item[item], element)
55
- } else {
56
- layout = create(this.options.layout.item.base, element)
57
- }
58
- } else {
59
- const itemName = this.options.itemName || 'item'
60
- layout = create(this.options.layout[itemName], element)
61
- }
62
-
63
- // console.log('translate', layout)
64
-
65
- if (this.translate && this.options.item && this.options.item.translate) {
66
- // console.log('----')
67
- this.translate(layout)
68
- }
69
-
70
- this.renderInfo(layout, info)
71
-
72
- if (context === 'top' || context === 'create') {
73
- container.insertBefore(element, container.firstChild)
74
- this.selectCreated(info, element)
75
- } else {
76
- container.appendChild(element)
77
- }
78
-
79
- this.emit('infoRendered', info, element)
80
-
81
- return element
82
- },
83
-
84
- /**
85
- * [renderInfo description]
86
- * @param {[type]} layout [description]
87
- * @param {[type]} info [description]
88
- * @return {[type]} [description]
89
- */
90
- renderInfo (layout, object) {
91
- // console.log('renderInfo', object)
92
- const info = dot(object)
93
-
94
- const f = this.extractInfo(layout.component)
95
-
96
- for (const field in f) {
97
- if (f.hasOwnProperty(field)) {
98
- if (f[field] && f[field].set) {
99
- f[field].set(this.objectValueByDotKey(object, field))
100
- } else {
101
- // console.log('innerHTML', typeof f[field])
102
- f[field].innerHTML = info[field]
103
- }
104
- }
105
- }
106
- },
107
-
108
- objectValueByDotKey (object, dotkey) {
109
- const keys = dotkey.split(/\./)
110
-
111
- let value = Object.assign({}, object)
112
-
113
- for (let i = 0; i < keys.length; i++) {
114
- if (value !== undefined) {
115
- value = value[keys[i]]
116
- }
117
- }
118
-
119
- return value
120
- },
121
-
122
- extractInfo (object) {
123
- // console.log('extractField', object)
124
-
125
- const field = {}
126
-
127
- for (const property in object) {
128
- if (object.hasOwnProperty(property)) {
129
- const infos = property.split(/\./)
130
-
131
- if (infos[0] === 'info' && infos[1] !== undefined) {
132
- const name = property.substr(5, property.length)
133
- // console.log('field', name, property)
134
-
135
- field[name] = object[property]
136
- }
137
- }
138
- }
139
-
140
- return field
141
- }
142
- }
@@ -1,216 +0,0 @@
1
- export default {
2
- requestById (id, cb) {
3
- // log.error('requestById', id)
4
- if (!id) return
5
- return this.getPage(id, (data) => {
6
- // log.error('getPage', data)
7
- const page = data?.page || null
8
- if (data?.count) this.virtual.setCount(data?.count)
9
- this.request(page, null, null, cb)
10
- })
11
- },
12
-
13
- request (page, size, more, cb) {
14
- // console.log('request', page, size, more, cb)
15
- if (more !== true) {
16
- this.ui.body.innerHTML = ''
17
- this.virtual.reset()
18
- this.dataList = []
19
- this.data = []
20
- this.page = 1
21
- this.stop = true
22
- } else {
23
- if (this.dataList.length < size) {
24
- // console.log('no more request needed, data ', this.dataList.length)
25
- return
26
- }
27
- }
28
-
29
- this.data = this.data || []
30
- let signal = null
31
-
32
- if (this.abortController) {
33
- // console.log('abort')
34
- this.abortController.abort()
35
- this.abortController = null
36
- }
37
-
38
- if (more !== true && window.AbortController) {
39
- this.abortController = new AbortController()
40
- signal = this.abortController.signal
41
- }
42
-
43
- page = page || 1
44
- size = size || this.options.list.size
45
- // console.log('size', this.options.name, size)
46
-
47
- if (page === 1) {
48
- this.ui.body.scrolltop = 0
49
- }
50
-
51
- const route = this.buildRoute(page, size)
52
-
53
- if (more !== true && this.options.count) {
54
- this.requestCount(route)
55
- }
56
-
57
- // console.log('route - ', this.rand, route)
58
-
59
- fetch(route, { signal }).then((resp) => {
60
- return resp.json()
61
- }).then((data) => {
62
- if (this.options.debug) {
63
- console.log('data', route, data.length, data)
64
- }
65
-
66
- // console.log('route', route);
67
-
68
- data = data || []
69
-
70
- if (this.options.reverse) {
71
- data.reverse()
72
- }
73
-
74
- if (data.error) {
75
- console.log('error', data.error)
76
- return
77
- }
78
-
79
- if (data.length < this.size && more) {
80
- this.stop = true
81
- } else {
82
- this.stop = false
83
- }
84
-
85
- this.data = []
86
- this.data = data
87
- this.storeData(data, page, size)
88
- this.render(data, page, size)
89
-
90
- // if (more === true) {
91
- // const a = this.data.concat(data)
92
- // this.data = a
93
- // this.storeData(data, more)
94
- // this.virtual.add(this.data, { page, size })
95
- // } else {
96
- // this.data = []
97
- // this.data = data
98
- // this.storeData(data)
99
- // this.render(data, page, size)
100
- // }
101
-
102
- if (cb) cb()
103
-
104
- this.emit('fetched', data)
105
-
106
- this.loaded = true
107
-
108
- if (page === 1 && data.length < 1) {
109
- this.emit('empty')
110
- }
111
- }).catch(function (e) {
112
- // console.log('error', e.message)
113
- })
114
- },
115
-
116
- getPage (id, cb) {
117
- // log.info('getPage', id)
118
- if (!id) {
119
- return Promise.reject(new Error('id is required'))
120
- }
121
-
122
- const route = this.buildRoute(null, null, null, id)
123
-
124
- // log.error('route', route)
125
-
126
- return fetch(route)
127
- .then((resp) => resp.json())
128
- .then((data) => {
129
- // log.debug('getPage data', data)
130
- if (cb) cb(data)
131
- return data
132
- })
133
- .catch((e) => {
134
- // console.log('error', e.message)
135
- return Promise.reject(e)
136
- })
137
- },
138
-
139
- requestCount (route, signal) {
140
- log.error('fetchCount', route + '&count=1')
141
- fetch(route + '&count=1', { signal }).then((resp) => {
142
- return resp.json()
143
- }).then((data) => {
144
- log.info('data', data.count)
145
- this.count = data.count
146
- this.statusDisplay('count', data.count)
147
- log.info(this.virtual.setCount)
148
- this.virtual.setCount(data.count)
149
- }).catch(function (e) {
150
- // console.log('error', e.message)
151
- })
152
- },
153
-
154
- addParams (route, params) {
155
- // log.info('addParams', route, params)
156
-
157
- if (!route) {
158
- console.log('error: no route specified!')
159
-
160
- return
161
- }
162
-
163
- if (route.indexOf('?') > -1) {
164
- // console.log('?', route, route.length, route[route.length - 1])
165
- if (route[route.length - 1] === '&' || route[route.length - 1] === '?') {
166
- route = route + params
167
- } else {
168
- route = route + '&' + params
169
- }
170
- } else {
171
- // console.log('add ?')
172
- route = route + '?' + params
173
- }
174
-
175
- return route
176
- },
177
-
178
- buildRoute (page, size, path, id) {
179
- // log.info('buildroute', this.options.route, path)
180
- path = path || 'list'
181
-
182
- page = page || 1
183
- size = size || this.options.list.size
184
-
185
- let route = this.options.route
186
-
187
- if (path) {
188
- route = this.options.route[path]
189
- }
190
-
191
- if (this.routeAddOn) {
192
- route = this.routeAddOn(route, path, id)
193
- }
194
-
195
- if (this.params && this.params()) {
196
- // console.log('params', route, this.params())
197
- route = this.addParams(route, this.params())
198
- } else {
199
-
200
- }
201
-
202
- if (this.ui.filter && this.ui.filter.element.classList.contains('selected')) {
203
- route = this.addParams(route, this.getFilter())
204
- }
205
-
206
- if (this.options.pagination) {
207
- if (id) {
208
- route = this.addParams(route, 'id=' + id + '&size=' + size)
209
- } else {
210
- route = this.addParams(route, 'page=' + page + '&size=' + size)
211
- }
212
- }
213
-
214
- return route
215
- }
216
- }