@katlux/block-ecommerce 0.1.1-alpha.119 → 0.1.1-alpha.121
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 +40 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KProductList/KProductList.d.vue.ts +6 -4
- package/dist/runtime/components/KProductList/KProductList.logic.d.ts +13 -1
- package/dist/runtime/components/KProductList/KProductList.logic.js +46 -6
- package/dist/runtime/components/KProductList/KProductList.vue +19 -57
- package/dist/runtime/components/KProductList/KProductList.vue.d.ts +6 -4
- package/dist/runtime/components/KProductListItem/KProductListItem.d.vue.ts +1 -1
- package/dist/runtime/components/KProductListItem/KProductListItem.logic.d.ts +1 -1
- package/dist/runtime/components/KProductListItem/KProductListItem.vue.d.ts +1 -1
- package/dist/runtime/types/product.d.ts +15 -0
- package/dist/runtime/types/product.js +0 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @katlux/block-ecommerce
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@katlux/block-ecommerce)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
Pre-built eCommerce UI block components for the Katlux UI toolkit, integrated with `@katlux/providers`.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @katlux/block-ecommerce@alpha
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Register the module in `nuxt.config.ts` alongside `@katlux/toolkit`:
|
|
15
|
+
```ts
|
|
16
|
+
export default defineNuxtConfig({
|
|
17
|
+
modules: [
|
|
18
|
+
'@katlux/toolkit',
|
|
19
|
+
'@katlux/block-ecommerce'
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Included Components
|
|
25
|
+
|
|
26
|
+
- `KProductList`: Responsive paginated or virtual-scrolled product catalog supporting `'grid'` and `'list'` layouts, custom slots (`#default`, `#loading`, `#empty`), `urlPageParam` routing sync, and pure Vue 3 `@update:currentPage` / `@update:pageSize` events.
|
|
27
|
+
- `KProductListItem`: Product card renderer with locale-aware currency formatting, placeholder fallback, and configurable `rowActions`.
|
|
28
|
+
|
|
29
|
+
## Documentation & Changelog
|
|
30
|
+
|
|
31
|
+
- **Monorepo Repository**: [https://github.com/katlux-ui/KatluxShowcase](https://github.com/katlux-ui/KatluxShowcase)
|
|
32
|
+
- **Changelog & Migration Guide**: [CHANGELOG.md](https://github.com/katlux-ui/KatluxShowcase/blob/dev/CHANGELOG.md)
|
|
33
|
+
|
|
34
|
+
## License & Trademark Policy
|
|
35
|
+
|
|
36
|
+
The code in this repository is completely free and open-source under the **Apache 2.0 License** (see [LICENSE](./LICENSE)).
|
|
37
|
+
However, **Katlux™** and the Katlux logo are unregistered trademarks of the Katlux project.
|
|
38
|
+
|
|
39
|
+
To protect our users from fraud, you may not use the "Katlux" name or logo to brand your own modified forks, derivative works, or malicious distributions without explicit permission. You are, however, completely free to state "Built with Katlux" in your projects!
|
|
40
|
+
|
package/dist/module.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KProductRowAction } from '
|
|
1
|
+
import type { KProductRowAction } from '../../types/product.js';
|
|
2
2
|
import { ADataProvider } from '@katlux/providers';
|
|
3
3
|
type __VLS_Props = {
|
|
4
4
|
dataProvider: ADataProvider;
|
|
@@ -14,6 +14,7 @@ type __VLS_Props = {
|
|
|
14
14
|
itemHeight?: number;
|
|
15
15
|
viewportHeight?: number;
|
|
16
16
|
buffer?: number;
|
|
17
|
+
urlPageParam?: string;
|
|
17
18
|
};
|
|
18
19
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
19
20
|
"update:currentPage": (page: number) => any;
|
|
@@ -24,18 +25,19 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
24
25
|
"onUpdate:pageSize"?: ((size: number) => any) | undefined;
|
|
25
26
|
"onPage-change"?: ((page: number) => any) | undefined;
|
|
26
27
|
}>, {
|
|
28
|
+
rowActions: KProductRowAction[];
|
|
29
|
+
locale: string;
|
|
27
30
|
currentPage: number;
|
|
28
31
|
pageSize: number;
|
|
29
32
|
buffer: number;
|
|
33
|
+
viewportHeight: number;
|
|
30
34
|
layout: "grid" | "list";
|
|
31
|
-
rowActions: KProductRowAction[];
|
|
32
35
|
gridColumns: number | string;
|
|
33
36
|
gap: string;
|
|
34
|
-
locale: string;
|
|
35
37
|
emptyText: string;
|
|
36
38
|
virtualScroll: boolean;
|
|
37
39
|
itemHeight: number;
|
|
38
|
-
|
|
40
|
+
urlPageParam: string;
|
|
39
41
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
40
42
|
declare const _default: typeof __VLS_export;
|
|
41
43
|
export default _default;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ADataProvider
|
|
1
|
+
import type { ADataProvider } from '@katlux/providers';
|
|
2
|
+
import type { KProductItemData, KProductRowAction } from '../../types/product.js';
|
|
2
3
|
import { type PropType } from 'vue';
|
|
3
4
|
export interface KProductListProps {
|
|
4
5
|
dataProvider: ADataProvider;
|
|
@@ -76,7 +77,17 @@ export declare const KProductListDefaultProps: {
|
|
|
76
77
|
};
|
|
77
78
|
export declare function useKProductListLogic(props: KProductListProps, emit?: KProductListEmits): {
|
|
78
79
|
isGrid: import("vue").ComputedRef<boolean>;
|
|
80
|
+
columnsCount: import("vue").ComputedRef<number>;
|
|
81
|
+
effectiveItemHeight: import("vue").ComputedRef<number>;
|
|
79
82
|
pageRows: import("vue").ComputedRef<KProductItemData[]>;
|
|
83
|
+
displayRows: import("vue").ComputedRef<KProductItemData[]>;
|
|
84
|
+
datasetItems: import("vue").ComputedRef<KProductItemData[]>;
|
|
85
|
+
startIndex: import("vue").ComputedRef<number>;
|
|
86
|
+
endIndex: import("vue").ComputedRef<number>;
|
|
87
|
+
containerRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
|
|
88
|
+
onScroll: (e: Event | UIEvent) => void;
|
|
89
|
+
scrollToIndex: (index: number, behavior?: ScrollBehavior, offset?: number) => void;
|
|
90
|
+
containerCssVars: import("vue").ComputedRef<Record<string, string>>;
|
|
80
91
|
loading: import("vue").Ref<boolean, boolean>;
|
|
81
92
|
initialLoad: import("vue").Ref<boolean, boolean>;
|
|
82
93
|
rowCount: import("vue").Ref<number, number>;
|
|
@@ -84,4 +95,5 @@ export declare function useKProductListLogic(props: KProductListProps, emit?: KP
|
|
|
84
95
|
pageSize: import("vue").Ref<number, number>;
|
|
85
96
|
setCurrentPage: (page: number) => void;
|
|
86
97
|
setPageSize: (size: number) => void;
|
|
98
|
+
emitPageUpdate: (val: number) => void;
|
|
87
99
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, watch } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { useVirtualDataset } from "#toolkit/composables/useVirtualDataset";
|
|
3
3
|
export const KProductListDefaultProps = {
|
|
4
4
|
dataProvider: {
|
|
5
5
|
type: Object,
|
|
@@ -56,8 +56,21 @@ export const KProductListDefaultProps = {
|
|
|
56
56
|
};
|
|
57
57
|
export function useKProductListLogic(props, emit) {
|
|
58
58
|
const isGrid = computed(() => props.layout !== "list");
|
|
59
|
+
const columnsCount = computed(() => isGrid.value ? Number(props.gridColumns) || 4 : 1);
|
|
60
|
+
const effectiveItemHeight = computed(() => {
|
|
61
|
+
if (typeof props.itemHeight === "number" && props.itemHeight > 0) return props.itemHeight;
|
|
62
|
+
return isGrid.value ? 350 : 140;
|
|
63
|
+
});
|
|
59
64
|
const {
|
|
60
|
-
|
|
65
|
+
pageRows,
|
|
66
|
+
displayRows,
|
|
67
|
+
datasetItems,
|
|
68
|
+
startIndex,
|
|
69
|
+
endIndex,
|
|
70
|
+
containerRef,
|
|
71
|
+
onScroll,
|
|
72
|
+
scrollToIndex,
|
|
73
|
+
containerCssVars,
|
|
61
74
|
loading,
|
|
62
75
|
initialLoad,
|
|
63
76
|
rowCount,
|
|
@@ -65,7 +78,15 @@ export function useKProductListLogic(props, emit) {
|
|
|
65
78
|
pageSize: dpPageSize,
|
|
66
79
|
setCurrentPage,
|
|
67
80
|
setPageSize
|
|
68
|
-
} =
|
|
81
|
+
} = useVirtualDataset({
|
|
82
|
+
dataProvider: () => props.dataProvider,
|
|
83
|
+
virtualScroll: () => !!props.virtualScroll,
|
|
84
|
+
itemHeight: effectiveItemHeight,
|
|
85
|
+
viewportHeight: () => props.viewportHeight || 600,
|
|
86
|
+
columns: columnsCount,
|
|
87
|
+
buffer: () => props.buffer ?? 2,
|
|
88
|
+
pageSize: () => props.pageSize
|
|
89
|
+
});
|
|
69
90
|
watch([() => props.currentPage, () => props.pageSize], ([page, size]) => {
|
|
70
91
|
if (size !== void 0 && size !== dpPageSize.value) {
|
|
71
92
|
const targetPage = page !== void 0 ? page : dpCurrentPage.value;
|
|
@@ -81,23 +102,42 @@ export function useKProductListLogic(props, emit) {
|
|
|
81
102
|
setCurrentPage(page);
|
|
82
103
|
}
|
|
83
104
|
}, { immediate: true });
|
|
84
|
-
|
|
105
|
+
let lastEmittedPage;
|
|
106
|
+
const emitPageUpdate = (val) => {
|
|
107
|
+
if (lastEmittedPage === val) return;
|
|
108
|
+
lastEmittedPage = val;
|
|
109
|
+
queueMicrotask(() => {
|
|
110
|
+
if (lastEmittedPage === val) lastEmittedPage = void 0;
|
|
111
|
+
});
|
|
85
112
|
emit?.("update:currentPage", val);
|
|
86
113
|
emit?.("page-change", val);
|
|
114
|
+
};
|
|
115
|
+
watch(dpCurrentPage, (val) => {
|
|
116
|
+
emitPageUpdate(val);
|
|
87
117
|
});
|
|
88
118
|
watch(dpPageSize, (val) => {
|
|
89
119
|
emit?.("update:pageSize", val);
|
|
90
120
|
});
|
|
91
|
-
const pageRows = computed(() => pageData.value || []);
|
|
92
121
|
return {
|
|
93
122
|
isGrid,
|
|
123
|
+
columnsCount,
|
|
124
|
+
effectiveItemHeight,
|
|
94
125
|
pageRows,
|
|
126
|
+
displayRows,
|
|
127
|
+
datasetItems,
|
|
128
|
+
startIndex,
|
|
129
|
+
endIndex,
|
|
130
|
+
containerRef,
|
|
131
|
+
onScroll,
|
|
132
|
+
scrollToIndex,
|
|
133
|
+
containerCssVars,
|
|
95
134
|
loading,
|
|
96
135
|
initialLoad,
|
|
97
136
|
rowCount,
|
|
98
137
|
currentPage: dpCurrentPage,
|
|
99
138
|
pageSize: dpPageSize,
|
|
100
139
|
setCurrentPage,
|
|
101
|
-
setPageSize
|
|
140
|
+
setPageSize,
|
|
141
|
+
emitPageUpdate
|
|
102
142
|
};
|
|
103
143
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template lang="pug">
|
|
2
2
|
.k-product-list(:class="{ 'is-grid': isGrid, 'is-list': !isGrid, 'is-virtual-scroll': props.virtualScroll }" :style="containerVars")
|
|
3
3
|
//- Loading state
|
|
4
|
-
.loading-container(v-if="loading")
|
|
4
|
+
.loading-container(v-if="loading && (!props.virtualScroll || displayProducts.length === 0)")
|
|
5
5
|
slot(name="loading" :loading="loading")
|
|
6
6
|
.list-container
|
|
7
7
|
.k-product-skeleton-card(v-for="i in skeletonCount" :key="i")
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
.footer(v-if="!loading && !isEmpty && !props.virtualScroll")
|
|
63
63
|
KPagination.pagination(
|
|
64
64
|
:dataProvider="props.dataProvider"
|
|
65
|
-
|
|
65
|
+
:urlPageParam="props.urlPageParam"
|
|
66
|
+
@update:currentPage="emitPageUpdate($event)"
|
|
66
67
|
@update:pageSize="emit('update:pageSize', $event)"
|
|
67
68
|
)
|
|
68
69
|
</template>
|
|
@@ -71,7 +72,6 @@
|
|
|
71
72
|
import { computed } from "vue";
|
|
72
73
|
import { ADataProvider } from "@katlux/providers";
|
|
73
74
|
import { useKatluxI18n } from "#toolkit/composables/useKatluxI18n";
|
|
74
|
-
import { useVirtualScroll } from "#toolkit/composables/useVirtualScroll";
|
|
75
75
|
import { useKProductListLogic } from "./KProductList.logic";
|
|
76
76
|
const { t } = useKatluxI18n();
|
|
77
77
|
const emit = defineEmits(["update:currentPage", "update:pageSize", "page-change"]);
|
|
@@ -88,68 +88,30 @@ const props = defineProps({
|
|
|
88
88
|
virtualScroll: { type: Boolean, required: false, default: false },
|
|
89
89
|
itemHeight: { type: Number, required: false, default: void 0 },
|
|
90
90
|
viewportHeight: { type: Number, required: false, default: 600 },
|
|
91
|
-
buffer: { type: Number, required: false, default: 2 }
|
|
91
|
+
buffer: { type: Number, required: false, default: 2 },
|
|
92
|
+
urlPageParam: { type: String, required: false, default: void 0 }
|
|
92
93
|
});
|
|
93
|
-
const {
|
|
94
|
+
const {
|
|
95
|
+
isGrid,
|
|
96
|
+
pageRows,
|
|
97
|
+
displayRows: displayProducts,
|
|
98
|
+
datasetItems,
|
|
99
|
+
startIndex,
|
|
100
|
+
containerRef,
|
|
101
|
+
onScroll,
|
|
102
|
+
containerCssVars,
|
|
103
|
+
effectiveItemHeight,
|
|
104
|
+
loading,
|
|
105
|
+
emitPageUpdate
|
|
106
|
+
} = useKProductListLogic(props, emit);
|
|
94
107
|
const skeletonCount = computed(() => Number(props.gridColumns) || 4);
|
|
95
108
|
const containerVars = computed(() => ({
|
|
96
109
|
"--k-product-grid-cols": String(props.gridColumns),
|
|
97
110
|
"--k-product-gap": props.gap
|
|
98
111
|
}));
|
|
99
|
-
const productItems = computed(() => {
|
|
100
|
-
const currentRows = pageRows.value;
|
|
101
|
-
const dp = props.dataProvider;
|
|
102
|
-
if (props.virtualScroll) {
|
|
103
|
-
if (Array.isArray(dp?.rowMap)) return dp.rowMap;
|
|
104
|
-
if (Array.isArray(dp?.rowMap?.value)) return dp.rowMap.value;
|
|
105
|
-
if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows;
|
|
106
|
-
if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value;
|
|
107
|
-
if (Array.isArray(dp?.allData?.value)) return dp.allData.value;
|
|
108
|
-
if (Array.isArray(dp?.allData)) return dp.allData;
|
|
109
|
-
if (Array.isArray(dp?.data)) return dp.data;
|
|
110
|
-
}
|
|
111
|
-
return currentRows;
|
|
112
|
-
});
|
|
113
|
-
const columnsCount = computed(() => isGrid.value ? Number(props.gridColumns) || 4 : 1);
|
|
114
|
-
const effectiveItemHeight = computed(() => {
|
|
115
|
-
if (typeof props.itemHeight === "number" && props.itemHeight > 0) return props.itemHeight;
|
|
116
|
-
return isGrid.value ? 350 : 140;
|
|
117
|
-
});
|
|
118
|
-
const {
|
|
119
|
-
visibleItems,
|
|
120
|
-
startIndex,
|
|
121
|
-
endIndex,
|
|
122
|
-
topSpacerHeight,
|
|
123
|
-
bottomSpacerHeight,
|
|
124
|
-
containerRef,
|
|
125
|
-
onScroll,
|
|
126
|
-
scrollToIndex,
|
|
127
|
-
containerCssVars
|
|
128
|
-
} = useVirtualScroll({
|
|
129
|
-
items: productItems,
|
|
130
|
-
itemHeight: effectiveItemHeight,
|
|
131
|
-
containerHeight: props.viewportHeight || 600,
|
|
132
|
-
columns: columnsCount,
|
|
133
|
-
buffer: props.buffer ?? 2,
|
|
134
|
-
virtualScroll: computed(() => !!props.virtualScroll),
|
|
135
|
-
onThresholdReach: () => {
|
|
136
|
-
const dp = props.dataProvider;
|
|
137
|
-
if (typeof dp?.loadMore === "function") {
|
|
138
|
-
dp.loadMore();
|
|
139
|
-
} else if (typeof dp?.nextPage === "function" && dp.hasMore) {
|
|
140
|
-
dp.nextPage();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const displayProducts = computed(() => {
|
|
145
|
-
if (props.virtualScroll) {
|
|
146
|
-
return visibleItems.value;
|
|
147
|
-
}
|
|
148
|
-
return pageRows.value;
|
|
149
|
-
});
|
|
150
112
|
const isEmpty = computed(() => {
|
|
151
113
|
if (props.virtualScroll) {
|
|
152
|
-
return
|
|
114
|
+
return datasetItems.value.length === 0;
|
|
153
115
|
}
|
|
154
116
|
return pageRows.value.length === 0;
|
|
155
117
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KProductRowAction } from '
|
|
1
|
+
import type { KProductRowAction } from '../../types/product.js';
|
|
2
2
|
import { ADataProvider } from '@katlux/providers';
|
|
3
3
|
type __VLS_Props = {
|
|
4
4
|
dataProvider: ADataProvider;
|
|
@@ -14,6 +14,7 @@ type __VLS_Props = {
|
|
|
14
14
|
itemHeight?: number;
|
|
15
15
|
viewportHeight?: number;
|
|
16
16
|
buffer?: number;
|
|
17
|
+
urlPageParam?: string;
|
|
17
18
|
};
|
|
18
19
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
19
20
|
"update:currentPage": (page: number) => any;
|
|
@@ -24,18 +25,19 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
24
25
|
"onUpdate:pageSize"?: ((size: number) => any) | undefined;
|
|
25
26
|
"onPage-change"?: ((page: number) => any) | undefined;
|
|
26
27
|
}>, {
|
|
28
|
+
rowActions: KProductRowAction[];
|
|
29
|
+
locale: string;
|
|
27
30
|
currentPage: number;
|
|
28
31
|
pageSize: number;
|
|
29
32
|
buffer: number;
|
|
33
|
+
viewportHeight: number;
|
|
30
34
|
layout: "grid" | "list";
|
|
31
|
-
rowActions: KProductRowAction[];
|
|
32
35
|
gridColumns: number | string;
|
|
33
36
|
gap: string;
|
|
34
|
-
locale: string;
|
|
35
37
|
emptyText: string;
|
|
36
38
|
virtualScroll: boolean;
|
|
37
39
|
itemHeight: number;
|
|
38
|
-
|
|
40
|
+
urlPageParam: string;
|
|
39
41
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
40
42
|
declare const _default: typeof __VLS_export;
|
|
41
43
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PropType } from 'vue';
|
|
2
|
-
import type { KProductItemData, KProductRowAction } from '
|
|
2
|
+
import type { KProductItemData, KProductRowAction } from '../../types/product.js';
|
|
3
3
|
export interface KProductListItemProps {
|
|
4
4
|
item: KProductItemData;
|
|
5
5
|
rowActions?: KProductRowAction[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface KProductItemData {
|
|
2
|
+
id: string | number;
|
|
3
|
+
title: string;
|
|
4
|
+
image?: string;
|
|
5
|
+
price?: number;
|
|
6
|
+
currency?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface KProductRowAction {
|
|
11
|
+
label: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
action: (item: KProductItemData) => void;
|
|
14
|
+
color?: 'primary' | 'danger' | 'success' | 'warning' | 'info' | 'light' | 'dark' | 'default';
|
|
15
|
+
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katlux/block-ecommerce",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.121",
|
|
4
4
|
"description": "Pre-built eCommerce block components for Katlux toolkit",
|
|
5
5
|
"author": "Katlux",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"**/*.sass"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@katlux/providers": "^0.1.1-alpha.
|
|
32
|
-
"@katlux/toolkit": "^0.1.1-alpha.
|
|
31
|
+
"@katlux/providers": "^0.1.1-alpha.134",
|
|
32
|
+
"@katlux/toolkit": "^0.1.1-alpha.147",
|
|
33
33
|
"@nuxt/kit": "^3.12.0",
|
|
34
34
|
"pug": "^3.0.0",
|
|
35
35
|
"sass": "^1.80.0"
|