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/list/render.js
CHANGED
|
@@ -23,7 +23,7 @@ export default {
|
|
|
23
23
|
// console.log('renderItem', info)
|
|
24
24
|
info = info || {}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const container = this.ui.body
|
|
27
27
|
|
|
28
28
|
if (context === 'create') {
|
|
29
29
|
container.scrolltop = 0
|
|
@@ -33,7 +33,7 @@ export default {
|
|
|
33
33
|
// container = this.ui['search-list']
|
|
34
34
|
// }
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const element = new Element({
|
|
37
37
|
tag: 'li',
|
|
38
38
|
class: 'item'
|
|
39
39
|
})
|
|
@@ -47,10 +47,10 @@ export default {
|
|
|
47
47
|
element.dataset.id = info[this.dataId]
|
|
48
48
|
element.dataset.info = this.options.info
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
let layout = null
|
|
51
51
|
|
|
52
52
|
if (this.options.itemSwitch) {
|
|
53
|
-
|
|
53
|
+
const item = info[this.options.itemSwitch]
|
|
54
54
|
|
|
55
55
|
if (this.options.layout.item[item]) {
|
|
56
56
|
layout = new Layout(this.options.layout.item[item], element)
|
|
@@ -58,7 +58,7 @@ export default {
|
|
|
58
58
|
layout = new Layout(this.options.layout.item.base, element)
|
|
59
59
|
}
|
|
60
60
|
} else {
|
|
61
|
-
|
|
61
|
+
const itemName = this.options.itemName || 'item'
|
|
62
62
|
layout = new Layout(this.options.layout[itemName], element)
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -91,11 +91,11 @@ export default {
|
|
|
91
91
|
*/
|
|
92
92
|
renderInfo (layout, object) {
|
|
93
93
|
// console.log('renderInfo', object)
|
|
94
|
-
|
|
94
|
+
const info = dot(object)
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
const f = this.extractInfo(layout.component)
|
|
97
97
|
|
|
98
|
-
for (
|
|
98
|
+
for (const field in f) {
|
|
99
99
|
if (f.hasOwnProperty(field)) {
|
|
100
100
|
if (f[field] && f[field].set) {
|
|
101
101
|
f[field].set(this.objectValueByDotKey(object, field))
|
|
@@ -108,11 +108,11 @@ export default {
|
|
|
108
108
|
},
|
|
109
109
|
|
|
110
110
|
objectValueByDotKey (object, dotkey) {
|
|
111
|
-
|
|
111
|
+
const keys = dotkey.split(/\./)
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
let value = Object.assign({}, object)
|
|
114
114
|
|
|
115
|
-
for (
|
|
115
|
+
for (let i = 0; i < keys.length; i++) {
|
|
116
116
|
if (value !== undefined) {
|
|
117
117
|
value = value[keys[i]]
|
|
118
118
|
}
|
|
@@ -124,14 +124,14 @@ export default {
|
|
|
124
124
|
extractInfo (object) {
|
|
125
125
|
// console.log('extractField', object)
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
const field = {}
|
|
128
128
|
|
|
129
|
-
for (
|
|
129
|
+
for (const property in object) {
|
|
130
130
|
if (object.hasOwnProperty(property)) {
|
|
131
|
-
|
|
131
|
+
const infos = property.split(/\./)
|
|
132
132
|
|
|
133
133
|
if (infos[0] === 'info' && infos[1] !== undefined) {
|
|
134
|
-
|
|
134
|
+
const name = property.substr(5, property.length)
|
|
135
135
|
// console.log('field', name, property)
|
|
136
136
|
|
|
137
137
|
field[name] = object[property]
|
package/src/list/request.js
CHANGED
|
@@ -16,7 +16,7 @@ export default {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
this.data = this.data || []
|
|
19
|
-
|
|
19
|
+
let signal = null
|
|
20
20
|
|
|
21
21
|
if (this.abortController) {
|
|
22
22
|
// console.log('abort')
|
|
@@ -37,7 +37,7 @@ export default {
|
|
|
37
37
|
this.ui.body.scrolltop = 0
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const route = this.buildRoute(page, size)
|
|
41
41
|
|
|
42
42
|
if (more !== true && this.options.count) {
|
|
43
43
|
this.requestCount(route)
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
|
|
46
46
|
// console.log('route - ', this.rand, route)
|
|
47
47
|
|
|
48
|
-
fetch(route, {signal}).then((resp) => {
|
|
48
|
+
fetch(route, { signal }).then((resp) => {
|
|
49
49
|
return resp.json()
|
|
50
50
|
}).then((data) => {
|
|
51
51
|
if (this.options.debug) {
|
|
@@ -68,7 +68,7 @@ export default {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
if (more === true) {
|
|
71
|
-
|
|
71
|
+
const a = this.data.concat(data)
|
|
72
72
|
this.data = a
|
|
73
73
|
this.storeData(data, more)
|
|
74
74
|
this.virtual.add(this.data)
|
|
@@ -95,7 +95,7 @@ export default {
|
|
|
95
95
|
|
|
96
96
|
requestCount (route, signal) {
|
|
97
97
|
// console.log('fetchCount', route)
|
|
98
|
-
fetch(route + '&count=1', {signal}).then((resp) => {
|
|
98
|
+
fetch(route + '&count=1', { signal }).then((resp) => {
|
|
99
99
|
return resp.json()
|
|
100
100
|
}).then((data) => {
|
|
101
101
|
// console.log('data', data.count)
|
|
@@ -137,7 +137,7 @@ export default {
|
|
|
137
137
|
page = page || 1
|
|
138
138
|
size = size || this.options.list.size
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
let route = this.options.route
|
|
141
141
|
|
|
142
142
|
if (path) {
|
|
143
143
|
route = this.options.route[path]
|
|
@@ -154,7 +154,7 @@ export default {
|
|
|
154
154
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
if (this.ui.filter && this.ui.filter.
|
|
157
|
+
if (this.ui.filter && this.ui.filter.element.classList.contains('selected')) {
|
|
158
158
|
route = this.addParams(route, this.getFilter())
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -174,7 +174,7 @@ export default {
|
|
|
174
174
|
// console.log('storeData', this.dataStore)
|
|
175
175
|
this.dataStore = this.dataStore || {}
|
|
176
176
|
|
|
177
|
-
for (
|
|
177
|
+
for (let i = 0; i < list.length; i++) {
|
|
178
178
|
this.dataList.push(list[i][this.dataId])
|
|
179
179
|
this.dataStore[list[i][this.dataId]] = list[i]
|
|
180
180
|
}
|
package/src/list/search.js
CHANGED
|
@@ -15,7 +15,7 @@ export default {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
this.data = this.data || []
|
|
18
|
-
|
|
18
|
+
let signal = null
|
|
19
19
|
|
|
20
20
|
if (this.abortController) {
|
|
21
21
|
this.abortController.abort()
|
|
@@ -34,7 +34,7 @@ export default {
|
|
|
34
34
|
this.ui.body.scrolltop = 0
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
let route = this.buildRoute(page, size, 'search')
|
|
38
38
|
|
|
39
39
|
route = this.addParams(route, 'search=' + keywords)
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ export default {
|
|
|
44
44
|
this.requestCount(route)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
fetch(route, {signal}).then((resp) => {
|
|
47
|
+
fetch(route, { signal }).then((resp) => {
|
|
48
48
|
return resp.json()
|
|
49
49
|
}).then((data) => {
|
|
50
50
|
// console.log('data', data)
|
|
@@ -64,7 +64,7 @@ export default {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (more === true) {
|
|
67
|
-
|
|
67
|
+
const a = this.data.concat(data)
|
|
68
68
|
this.data = a
|
|
69
69
|
this.storeData(data, more)
|
|
70
70
|
this.virtual.add(this.data)
|
|
@@ -93,7 +93,7 @@ export default {
|
|
|
93
93
|
toggleSearch (e) {
|
|
94
94
|
e.stopPropagation()
|
|
95
95
|
// console.log('toggle search', this.ui.body)
|
|
96
|
-
if (!this.ui['search-input'].
|
|
96
|
+
if (!this.ui['search-input'].element.classList.contains('show')) {
|
|
97
97
|
this.showSearch()
|
|
98
98
|
} else {
|
|
99
99
|
this.hideSearch()
|
|
@@ -114,13 +114,13 @@ export default {
|
|
|
114
114
|
this.element.classList.add('search-mode')
|
|
115
115
|
|
|
116
116
|
if (this.ui.search) {
|
|
117
|
-
this.ui.search.
|
|
117
|
+
this.ui.search.element.classList.add('selected')
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
if (this.ui['search-input']) {
|
|
121
|
-
this.ui['search-input'].
|
|
122
|
-
this.ui['search-input'].
|
|
123
|
-
this.ui['search-input'].
|
|
121
|
+
this.ui['search-input'].set()
|
|
122
|
+
this.ui['search-input'].show()
|
|
123
|
+
this.ui['search-input'].focus()
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
this.ui.body.innerHTML = ''
|
|
@@ -139,11 +139,11 @@ export default {
|
|
|
139
139
|
this.element.classList.remove('search-mode')
|
|
140
140
|
|
|
141
141
|
if (this.ui.search) {
|
|
142
|
-
this.ui.search.
|
|
142
|
+
this.ui.search.element.classList.remove('selected')
|
|
143
143
|
}
|
|
144
144
|
if (this.ui['search-input']) {
|
|
145
|
-
this.ui['search-input'].
|
|
146
|
-
this.ui['search-input'].
|
|
145
|
+
this.ui['search-input'].hide()
|
|
146
|
+
this.ui['search-input'].set()
|
|
147
147
|
}
|
|
148
148
|
// this.ui['search-list'].classList.remove('show')
|
|
149
149
|
// this.ui.body.classList.remove('hide')
|
package/src/list/select.js
CHANGED
|
@@ -3,7 +3,7 @@ export default {
|
|
|
3
3
|
// console.log('select', item.dataset.id)
|
|
4
4
|
if (!item || !item.dataset.id) return
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const id = item.dataset.id
|
|
7
7
|
|
|
8
8
|
this.index = this.dataList.indexOf(id)
|
|
9
9
|
this.info = this.dataStore[id]
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
return
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const selected = this.ui.body.querySelector('.selected')
|
|
16
16
|
if (selected) selected.classList.remove('selected')
|
|
17
17
|
|
|
18
18
|
if (id) {
|
|
@@ -32,7 +32,7 @@ export default {
|
|
|
32
32
|
|
|
33
33
|
unselect () {
|
|
34
34
|
// console.log('unselect')
|
|
35
|
-
|
|
35
|
+
const item = this.ui.body.querySelector('[data-id="' + this.id + '"]') || this.item
|
|
36
36
|
this.id = null
|
|
37
37
|
if (item) {
|
|
38
38
|
item.classList.remove('selected')
|
|
@@ -51,7 +51,7 @@ export default {
|
|
|
51
51
|
|
|
52
52
|
getItemById (id, silent) {
|
|
53
53
|
// console.log('selectItemById', id)
|
|
54
|
-
|
|
54
|
+
const item = this.ui.body.querySelector('[data-id="' + id + '"]')
|
|
55
55
|
|
|
56
56
|
if (!item) {
|
|
57
57
|
return null
|
|
@@ -67,7 +67,7 @@ export default {
|
|
|
67
67
|
return false
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
const index = this.dataList.indexOf(id)
|
|
71
71
|
if (index < 0) {
|
|
72
72
|
// console.log('can\'t selectid, not in the list')
|
|
73
73
|
return false
|
|
@@ -83,16 +83,16 @@ export default {
|
|
|
83
83
|
|
|
84
84
|
selectItemById (id, direction) {
|
|
85
85
|
// console.log('selectItemById', id)
|
|
86
|
-
|
|
86
|
+
const item = this.ui.body.querySelector('[data-id="' + id + '"]')
|
|
87
87
|
|
|
88
88
|
this.id = id
|
|
89
89
|
|
|
90
90
|
if (!item) {
|
|
91
|
-
|
|
91
|
+
const index = this.dataList.indexOf(id)
|
|
92
92
|
// console.log('not found in DOM, check in dataList', index)
|
|
93
93
|
if (index > -1) {
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
const listSize = this.options.list.size
|
|
95
|
+
const slice = listSize * index / listSize
|
|
96
96
|
// console.log('getSlice', slice)
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -103,7 +103,7 @@ export default {
|
|
|
103
103
|
|
|
104
104
|
// if (this.item) this.item.classList.remove('selected')
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
const selected = this.ui.body.querySelector('.selected')
|
|
107
107
|
if (selected) selected.classList.remove('selected')
|
|
108
108
|
|
|
109
109
|
this.item = item
|
|
@@ -118,7 +118,7 @@ export default {
|
|
|
118
118
|
},
|
|
119
119
|
|
|
120
120
|
selectPosition (item, direction) {
|
|
121
|
-
|
|
121
|
+
const offsetY = this.options.item.height
|
|
122
122
|
direction = direction || 'down'
|
|
123
123
|
// console.log('selectPosition', this.ui.body, direction)
|
|
124
124
|
|
|
@@ -126,12 +126,12 @@ export default {
|
|
|
126
126
|
|
|
127
127
|
// console.log('coord', this.coord)
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
const itemTop = item.offsetTop + this.coord.top - this.ui.body.scrollTop
|
|
130
130
|
|
|
131
131
|
if (direction === 'down' && itemTop + this.options.item.height + offsetY - this.coord.y > this.coord.height) {
|
|
132
132
|
var top = this.ui.body.scrollTop + itemTop - this.coord.height - this.coord.y + this.options.item.height + offsetY
|
|
133
133
|
this.ui.body.scrollTo({
|
|
134
|
-
top
|
|
134
|
+
top,
|
|
135
135
|
left: 0
|
|
136
136
|
// behavior: 'smooth'
|
|
137
137
|
})
|
|
@@ -142,7 +142,7 @@ export default {
|
|
|
142
142
|
// console.lof('scrollTo', top, item)
|
|
143
143
|
this.ui.body.scrollTo({
|
|
144
144
|
left: 0,
|
|
145
|
-
top
|
|
145
|
+
top
|
|
146
146
|
// behavior: 'smooth'
|
|
147
147
|
})
|
|
148
148
|
}
|
|
@@ -150,9 +150,9 @@ export default {
|
|
|
150
150
|
|
|
151
151
|
selectNext (silent) {
|
|
152
152
|
// console.log('selectNext', this.id)
|
|
153
|
-
|
|
153
|
+
const idx = this.dataList.indexOf(this.id)
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
const id = this.dataList[idx + 1]
|
|
156
156
|
|
|
157
157
|
// console.log('id', id)
|
|
158
158
|
|
|
@@ -172,9 +172,9 @@ export default {
|
|
|
172
172
|
|
|
173
173
|
selectPrevious (silent) {
|
|
174
174
|
// console.log('selectPrevious', this.id)
|
|
175
|
-
|
|
175
|
+
const idx = this.dataList.indexOf(this.id)
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
const id = this.dataList[idx - 1]
|
|
178
178
|
|
|
179
179
|
if (id) {
|
|
180
180
|
this.id = id
|
package/src/list/status.js
CHANGED
package/src/list/update.js
CHANGED
|
@@ -9,8 +9,8 @@ export default {
|
|
|
9
9
|
|
|
10
10
|
getUpdatedIndex (id) {
|
|
11
11
|
// console.log('getUpdatedIndex', id)
|
|
12
|
-
|
|
13
|
-
for (
|
|
12
|
+
let index = null
|
|
13
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
14
14
|
// console.log('--', this.data[i][this.dataId], id)
|
|
15
15
|
if (this.data[i][this.dataId] === id) {
|
|
16
16
|
index = i
|
|
@@ -23,9 +23,9 @@ export default {
|
|
|
23
23
|
|
|
24
24
|
getUpdatedInfo (id) {
|
|
25
25
|
// console.log('getUpdatedInfo', id)
|
|
26
|
-
|
|
26
|
+
const index = this.getUpdatedIndex(id)
|
|
27
27
|
// console.log('index', index)
|
|
28
|
-
|
|
28
|
+
const route = this.buildRoute(index + 1, 1)
|
|
29
29
|
// console.log('roote', route)
|
|
30
30
|
fetch(route).then((resp) => {
|
|
31
31
|
return resp.json()
|
|
@@ -50,10 +50,10 @@ export default {
|
|
|
50
50
|
this.dataStore[info[this.dataId]] = info
|
|
51
51
|
|
|
52
52
|
// update item if on the screen
|
|
53
|
-
|
|
53
|
+
const item = this.ui.body.querySelector('[data-id="' + info[this.dataId] + '"]')
|
|
54
54
|
if (item) {
|
|
55
55
|
item.innerHTML = ''
|
|
56
|
-
|
|
56
|
+
const layout = new Layout(this.options.layout.item, item)
|
|
57
57
|
|
|
58
58
|
this.renderInfo(layout, info)
|
|
59
59
|
}
|
package/src/list/virtual.js
CHANGED
|
@@ -39,14 +39,14 @@ function VirtualList (options) {
|
|
|
39
39
|
VirtualList.prototype._renderChunk = function (node, from, number) {
|
|
40
40
|
// console.log('_renderChunk', from, number, this.options.class)
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
const fragment = document.createDocumentFragment()
|
|
43
43
|
fragment.appendChild(this.scroller)
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
let last = from + number
|
|
46
46
|
if (last > this.count) last = this.count
|
|
47
47
|
|
|
48
|
-
for (
|
|
49
|
-
|
|
48
|
+
for (let i = from; i < last; i++) {
|
|
49
|
+
const item = this.render(i)
|
|
50
50
|
|
|
51
51
|
item.style.position = 'absolute'
|
|
52
52
|
item.style.top = i * this.itemHeight + 'px'
|
|
@@ -84,7 +84,7 @@ VirtualList.prototype.set = function (items) {
|
|
|
84
84
|
this.container.innerHTML = ''
|
|
85
85
|
this.container.scrollTop = 0
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
const height = this.itemHeight * this.count
|
|
88
88
|
|
|
89
89
|
this.scroller.style.height = height + 'px'
|
|
90
90
|
|
|
@@ -94,7 +94,7 @@ VirtualList.prototype.set = function (items) {
|
|
|
94
94
|
// console.log('this.itemsByScreen', this.itemsByScreen)
|
|
95
95
|
|
|
96
96
|
// Cache 4 times the number of items that fit in the container viewport
|
|
97
|
-
|
|
97
|
+
let size = this.itemsByScreen * 4
|
|
98
98
|
this._renderChunk(this.container, 0, size)
|
|
99
99
|
|
|
100
100
|
this.size = size
|
|
@@ -102,13 +102,13 @@ VirtualList.prototype.set = function (items) {
|
|
|
102
102
|
// console.log('emit size', size)
|
|
103
103
|
this.emit('size', size)
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
const self = this
|
|
106
|
+
let lastRepaintY
|
|
107
|
+
const maxBuffer = this.itemsByScreen * this.itemHeight
|
|
108
108
|
|
|
109
109
|
function onScroll (e) {
|
|
110
110
|
// console.log('scroll', e.target.scrollTop, height)
|
|
111
|
-
|
|
111
|
+
const scrollTop = e.target.scrollTop
|
|
112
112
|
|
|
113
113
|
// console.log('itemsByScreen', self.itemsByScreen)
|
|
114
114
|
|
|
@@ -124,7 +124,7 @@ VirtualList.prototype.set = function (items) {
|
|
|
124
124
|
|
|
125
125
|
// console.log('itemsByScreen', self.itemsByScreen)
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
let first = parseInt(scrollTop / self.itemHeight) - self.itemsByScreen
|
|
128
128
|
first = first < 0 ? 0 : first
|
|
129
129
|
|
|
130
130
|
size = self.itemsByScreen * 4
|
|
@@ -134,7 +134,7 @@ VirtualList.prototype.set = function (items) {
|
|
|
134
134
|
lastRepaintY = scrollTop
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
const progress = Math.ceil((scrollTop / self.itemHeight) + self.itemsByScreen) - 1
|
|
138
138
|
// console.log('progress', progress)
|
|
139
139
|
self.emit('progress', progress)
|
|
140
140
|
|
|
@@ -160,14 +160,14 @@ VirtualList.prototype.update = function (items) {
|
|
|
160
160
|
this.count = this.items.length
|
|
161
161
|
|
|
162
162
|
// var itemsByScreen = Math.ceil(this.container.offsetHeight / this.itemHeight)
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
const cachedItemsLen = this.itemsByScreen * 4
|
|
164
|
+
const scrollTop = this.container.scrollTop
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
const height = this.itemHeight * this.count
|
|
167
167
|
|
|
168
168
|
this.scroller.style.height = height + 'px'
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
let first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
171
171
|
first = first < 0 ? 0 : first
|
|
172
172
|
|
|
173
173
|
// console.log('first', first, cachedItemsLen)
|
|
@@ -183,7 +183,7 @@ VirtualList.prototype.add = function (items) {
|
|
|
183
183
|
|
|
184
184
|
this.count = this.items.length
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
const height = this.itemHeight * this.count
|
|
187
187
|
|
|
188
188
|
this.scroller.style.height = height + 'px'
|
|
189
189
|
}
|
|
@@ -212,10 +212,10 @@ VirtualList.prototype.setOffset = function (info) {
|
|
|
212
212
|
|
|
213
213
|
// console.log('new itemsByScreen', this.itemsByScreen)
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
const itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
216
216
|
|
|
217
217
|
// Cache 4 times the number of items that fit in the container viewport
|
|
218
|
-
|
|
218
|
+
const size = itemsByScreen * 4
|
|
219
219
|
|
|
220
220
|
return size
|
|
221
221
|
}
|
|
@@ -227,7 +227,7 @@ VirtualList.prototype.getCount = function () {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
VirtualList.createScroller = function () {
|
|
230
|
-
|
|
230
|
+
const scroller = document.createElement('div')
|
|
231
231
|
scroller.classList.add('scroller')
|
|
232
232
|
return scroller
|
|
233
233
|
}
|
package/src/list/virtual.new.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// based on https://sergimansilla.com/blog/virtual-scrolling/
|
|
2
2
|
|
|
3
3
|
// Import necessary modules
|
|
4
|
-
import passiveEvents from '../module/passive'
|
|
5
|
-
import emitter from '../module/emitter'
|
|
4
|
+
import passiveEvents from '../module/passive' // Import the passiveEvents utility.
|
|
5
|
+
import emitter from '../module/emitter' // Import the emitter module.
|
|
6
6
|
|
|
7
7
|
// Define the VirtualList class
|
|
8
8
|
class VirtualList {
|
|
9
9
|
constructor (options) {
|
|
10
10
|
// Initialize the class with options passed to the constructor.
|
|
11
|
-
this.options = { ...(options || {}) }
|
|
12
|
-
Object.assign(this, emitter)
|
|
11
|
+
this.options = { ...(options || {}) } // Spread operator to merge options with default values.
|
|
12
|
+
Object.assign(this, emitter) // Assign emitter methods to the instance.
|
|
13
13
|
|
|
14
14
|
// Destructure options for easier access to properties.
|
|
15
15
|
const { itemHeight = 0, size = 0, items = [], render, container } = options
|
|
@@ -103,7 +103,7 @@ class VirtualList {
|
|
|
103
103
|
// Add a scroll event listener to render items dynamically.
|
|
104
104
|
const onScroll = (e) => {
|
|
105
105
|
const scrollTop = e.target.scrollTop
|
|
106
|
-
|
|
106
|
+
const first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
107
107
|
|
|
108
108
|
size = this.itemsByScreen * 4
|
|
109
109
|
|