material 0.9.20 → 0.9.21
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/package.json +1 -1
- package/src/class/component.js +1 -1
- package/src/datehour.js +17 -12
- package/src/module/dom.js +0 -1
- package/src/module/layout.js +1 -1
- package/src/slider-new.js +341 -0
- package/src/switch.js +5 -7
- package/src/switcher.js +10 -10
- package/src/text.js +1 -1
- package/src/textfield.js +2 -1
- package/src/list.new/build.js +0 -139
- package/src/list.new/click.js +0 -40
- package/src/list.new/collection.js +0 -30
- package/src/list.new/create.js +0 -45
- package/src/list.new/data.js +0 -16
- package/src/list.new/display.js +0 -78
- package/src/list.new/empty.js +0 -9
- package/src/list.new/filter.js +0 -114
- package/src/list.new/image.js +0 -19
- package/src/list.new/init.js +0 -6
- package/src/list.new/load.js +0 -9
- package/src/list.new/remove.js +0 -22
- package/src/list.new/render.js +0 -142
- package/src/list.new/request.js +0 -216
- package/src/list.new/search.js +0 -155
- package/src/list.new/select.js +0 -221
- package/src/list.new/status.js +0 -21
- package/src/list.new/update.js +0 -75
- package/src/list.new/virtual.js +0 -186
- package/src/list.new/virtual.new.js +0 -213
package/src/list.new/virtual.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
// based on https://sergimansilla.com/blog/virtual-scrolling/
|
|
2
|
-
|
|
3
|
-
// Import necessary modules
|
|
4
|
-
import passiveEvents from '../module/passive' // Import the passiveEvents utility.
|
|
5
|
-
import emitter from '../module/emitter' // Import the emitter module.
|
|
6
|
-
|
|
7
|
-
// Define the VirtualList class
|
|
8
|
-
class VirtualList {
|
|
9
|
-
constructor (options) {
|
|
10
|
-
// Initialize the class with options passed to the constructor.
|
|
11
|
-
this.options = { ...(options || {}) } // Spread operator to merge options with default values.
|
|
12
|
-
Object.assign(this, emitter) // Assign emitter methods to the instance.
|
|
13
|
-
|
|
14
|
-
// Destructure options for easier access to properties.
|
|
15
|
-
const { itemHeight = 0, size = 0, items = [], render, container } = options
|
|
16
|
-
|
|
17
|
-
// Initialize instance variables with default or provided values.
|
|
18
|
-
this.itemHeight = itemHeight
|
|
19
|
-
this.next = false
|
|
20
|
-
this.size = size
|
|
21
|
-
this.chunkSize = size
|
|
22
|
-
this.items = items
|
|
23
|
-
this.render = render
|
|
24
|
-
this.scroller = VirtualList.createScroller()
|
|
25
|
-
this.container = container
|
|
26
|
-
|
|
27
|
-
// Add 'virtual' class to the container element.
|
|
28
|
-
this.container.classList.add('virtual')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Method to render a chunk of items within the visible range.
|
|
32
|
-
renderChunk (node, from, number) {
|
|
33
|
-
console.error('renderChunck', from, number)
|
|
34
|
-
const fragment = document.createDocumentFragment()
|
|
35
|
-
fragment.appendChild(this.scroller)
|
|
36
|
-
|
|
37
|
-
let last = from + number
|
|
38
|
-
if (last > this.count) last = this.count
|
|
39
|
-
|
|
40
|
-
for (let i = from; i < last; i++) {
|
|
41
|
-
const item = this.render(i)
|
|
42
|
-
|
|
43
|
-
// Position the item absolutely based on its index and item height.
|
|
44
|
-
item.style.position = 'absolute'
|
|
45
|
-
item.style.top = i * this.itemHeight + 'px'
|
|
46
|
-
if (i === last) item.classList.add('last')
|
|
47
|
-
fragment.appendChild(item)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
node.innerHTML = ''
|
|
51
|
-
node.appendChild(fragment)
|
|
52
|
-
|
|
53
|
-
// Emit 'next' event if applicable.
|
|
54
|
-
// console.log('last', last)
|
|
55
|
-
// console.log('count', this.count)
|
|
56
|
-
// console.log('next', this.next)
|
|
57
|
-
// console.log('size', this.size)
|
|
58
|
-
|
|
59
|
-
if (this.next && last && last > (this.count - this.size / 2)) {
|
|
60
|
-
this.emit('next', this.count)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.next = true
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Method to set the items and render the initial chunk.
|
|
67
|
-
set (items, info) {
|
|
68
|
-
console.error('set', items, info.page, info.size)
|
|
69
|
-
|
|
70
|
-
this.next = false
|
|
71
|
-
this.items = items
|
|
72
|
-
this.count = items.length
|
|
73
|
-
|
|
74
|
-
if (this.count < 1 || this.count === undefined) return
|
|
75
|
-
|
|
76
|
-
// this.container.innerHTML = ''
|
|
77
|
-
// this.container.scrollTop = 0
|
|
78
|
-
|
|
79
|
-
this.itemsByScreen = info.size / 2
|
|
80
|
-
|
|
81
|
-
let size = this.itemsByScreen * 4
|
|
82
|
-
this.renderChunk(this.container, (info.page - 1) * size, size)
|
|
83
|
-
|
|
84
|
-
this.size = size
|
|
85
|
-
|
|
86
|
-
this.emit('size', size)
|
|
87
|
-
|
|
88
|
-
let lastRepaintY
|
|
89
|
-
const maxBuffer = this.itemsByScreen * this.itemHeight
|
|
90
|
-
|
|
91
|
-
// Add a scroll event listener to render items dynamically.
|
|
92
|
-
const onScroll = (e) => {
|
|
93
|
-
const scrollTop = e.target.scrollTop
|
|
94
|
-
console.log('scrollTop', scrollTop)
|
|
95
|
-
const first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
96
|
-
|
|
97
|
-
size = this.itemsByScreen * 4
|
|
98
|
-
|
|
99
|
-
if (!lastRepaintY || Math.abs(scrollTop - lastRepaintY) > maxBuffer) {
|
|
100
|
-
this.renderChunk(this.container, first, size)
|
|
101
|
-
lastRepaintY = scrollTop
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const progress = Math.ceil((scrollTop / this.itemHeight) + this.itemsByScreen) - 1
|
|
105
|
-
this.emit('progress', progress)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!this.scrollEvents) {
|
|
109
|
-
// Add scroll event listener with passive option if supported.
|
|
110
|
-
this.container.addEventListener(
|
|
111
|
-
'scroll',
|
|
112
|
-
onScroll,
|
|
113
|
-
passiveEvents() ? { passive: true } : false
|
|
114
|
-
)
|
|
115
|
-
this.scrollEvents = true
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Method to add items and update the container height.
|
|
120
|
-
add (items, info) {
|
|
121
|
-
console.error('add', items.length, info)
|
|
122
|
-
this.items = items || this.items
|
|
123
|
-
|
|
124
|
-
if (!this.items) return
|
|
125
|
-
|
|
126
|
-
this.count = this.items.length
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Method to update the items and re-render the visible chunk.
|
|
130
|
-
update (items) {
|
|
131
|
-
console.error('update', items.length)
|
|
132
|
-
this.items = items || this.items
|
|
133
|
-
|
|
134
|
-
if (!this.items) return
|
|
135
|
-
|
|
136
|
-
this.count = this.items.length
|
|
137
|
-
const cachedItemsLen = this.itemsByScreen * 4
|
|
138
|
-
const scrollTop = this.container.scrollTop
|
|
139
|
-
const height = this.itemHeight * this.count
|
|
140
|
-
|
|
141
|
-
// this.scroller.style.height = height + 'px'
|
|
142
|
-
|
|
143
|
-
let first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
144
|
-
first = first < 0 ? 0 : first
|
|
145
|
-
|
|
146
|
-
this.renderChunk(this.container, first, cachedItemsLen)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Method to reset the items and container to an initial state.
|
|
150
|
-
reset () {
|
|
151
|
-
console.log('reset')
|
|
152
|
-
this.items = []
|
|
153
|
-
this.count = 0
|
|
154
|
-
|
|
155
|
-
this.container.scrollTop = 0
|
|
156
|
-
|
|
157
|
-
this.scroller.style.height = '0'
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
setCount (count) {
|
|
161
|
-
console.log('setCount', count, this.itemHeight)
|
|
162
|
-
this.totalCount = count
|
|
163
|
-
const height = this.itemHeight * count
|
|
164
|
-
|
|
165
|
-
this.container.height = height + 'px'
|
|
166
|
-
|
|
167
|
-
console.log('scroller height', height)
|
|
168
|
-
this.scroller.style.height = height + 'px'
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Method to get the total count of items.
|
|
172
|
-
getCount () {
|
|
173
|
-
console.log('getCount', this.totalCount)
|
|
174
|
-
return this.totalCount
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Static method to create a scroller element.
|
|
178
|
-
static createScroller () {
|
|
179
|
-
const scroller = document.createElement('div')
|
|
180
|
-
scroller.classList.add('scroller')
|
|
181
|
-
return scroller
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Export the VirtualList class as the default export.
|
|
186
|
-
export default VirtualList
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
// based on https://sergimansilla.com/blog/virtual-scrolling/
|
|
2
|
-
|
|
3
|
-
// Import necessary modules
|
|
4
|
-
import passiveEvents from '../module/passive' // Import the passiveEvents utility.
|
|
5
|
-
import emitter from '../module/emitter' // Import the emitter module.
|
|
6
|
-
|
|
7
|
-
// Define the VirtualList class
|
|
8
|
-
class VirtualList {
|
|
9
|
-
constructor (options) {
|
|
10
|
-
// Initialize the class with options passed to the constructor.
|
|
11
|
-
this.options = { ...(options || {}) } // Spread operator to merge options with default values.
|
|
12
|
-
Object.assign(this, emitter) // Assign emitter methods to the instance.
|
|
13
|
-
|
|
14
|
-
// Destructure options for easier access to properties.
|
|
15
|
-
const { itemHeight = 0, size = 0, items = [], render, container } = options
|
|
16
|
-
|
|
17
|
-
// Initialize instance variables with default or provided values.
|
|
18
|
-
this.itemHeight = itemHeight
|
|
19
|
-
this.next = false
|
|
20
|
-
this.size = size
|
|
21
|
-
this.chunkSize = size
|
|
22
|
-
this.items = items
|
|
23
|
-
this.render = render
|
|
24
|
-
this.scroller = VirtualList.createScroller()
|
|
25
|
-
this.container = container
|
|
26
|
-
|
|
27
|
-
// Get the offset height of the container.
|
|
28
|
-
this.setOffset()
|
|
29
|
-
|
|
30
|
-
// Add a window resize event listener to update the offset height.
|
|
31
|
-
window.addEventListener('resize', () => {
|
|
32
|
-
clearTimeout(this.resizeTimeout)
|
|
33
|
-
|
|
34
|
-
this.resizeTimeout = setTimeout(() => {
|
|
35
|
-
this.setOffset()
|
|
36
|
-
}, 50)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
// Add 'virtual' class to the container element.
|
|
40
|
-
this.container.classList.add('virtual')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Method to render a chunk of items within the visible range.
|
|
44
|
-
renderChunk (node, from, number) {
|
|
45
|
-
const fragment = document.createDocumentFragment()
|
|
46
|
-
fragment.appendChild(this.scroller)
|
|
47
|
-
|
|
48
|
-
let last = from + number
|
|
49
|
-
if (last > this.count) last = this.count
|
|
50
|
-
|
|
51
|
-
for (let i = from; i < last; i++) {
|
|
52
|
-
const item = this.render(i)
|
|
53
|
-
|
|
54
|
-
// Position the item absolutely based on its index and item height.
|
|
55
|
-
item.style.position = 'absolute'
|
|
56
|
-
item.style.top = i * this.itemHeight + 'px'
|
|
57
|
-
fragment.appendChild(item)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
node.innerHTML = ''
|
|
61
|
-
node.appendChild(fragment)
|
|
62
|
-
|
|
63
|
-
// Emit 'next' event if applicable.
|
|
64
|
-
// console.log('last', last)
|
|
65
|
-
// console.log('count', this.count)
|
|
66
|
-
// console.log('next', this.next)
|
|
67
|
-
// console.log('size', this.size)
|
|
68
|
-
|
|
69
|
-
if (this.next && last && last > (this.count - this.size / 2)) {
|
|
70
|
-
this.emit('next', this.count)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.next = true
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Method to set the items and render the initial chunk.
|
|
77
|
-
set (items) {
|
|
78
|
-
this.next = false
|
|
79
|
-
this.items = items
|
|
80
|
-
this.count = items.length
|
|
81
|
-
|
|
82
|
-
if (this.count < 1 || this.count === undefined) return
|
|
83
|
-
|
|
84
|
-
this.container.innerHTML = ''
|
|
85
|
-
this.container.scrollTop = 0
|
|
86
|
-
|
|
87
|
-
const height = this.itemHeight * this.count
|
|
88
|
-
|
|
89
|
-
this.scroller.style.height = height + 'px'
|
|
90
|
-
|
|
91
|
-
this.itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
92
|
-
|
|
93
|
-
let size = this.itemsByScreen * 4
|
|
94
|
-
this.renderChunk(this.container, 0, size)
|
|
95
|
-
|
|
96
|
-
this.size = size
|
|
97
|
-
|
|
98
|
-
this.emit('size', size)
|
|
99
|
-
|
|
100
|
-
let lastRepaintY
|
|
101
|
-
const maxBuffer = this.itemsByScreen * this.itemHeight
|
|
102
|
-
|
|
103
|
-
// Add a scroll event listener to render items dynamically.
|
|
104
|
-
const onScroll = (e) => {
|
|
105
|
-
const scrollTop = e.target.scrollTop
|
|
106
|
-
const first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
107
|
-
|
|
108
|
-
size = this.itemsByScreen * 4
|
|
109
|
-
|
|
110
|
-
if (!lastRepaintY || Math.abs(scrollTop - lastRepaintY) > maxBuffer) {
|
|
111
|
-
this.renderChunk(this.container, first, size)
|
|
112
|
-
lastRepaintY = scrollTop
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const progress = Math.ceil((scrollTop / this.itemHeight) + this.itemsByScreen) - 1
|
|
116
|
-
this.emit('progress', progress)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!this.scrollEvents) {
|
|
120
|
-
// Add scroll event listener with passive option if supported.
|
|
121
|
-
this.container.addEventListener(
|
|
122
|
-
'scroll',
|
|
123
|
-
onScroll,
|
|
124
|
-
passiveEvents() ? { passive: true } : false
|
|
125
|
-
)
|
|
126
|
-
this.scrollEvents = true
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Method to update the items and re-render the visible chunk.
|
|
131
|
-
update (items) {
|
|
132
|
-
this.items = items || this.items
|
|
133
|
-
|
|
134
|
-
if (!this.items) return
|
|
135
|
-
|
|
136
|
-
this.count = this.items.length
|
|
137
|
-
const cachedItemsLen = this.itemsByScreen * 4
|
|
138
|
-
const scrollTop = this.container.scrollTop
|
|
139
|
-
const height = this.itemHeight * this.count
|
|
140
|
-
|
|
141
|
-
this.scroller.style.height = height + 'px'
|
|
142
|
-
|
|
143
|
-
let first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
144
|
-
first = first < 0 ? 0 : first
|
|
145
|
-
|
|
146
|
-
this.renderChunk(this.container, first, cachedItemsLen)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Method to add items and update the container height.
|
|
150
|
-
add (items) {
|
|
151
|
-
this.items = items || this.items
|
|
152
|
-
|
|
153
|
-
if (!this.items) return
|
|
154
|
-
|
|
155
|
-
this.count = this.items.length
|
|
156
|
-
const height = this.itemHeight * this.count
|
|
157
|
-
|
|
158
|
-
this.scroller.style.height = height + 'px'
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Method to reset the items and container to an initial state.
|
|
162
|
-
reset () {
|
|
163
|
-
this.items = []
|
|
164
|
-
this.count = 0
|
|
165
|
-
|
|
166
|
-
this.container.scrollTop = 0
|
|
167
|
-
|
|
168
|
-
this.scroller.style.height = '0'
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Method to set the offset height of the container.
|
|
172
|
-
setOffset (info) {
|
|
173
|
-
this.offsetHeight = this.container.offsetHeight
|
|
174
|
-
if (this.offsetHeight < 1) {
|
|
175
|
-
this.offsetHeight = window.innerHeight ||
|
|
176
|
-
document.documentElement.clientHeight ||
|
|
177
|
-
document.body.clientHeight
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
this.itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
181
|
-
|
|
182
|
-
const itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
183
|
-
const size = itemsByScreen * 4
|
|
184
|
-
|
|
185
|
-
return size
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
setCount = function (count) {
|
|
189
|
-
console.error('setCount', count)
|
|
190
|
-
this.count = count
|
|
191
|
-
const height = this.itemHeight * this.count
|
|
192
|
-
|
|
193
|
-
this.container.height = height + 'px'
|
|
194
|
-
|
|
195
|
-
// console.log('scroller height', height)
|
|
196
|
-
this.scroller.style.height = height + 'px'
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Method to get the total count of items.
|
|
200
|
-
getCount () {
|
|
201
|
-
return this.count
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Static method to create a scroller element.
|
|
205
|
-
static createScroller () {
|
|
206
|
-
const scroller = document.createElement('div')
|
|
207
|
-
scroller.classList.add('scroller')
|
|
208
|
-
return scroller
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Export the VirtualList class as the default export.
|
|
213
|
-
export default VirtualList
|