@bildvitta/quasar-ui-asteroid 2.23.0-beta.4 → 2.23.0-beta.7
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/components/search-box/QasSearchBox.stories.js +4 -0
- package/src/components/search-box/QasSearchBox.vue +1 -1
- package/src/components/select/QasSelect.stories.js +4 -0
- package/src/components/select/QasSelect.vue +28 -19
- package/src/components/select-list/QasSelectList.vue +15 -13
- package/src/mixins/lazy-loading-filter.js +33 -27
package/package.json
CHANGED
|
@@ -12,16 +12,19 @@
|
|
|
12
12
|
</slot>
|
|
13
13
|
</template>
|
|
14
14
|
|
|
15
|
+
<template #hint>
|
|
16
|
+
<slot name="hint">
|
|
17
|
+
<div v-if="isLoading" class="q-pb-sm">
|
|
18
|
+
Buscando por opções...
|
|
19
|
+
</div>
|
|
20
|
+
</slot>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
15
23
|
<template #no-option>
|
|
16
|
-
<slot name="no-option">
|
|
24
|
+
<slot v-if="!isLoading" name="no-option">
|
|
17
25
|
<q-item>
|
|
18
26
|
<q-item-section class="text-grey">
|
|
19
|
-
|
|
20
|
-
Buscando por {{ label }}...
|
|
21
|
-
</template>
|
|
22
|
-
<template v-else>
|
|
23
|
-
{{ noOptionLabel }}
|
|
24
|
-
</template>
|
|
27
|
+
{{ noOptionLabel }}
|
|
25
28
|
</q-item-section>
|
|
26
29
|
</q-item>
|
|
27
30
|
</slot>
|
|
@@ -98,10 +101,6 @@ export default {
|
|
|
98
101
|
}
|
|
99
102
|
},
|
|
100
103
|
|
|
101
|
-
label () {
|
|
102
|
-
return this.$attrs.label || ''
|
|
103
|
-
},
|
|
104
|
-
|
|
105
104
|
listeners () {
|
|
106
105
|
const { input, ...events } = this.$listeners
|
|
107
106
|
|
|
@@ -148,19 +147,23 @@ export default {
|
|
|
148
147
|
return this.hasFetchError || this.$attrs.error
|
|
149
148
|
},
|
|
150
149
|
|
|
150
|
+
hasLoading () {
|
|
151
|
+
return this.isLoading || this.$attrs.loading
|
|
152
|
+
},
|
|
153
|
+
|
|
151
154
|
attributes () {
|
|
152
155
|
return {
|
|
156
|
+
bottomSlots: true,
|
|
153
157
|
emitValue: true,
|
|
154
158
|
mapOptions: true,
|
|
155
159
|
outlined: true,
|
|
156
160
|
clearable: this.isSearchable,
|
|
157
|
-
loading: this.isLoading,
|
|
158
161
|
inputDebounce: this.useLazyLoading ? 500 : 0,
|
|
159
|
-
popupContentClass: this.$_virtualScrollClassName,
|
|
160
162
|
...this.$attrs,
|
|
161
163
|
options: this.filteredOptions,
|
|
162
164
|
useInput: this.isSearchable,
|
|
163
|
-
error: this.hasError
|
|
165
|
+
error: this.hasError,
|
|
166
|
+
loading: this.hasLoading
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
},
|
|
@@ -189,15 +192,21 @@ export default {
|
|
|
189
192
|
const Fuse = (await import('fuse.js')).default
|
|
190
193
|
this.fuse = new Fuse(this.defaultOptions, this.defaultFuseOptions)
|
|
191
194
|
}
|
|
195
|
+
|
|
196
|
+
this.useLazyLoading && this.$_setFetchOptions('')
|
|
192
197
|
},
|
|
193
198
|
|
|
194
199
|
methods: {
|
|
195
|
-
onFilter (value, update) {
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
async onFilter (value, update) {
|
|
201
|
+
if (this.useLazyLoading && value !== this.search) {
|
|
202
|
+
await this.$_filterOptionsByStore(value)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!this.useLazyLoading && this.searchable) {
|
|
206
|
+
this.filterOptionsByFuse(value)
|
|
207
|
+
}
|
|
198
208
|
|
|
199
|
-
|
|
200
|
-
})
|
|
209
|
+
update()
|
|
201
210
|
},
|
|
202
211
|
|
|
203
212
|
filterOptionsByFuse (value) {
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<qas-search-box v-bind="$attrs" class="q-pa-md" :fuse-options="fuseOptions" :list="sortedOptions">
|
|
3
3
|
<template #default="{ results }">
|
|
4
|
-
<q-
|
|
5
|
-
<
|
|
6
|
-
<slot name="item
|
|
7
|
-
<
|
|
8
|
-
<
|
|
4
|
+
<q-list separator>
|
|
5
|
+
<q-item v-for="(item, index) in results" :key="index">
|
|
6
|
+
<slot name="item" v-bind="self">
|
|
7
|
+
<slot name="item-section" :result="item">
|
|
8
|
+
<q-item-section class="items-start text-bold">
|
|
9
|
+
<div :class="labelClass" @click="redirectRoute(item)">{{ item.label }}</div>
|
|
10
|
+
</q-item-section>
|
|
11
|
+
</slot>
|
|
12
|
+
|
|
13
|
+
<q-item-section avatar>
|
|
14
|
+
<slot name="item-action" v-bind="self">
|
|
15
|
+
<qas-btn hide-mobile-label v-bind="setButtonProps(item)" size="sm" @click="handleClick(item)" />
|
|
16
|
+
</slot>
|
|
9
17
|
</q-item-section>
|
|
10
18
|
</slot>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<slot name="item-action" v-bind="self">
|
|
14
|
-
<qas-btn hide-mobile-label v-bind="setButtonProps(item)" size="sm" @click="handleClick(item)" />
|
|
15
|
-
</slot>
|
|
16
|
-
</q-item-section>
|
|
17
|
-
</slot>
|
|
18
|
-
</q-item>
|
|
19
|
+
</q-item>
|
|
20
|
+
</q-list>
|
|
19
21
|
</template>
|
|
20
22
|
</qas-search-box>
|
|
21
23
|
</template>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { decamelize } from 'humps'
|
|
2
|
+
import { isEqual } from 'lodash'
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
props: {
|
|
@@ -30,9 +31,11 @@ export default {
|
|
|
30
31
|
isScrolling: false,
|
|
31
32
|
pagination: {
|
|
32
33
|
page: 1,
|
|
33
|
-
lastPage: null
|
|
34
|
+
lastPage: null,
|
|
35
|
+
hasCount: true,
|
|
36
|
+
hasNextPage: false
|
|
34
37
|
},
|
|
35
|
-
search:
|
|
38
|
+
search: ''
|
|
36
39
|
}
|
|
37
40
|
},
|
|
38
41
|
|
|
@@ -60,10 +63,17 @@ export default {
|
|
|
60
63
|
|
|
61
64
|
$_hasFilteredOptions () {
|
|
62
65
|
return !!this.filteredOptions.length
|
|
63
|
-
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
watch: {
|
|
70
|
+
lazyLoadingProps: {
|
|
71
|
+
handler (value, oldValue) {
|
|
72
|
+
if (isEqual(value, oldValue)) return
|
|
73
|
+
|
|
74
|
+
this.$_filterOptionsByStore('')
|
|
75
|
+
this.$emit('input', '')
|
|
76
|
+
}
|
|
67
77
|
}
|
|
68
78
|
},
|
|
69
79
|
|
|
@@ -78,21 +88,22 @@ export default {
|
|
|
78
88
|
this.search = search
|
|
79
89
|
this.pagination = {
|
|
80
90
|
page: 1,
|
|
81
|
-
lastPage: null
|
|
91
|
+
lastPage: null,
|
|
92
|
+
hasCount: true,
|
|
93
|
+
hasNextPage: false
|
|
82
94
|
}
|
|
83
95
|
},
|
|
84
96
|
|
|
85
|
-
async $_onVirtualScroll ({ index }) {
|
|
97
|
+
async $_onVirtualScroll ({ index, ref }) {
|
|
86
98
|
const lastIndex = this.filteredOptions.length - 1
|
|
87
99
|
|
|
88
100
|
if (index === lastIndex && this.$_canFetchOptions()) {
|
|
89
|
-
const { scrollContainer, top } = this.$_getScrollContainerTop()
|
|
90
|
-
|
|
91
101
|
await this.$_loadMoreOptions()
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
this.$nextTick(() => {
|
|
104
|
+
ref.reset()
|
|
105
|
+
ref.refresh(lastIndex)
|
|
106
|
+
})
|
|
96
107
|
}
|
|
97
108
|
},
|
|
98
109
|
|
|
@@ -114,7 +125,9 @@ export default {
|
|
|
114
125
|
if (!this.name) throw new Error(this.$_getMissingPropsMessage('name'))
|
|
115
126
|
|
|
116
127
|
this.hasFetchError = false
|
|
128
|
+
|
|
117
129
|
this.isLoading = true
|
|
130
|
+
this.$emit('fetching', true)
|
|
118
131
|
|
|
119
132
|
const { url, params, decamelizeFieldName } = this.$_defaultLazyLoadingProps
|
|
120
133
|
|
|
@@ -128,11 +141,14 @@ export default {
|
|
|
128
141
|
}
|
|
129
142
|
})
|
|
130
143
|
|
|
131
|
-
const { results, count } = data
|
|
144
|
+
const { results, count, hasNextPage } = data
|
|
145
|
+
const hasCount = count !== undefined
|
|
132
146
|
|
|
133
147
|
this.pagination = {
|
|
134
148
|
page: this.pagination.page + 1,
|
|
135
|
-
lastPage: Math.ceil(count / params.limit)
|
|
149
|
+
lastPage: hasCount ? Math.ceil(count / params.limit) : null,
|
|
150
|
+
hasCount,
|
|
151
|
+
hasNextPage
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
this.$emit('fetch-options-success', data)
|
|
@@ -148,6 +164,7 @@ export default {
|
|
|
148
164
|
return []
|
|
149
165
|
} finally {
|
|
150
166
|
this.isLoading = false
|
|
167
|
+
this.$emit('fetching', false)
|
|
151
168
|
}
|
|
152
169
|
},
|
|
153
170
|
|
|
@@ -156,23 +173,12 @@ export default {
|
|
|
156
173
|
},
|
|
157
174
|
|
|
158
175
|
$_canFetchOptions () {
|
|
159
|
-
const { lastPage, page } = this.pagination
|
|
160
|
-
const hasMorePages = lastPage && page <= lastPage
|
|
176
|
+
const { lastPage, page, hasCount, hasNextPage } = this.pagination
|
|
177
|
+
const hasMorePages = hasCount ? lastPage && page <= lastPage : hasNextPage
|
|
161
178
|
|
|
162
179
|
return hasMorePages && !this.isLoading && !this.isScrolling && this.useLazyLoading
|
|
163
180
|
},
|
|
164
181
|
|
|
165
|
-
$_getScrollContainerTop () {
|
|
166
|
-
const scrollContainer = document.querySelector(`.${this.$_virtualScrollClassName}`)
|
|
167
|
-
const scrollContainerHeight = scrollContainer.offsetHeight
|
|
168
|
-
const scrollContainerTop = scrollContainer.scrollTop
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
scrollContainer,
|
|
172
|
-
top: scrollContainerTop + (scrollContainerHeight / 2)
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
|
|
176
182
|
$_handleOptions (options) {
|
|
177
183
|
if (this.labelKey && this.valueKey && this.renameKey) {
|
|
178
184
|
return options.map(item => this.renameKey(item))
|