sprintify-ui 0.0.162 → 0.0.164
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/dist/sprintify-ui.es.js +5237 -5219
- package/dist/types/src/components/BaseBadge.vue.d.ts +4 -4
- package/dist/types/src/components/BaseDataIterator.vue.d.ts +4 -4
- package/dist/types/src/composables/paginatedData.d.ts +7 -0
- package/package.json +1 -1
- package/src/components/BaseAutocompleteFetch.vue +26 -15
- package/src/components/BaseBadge.vue +2 -2
- package/src/components/BaseDataIterator.vue +4 -48
- package/src/components/BaseDataTable.stories.js +0 -1
- package/src/components/BaseTagAutocompleteFetch.vue +32 -14
- package/src/composables/paginatedData.ts +65 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
2
|
-
contrast
|
|
3
|
-
color
|
|
2
|
+
contrast?: "high" | "low" | undefined;
|
|
3
|
+
color?: string | undefined;
|
|
4
4
|
size?: "base" | "sm" | "lg" | undefined;
|
|
5
5
|
icon?: string | undefined;
|
|
6
6
|
}>, {
|
|
@@ -9,8 +9,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
9
9
|
size: string;
|
|
10
10
|
icon: undefined;
|
|
11
11
|
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
12
|
-
contrast
|
|
13
|
-
color
|
|
12
|
+
contrast?: "high" | "low" | undefined;
|
|
13
|
+
color?: string | undefined;
|
|
14
14
|
size?: "base" | "sm" | "lg" | undefined;
|
|
15
15
|
icon?: string | undefined;
|
|
16
16
|
}>, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropType } from 'vue';
|
|
2
|
-
import { DataTableQuery, MenuItemInterface
|
|
2
|
+
import { Collection, DataTableQuery, MenuItemInterface } from '@/types';
|
|
3
3
|
type Direction = 'asc' | 'desc';
|
|
4
4
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
5
5
|
/**
|
|
@@ -120,7 +120,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
120
120
|
historyMode: boolean;
|
|
121
121
|
}>, {
|
|
122
122
|
default: (_: {
|
|
123
|
-
items:
|
|
123
|
+
items: Collection;
|
|
124
124
|
loading: boolean;
|
|
125
125
|
error: boolean;
|
|
126
126
|
firstLoad: boolean;
|
|
@@ -131,7 +131,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
131
131
|
onPageChange: (p: number) => void;
|
|
132
132
|
}) => any;
|
|
133
133
|
sidebarTop: (_: {
|
|
134
|
-
paginationMetadata: PaginationMetadata | null;
|
|
134
|
+
paginationMetadata: import("@/types").PaginationMetadata | null;
|
|
135
135
|
}) => any;
|
|
136
136
|
filters: (_: {
|
|
137
137
|
query: {
|
|
@@ -145,7 +145,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
145
145
|
updateQueryValue: (key: string, value: any) => void;
|
|
146
146
|
}) => any;
|
|
147
147
|
sidebarBottom: (_: {
|
|
148
|
-
paginationMetadata: PaginationMetadata | null;
|
|
148
|
+
paginationMetadata: import("@/types").PaginationMetadata | null;
|
|
149
149
|
}) => any;
|
|
150
150
|
}>;
|
|
151
151
|
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { Collection, PaginatedCollection, ResourceCollection, PaginationMetadata } from '@/types';
|
|
3
|
+
export declare function useHasPaginatedData(data: Ref<Collection | PaginatedCollection | ResourceCollection | null>): {
|
|
4
|
+
items: import("vue").ComputedRef<Collection>;
|
|
5
|
+
paginationMetadata: import("vue").ComputedRef<PaginationMetadata | null>;
|
|
6
|
+
lastPage: import("vue").ComputedRef<number>;
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -52,8 +52,15 @@
|
|
|
52
52
|
import { config } from '@/index';
|
|
53
53
|
import { debounce, throttle } from 'lodash';
|
|
54
54
|
import { PropType } from 'vue';
|
|
55
|
-
import {
|
|
55
|
+
import {
|
|
56
|
+
Collection,
|
|
57
|
+
Option,
|
|
58
|
+
PaginatedCollection,
|
|
59
|
+
ResourceCollection,
|
|
60
|
+
SelectConfiguration,
|
|
61
|
+
} from '@/types';
|
|
56
62
|
import BaseAutocomplete from './BaseAutocomplete.vue';
|
|
63
|
+
import { useHasPaginatedData } from '@/composables/paginatedData';
|
|
57
64
|
|
|
58
65
|
/**
|
|
59
66
|
* Behavior notes
|
|
@@ -150,16 +157,20 @@ const emit = defineEmits([
|
|
|
150
157
|
const showLoading = ref(false);
|
|
151
158
|
const fetching = ref(false);
|
|
152
159
|
const firstSearch = ref(false);
|
|
153
|
-
const reachedEnd = ref(false);
|
|
154
160
|
const keywords = ref('');
|
|
155
161
|
const page = ref(1);
|
|
156
162
|
const options = ref<Option[]>([]);
|
|
157
163
|
|
|
164
|
+
const data = ref<null | ResourceCollection | PaginatedCollection | Collection>(
|
|
165
|
+
null
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const { items, lastPage } = useHasPaginatedData(data);
|
|
169
|
+
|
|
158
170
|
const autocomplete = ref<InstanceType<typeof BaseAutocomplete> | null>(null);
|
|
159
171
|
|
|
160
172
|
const onTyping = (query: string) => {
|
|
161
173
|
page.value = 1;
|
|
162
|
-
reachedEnd.value = false;
|
|
163
174
|
keywords.value = query;
|
|
164
175
|
showLoading.value = true;
|
|
165
176
|
debouncedSearch();
|
|
@@ -180,21 +191,22 @@ const onClear = () => {
|
|
|
180
191
|
};
|
|
181
192
|
|
|
182
193
|
const scrollBottom = throttle(() => {
|
|
183
|
-
if (
|
|
194
|
+
if (page.value >= lastPage.value) {
|
|
184
195
|
return;
|
|
185
196
|
}
|
|
186
197
|
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
search();
|
|
198
|
+
if (fetching.value) {
|
|
199
|
+
return;
|
|
190
200
|
}
|
|
201
|
+
|
|
202
|
+
page.value++;
|
|
203
|
+
search();
|
|
191
204
|
}, 500);
|
|
192
205
|
|
|
193
206
|
watch(
|
|
194
207
|
() => props.url,
|
|
195
208
|
() => {
|
|
196
209
|
page.value = 1;
|
|
197
|
-
reachedEnd.value = false;
|
|
198
210
|
search();
|
|
199
211
|
}
|
|
200
212
|
);
|
|
@@ -215,16 +227,15 @@ function search() {
|
|
|
215
227
|
},
|
|
216
228
|
})
|
|
217
229
|
.then((response: any) => {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
230
|
+
data.value = response.data as
|
|
231
|
+
| ResourceCollection
|
|
232
|
+
| PaginatedCollection
|
|
233
|
+
| Collection;
|
|
223
234
|
|
|
224
235
|
if (page.value == 1) {
|
|
225
|
-
options.value =
|
|
236
|
+
options.value = items.value;
|
|
226
237
|
} else {
|
|
227
|
-
options.value.push(...
|
|
238
|
+
options.value.push(...items.value);
|
|
228
239
|
}
|
|
229
240
|
|
|
230
241
|
firstSearch.value = true;
|
|
@@ -213,7 +213,7 @@ const DEFAULT_QUERY = {
|
|
|
213
213
|
</script>
|
|
214
214
|
|
|
215
215
|
<script lang="ts" setup>
|
|
216
|
-
import { cloneDeep, debounce,
|
|
216
|
+
import { cloneDeep, debounce, merge, set } from 'lodash';
|
|
217
217
|
import hash from 'object-hash';
|
|
218
218
|
import { PropType } from 'vue';
|
|
219
219
|
import {
|
|
@@ -221,7 +221,6 @@ import {
|
|
|
221
221
|
DataTableQuery,
|
|
222
222
|
MenuItemInterface,
|
|
223
223
|
PaginatedCollection,
|
|
224
|
-
PaginationMetadata,
|
|
225
224
|
ResourceCollection,
|
|
226
225
|
} from '@/types';
|
|
227
226
|
|
|
@@ -232,6 +231,7 @@ import BasePagination from './BasePagination.vue';
|
|
|
232
231
|
import BaseModalSide from './BaseModalSide.vue';
|
|
233
232
|
import { config } from '@/index';
|
|
234
233
|
import { useMutationObserver, useResizeObserver } from '@vueuse/core';
|
|
234
|
+
import { useHasPaginatedData } from '@/composables/paginatedData';
|
|
235
235
|
|
|
236
236
|
const props = defineProps({
|
|
237
237
|
/**
|
|
@@ -571,6 +571,7 @@ function fetch(force = false, showLoading = true) {
|
|
|
571
571
|
const urlQueryString = urlSplit[1] ?? null;
|
|
572
572
|
const urlQuery = config.parseQueryString(urlQueryString);
|
|
573
573
|
|
|
574
|
+
// Ordered by priority
|
|
574
575
|
const allParams = merge(
|
|
575
576
|
cloneDeep(query.value),
|
|
576
577
|
cloneDeep(props.urlQuery),
|
|
@@ -615,45 +616,7 @@ const data = ref<null | ResourceCollection | PaginatedCollection | Collection>(
|
|
|
615
616
|
null
|
|
616
617
|
);
|
|
617
618
|
|
|
618
|
-
const items =
|
|
619
|
-
if (!data.value) {
|
|
620
|
-
return [];
|
|
621
|
-
}
|
|
622
|
-
if (isArray(data.value)) {
|
|
623
|
-
return data.value;
|
|
624
|
-
}
|
|
625
|
-
return data.value.data;
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
const paginationMetadata = computed<PaginationMetadata | null>(() => {
|
|
629
|
-
const defaultMeta = {
|
|
630
|
-
current_page: 1,
|
|
631
|
-
last_page: 1,
|
|
632
|
-
per_page: 1,
|
|
633
|
-
total: 0,
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
if (!data.value) {
|
|
637
|
-
return defaultMeta;
|
|
638
|
-
}
|
|
639
|
-
if (isArray(data.value)) {
|
|
640
|
-
return defaultMeta;
|
|
641
|
-
}
|
|
642
|
-
if ('meta' in data.value) {
|
|
643
|
-
return data.value.meta;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
if (data.value.current_page) {
|
|
647
|
-
return {
|
|
648
|
-
current_page: data.value.current_page,
|
|
649
|
-
last_page: data.value.last_page,
|
|
650
|
-
per_page: data.value.per_page,
|
|
651
|
-
total: data.value.total,
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
return null;
|
|
656
|
-
});
|
|
619
|
+
const { items, paginationMetadata, lastPage } = useHasPaginatedData(data);
|
|
657
620
|
|
|
658
621
|
const page = computed((): number => {
|
|
659
622
|
if (query.value.page && parseInt(query.value.page + '')) {
|
|
@@ -662,13 +625,6 @@ const page = computed((): number => {
|
|
|
662
625
|
return 1;
|
|
663
626
|
});
|
|
664
627
|
|
|
665
|
-
const lastPage = computed(() => {
|
|
666
|
-
if (!paginationMetadata.value) {
|
|
667
|
-
return 1;
|
|
668
|
-
}
|
|
669
|
-
return paginationMetadata.value.last_page;
|
|
670
|
-
});
|
|
671
|
-
|
|
672
628
|
const sortField = computed((): string => {
|
|
673
629
|
return query.value.sort?.trim().replace(/^(-)/, '') ?? '';
|
|
674
630
|
});
|
|
@@ -39,11 +39,17 @@
|
|
|
39
39
|
</template>
|
|
40
40
|
|
|
41
41
|
<script lang="ts" setup>
|
|
42
|
-
import { debounce, throttle } from 'lodash';
|
|
42
|
+
import { debounce, isArray, throttle } from 'lodash';
|
|
43
43
|
import { config } from '@/index';
|
|
44
44
|
import { PropType } from 'vue';
|
|
45
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
Collection,
|
|
47
|
+
Option,
|
|
48
|
+
PaginatedCollection,
|
|
49
|
+
ResourceCollection,
|
|
50
|
+
} from '@/types';
|
|
46
51
|
import BaseTagAutocomplete from './BaseTagAutocomplete.vue';
|
|
52
|
+
import { useHasPaginatedData } from '@/composables/paginatedData';
|
|
47
53
|
|
|
48
54
|
const props = defineProps({
|
|
49
55
|
modelValue: {
|
|
@@ -99,14 +105,18 @@ const http = config.http;
|
|
|
99
105
|
const showLoading = ref(false);
|
|
100
106
|
const fetching = ref(false);
|
|
101
107
|
const firstSearch = ref(false);
|
|
102
|
-
const reachedEnd = ref(false);
|
|
103
108
|
const keywords = ref('');
|
|
104
109
|
const page = ref(1);
|
|
105
110
|
const options = ref<Option[]>([]);
|
|
106
111
|
|
|
112
|
+
const data = ref<null | ResourceCollection | PaginatedCollection | Collection>(
|
|
113
|
+
null
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const { items, lastPage } = useHasPaginatedData(data);
|
|
117
|
+
|
|
107
118
|
const onTyping = (query: string) => {
|
|
108
119
|
page.value = 1;
|
|
109
|
-
reachedEnd.value = false;
|
|
110
120
|
|
|
111
121
|
if (keywords.value != query) {
|
|
112
122
|
keywords.value = query;
|
|
@@ -122,15 +132,24 @@ const onOpen = () => {
|
|
|
122
132
|
};
|
|
123
133
|
|
|
124
134
|
const scrollBottom = throttle(() => {
|
|
135
|
+
if (page.value >= lastPage.value) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
125
138
|
if (fetching.value) {
|
|
126
139
|
return;
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
page.value++;
|
|
143
|
+
search();
|
|
144
|
+
}, 500);
|
|
145
|
+
|
|
146
|
+
watch(
|
|
147
|
+
() => props.url,
|
|
148
|
+
() => {
|
|
149
|
+
page.value = 1;
|
|
131
150
|
search();
|
|
132
151
|
}
|
|
133
|
-
|
|
152
|
+
);
|
|
134
153
|
|
|
135
154
|
const search = () => {
|
|
136
155
|
if (fetching.value) {
|
|
@@ -149,16 +168,15 @@ const search = () => {
|
|
|
149
168
|
},
|
|
150
169
|
})
|
|
151
170
|
.then((response: any) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
171
|
+
data.value = response.data as
|
|
172
|
+
| ResourceCollection
|
|
173
|
+
| PaginatedCollection
|
|
174
|
+
| Collection;
|
|
157
175
|
|
|
158
176
|
if (page.value == 1) {
|
|
159
|
-
options.value =
|
|
177
|
+
options.value = items.value;
|
|
160
178
|
} else {
|
|
161
|
-
options.value.push(...
|
|
179
|
+
options.value.push(...items.value);
|
|
162
180
|
}
|
|
163
181
|
|
|
164
182
|
firstSearch.value = true;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
Collection,
|
|
4
|
+
PaginatedCollection,
|
|
5
|
+
ResourceCollection,
|
|
6
|
+
PaginationMetadata,
|
|
7
|
+
} from '@/types';
|
|
8
|
+
import { isArray } from 'lodash';
|
|
9
|
+
|
|
10
|
+
export function useHasPaginatedData(
|
|
11
|
+
data: Ref<Collection | PaginatedCollection | ResourceCollection | null>
|
|
12
|
+
) {
|
|
13
|
+
const items = computed(() => {
|
|
14
|
+
if (!data.value) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
if (isArray(data.value)) {
|
|
18
|
+
return data.value;
|
|
19
|
+
}
|
|
20
|
+
return data.value.data;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const paginationMetadata = computed<PaginationMetadata | null>(() => {
|
|
24
|
+
const defaultMeta = {
|
|
25
|
+
current_page: 1,
|
|
26
|
+
last_page: 1,
|
|
27
|
+
per_page: 1,
|
|
28
|
+
total: 0,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (!data.value) {
|
|
32
|
+
return defaultMeta;
|
|
33
|
+
}
|
|
34
|
+
if (isArray(data.value)) {
|
|
35
|
+
return defaultMeta;
|
|
36
|
+
}
|
|
37
|
+
if ('meta' in data.value) {
|
|
38
|
+
return data.value.meta;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (data.value.current_page) {
|
|
42
|
+
return {
|
|
43
|
+
current_page: data.value.current_page,
|
|
44
|
+
last_page: data.value.last_page,
|
|
45
|
+
per_page: data.value.per_page,
|
|
46
|
+
total: data.value.total,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const lastPage = computed(() => {
|
|
54
|
+
if (!paginationMetadata.value) {
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
return paginationMetadata.value.last_page;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
items,
|
|
62
|
+
paginationMetadata,
|
|
63
|
+
lastPage,
|
|
64
|
+
};
|
|
65
|
+
}
|