@katlux/block-ecommerce 0.1.1-alpha.120 → 0.1.1-alpha.122

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 ADDED
@@ -0,0 +1,40 @@
1
+ # @katlux/block-ecommerce
2
+
3
+ [![npm version](https://img.shields.io/badge/version-0.1.1--alpha.121-orange.svg)](https://www.npmjs.com/package/@katlux/block-ecommerce)
4
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](./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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.1-alpha.119",
7
+ "version": "0.1.1-alpha.122",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,4 +1,4 @@
1
- import type { KProductRowAction } from '@katlux/providers';
1
+ import type { KProductRowAction } from '../../types/product.js';
2
2
  import { ADataProvider } from '@katlux/providers';
3
3
  type __VLS_Props = {
4
4
  dataProvider: ADataProvider;
@@ -19,14 +19,17 @@ type __VLS_Props = {
19
19
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
20
  "update:currentPage": (page: number) => any;
21
21
  "update:pageSize": (size: number) => any;
22
+ "page-change": (page: number) => any;
22
23
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
23
24
  "onUpdate:currentPage"?: ((page: number) => any) | undefined;
24
25
  "onUpdate:pageSize"?: ((size: number) => any) | undefined;
26
+ "onPage-change"?: ((page: number) => any) | undefined;
25
27
  }>, {
26
28
  locale: string;
27
29
  currentPage: number;
28
30
  pageSize: number;
29
31
  buffer: number;
32
+ viewportHeight: number;
30
33
  layout: "grid" | "list";
31
34
  rowActions: KProductRowAction[];
32
35
  gridColumns: number | string;
@@ -34,7 +37,6 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
34
37
  emptyText: string;
35
38
  virtualScroll: boolean;
36
39
  itemHeight: number;
37
- viewportHeight: number;
38
40
  urlPageParam: string;
39
41
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
40
42
  declare const _default: typeof __VLS_export;
@@ -1,4 +1,5 @@
1
- import type { ADataProvider, KProductItemData, KProductRowAction } from '@katlux/providers';
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;
@@ -18,6 +19,7 @@ export interface KProductListProps {
18
19
  export type KProductListEmits = {
19
20
  (e: 'update:currentPage', page: number): void;
20
21
  (e: 'update:pageSize', size: number): void;
22
+ (e: 'page-change', page: number): void;
21
23
  };
22
24
  export declare const KProductListDefaultProps: {
23
25
  dataProvider: {
@@ -75,7 +77,17 @@ export declare const KProductListDefaultProps: {
75
77
  };
76
78
  export declare function useKProductListLogic(props: KProductListProps, emit?: KProductListEmits): {
77
79
  isGrid: import("vue").ComputedRef<boolean>;
80
+ columnsCount: import("vue").ComputedRef<number>;
81
+ effectiveItemHeight: import("vue").ComputedRef<number>;
78
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>>;
79
91
  loading: import("vue").Ref<boolean, boolean>;
80
92
  initialLoad: import("vue").Ref<boolean, boolean>;
81
93
  rowCount: import("vue").Ref<number, number>;
@@ -83,4 +95,5 @@ export declare function useKProductListLogic(props: KProductListProps, emit?: KP
83
95
  pageSize: import("vue").Ref<number, number>;
84
96
  setCurrentPage: (page: number) => void;
85
97
  setPageSize: (size: number) => void;
98
+ emitPageUpdate: (val: number) => void;
86
99
  };
@@ -1,5 +1,5 @@
1
1
  import { computed, watch } from "vue";
2
- import { useDataProvider } from "#toolkit/composables/useDataProvider";
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
- pageData,
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
- } = useDataProvider(() => props.dataProvider);
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,22 +102,42 @@ export function useKProductListLogic(props, emit) {
81
102
  setCurrentPage(page);
82
103
  }
83
104
  }, { immediate: true });
84
- watch(dpCurrentPage, (val) => {
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);
113
+ emit?.("page-change", val);
114
+ };
115
+ watch(dpCurrentPage, (val) => {
116
+ emitPageUpdate(val);
86
117
  });
87
118
  watch(dpPageSize, (val) => {
88
119
  emit?.("update:pageSize", val);
89
120
  });
90
- const pageRows = computed(() => pageData.value || []);
91
121
  return {
92
122
  isGrid,
123
+ columnsCount,
124
+ effectiveItemHeight,
93
125
  pageRows,
126
+ displayRows,
127
+ datasetItems,
128
+ startIndex,
129
+ endIndex,
130
+ containerRef,
131
+ onScroll,
132
+ scrollToIndex,
133
+ containerCssVars,
94
134
  loading,
95
135
  initialLoad,
96
136
  rowCount,
97
137
  currentPage: dpCurrentPage,
98
138
  pageSize: dpPageSize,
99
139
  setCurrentPage,
100
- setPageSize
140
+ setPageSize,
141
+ emitPageUpdate
101
142
  };
102
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")
@@ -63,7 +63,7 @@
63
63
  KPagination.pagination(
64
64
  :dataProvider="props.dataProvider"
65
65
  :urlPageParam="props.urlPageParam"
66
- @update:currentPage="emit('update:currentPage', $event)"
66
+ @update:currentPage="emitPageUpdate($event)"
67
67
  @update:pageSize="emit('update:pageSize', $event)"
68
68
  )
69
69
  </template>
@@ -72,10 +72,9 @@
72
72
  import { computed } from "vue";
73
73
  import { ADataProvider } from "@katlux/providers";
74
74
  import { useKatluxI18n } from "#toolkit/composables/useKatluxI18n";
75
- import { useVirtualScroll } from "#toolkit/composables/useVirtualScroll";
76
75
  import { useKProductListLogic } from "./KProductList.logic";
77
76
  const { t } = useKatluxI18n();
78
- const emit = defineEmits(["update:currentPage", "update:pageSize"]);
77
+ const emit = defineEmits(["update:currentPage", "update:pageSize", "page-change"]);
79
78
  const props = defineProps({
80
79
  dataProvider: { type: Object, required: true },
81
80
  layout: { type: String, required: false, default: "grid" },
@@ -92,66 +91,27 @@ const props = defineProps({
92
91
  buffer: { type: Number, required: false, default: 2 },
93
92
  urlPageParam: { type: String, required: false, default: void 0 }
94
93
  });
95
- const { isGrid, pageRows, loading } = useKProductListLogic(props, emit);
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);
96
107
  const skeletonCount = computed(() => Number(props.gridColumns) || 4);
97
108
  const containerVars = computed(() => ({
98
109
  "--k-product-grid-cols": String(props.gridColumns),
99
110
  "--k-product-gap": props.gap
100
111
  }));
101
- const productItems = computed(() => {
102
- const currentRows = pageRows.value;
103
- const dp = props.dataProvider;
104
- if (props.virtualScroll) {
105
- if (Array.isArray(dp?.rowMap)) return dp.rowMap;
106
- if (Array.isArray(dp?.rowMap?.value)) return dp.rowMap.value;
107
- if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows;
108
- if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value;
109
- if (Array.isArray(dp?.allData?.value)) return dp.allData.value;
110
- if (Array.isArray(dp?.allData)) return dp.allData;
111
- if (Array.isArray(dp?.data)) return dp.data;
112
- }
113
- return currentRows;
114
- });
115
- const columnsCount = computed(() => isGrid.value ? Number(props.gridColumns) || 4 : 1);
116
- const effectiveItemHeight = computed(() => {
117
- if (typeof props.itemHeight === "number" && props.itemHeight > 0) return props.itemHeight;
118
- return isGrid.value ? 350 : 140;
119
- });
120
- const {
121
- visibleItems,
122
- startIndex,
123
- endIndex,
124
- topSpacerHeight,
125
- bottomSpacerHeight,
126
- containerRef,
127
- onScroll,
128
- scrollToIndex,
129
- containerCssVars
130
- } = useVirtualScroll({
131
- items: productItems,
132
- itemHeight: effectiveItemHeight,
133
- containerHeight: props.viewportHeight || 600,
134
- columns: columnsCount,
135
- buffer: props.buffer ?? 2,
136
- virtualScroll: computed(() => !!props.virtualScroll),
137
- onThresholdReach: () => {
138
- const dp = props.dataProvider;
139
- if (typeof dp?.loadMore === "function") {
140
- dp.loadMore();
141
- } else if (typeof dp?.nextPage === "function" && dp.hasMore) {
142
- dp.nextPage();
143
- }
144
- }
145
- });
146
- const displayProducts = computed(() => {
147
- if (props.virtualScroll) {
148
- return visibleItems.value;
149
- }
150
- return pageRows.value;
151
- });
152
112
  const isEmpty = computed(() => {
153
113
  if (props.virtualScroll) {
154
- return productItems.value.length === 0;
114
+ return datasetItems.value.length === 0;
155
115
  }
156
116
  return pageRows.value.length === 0;
157
117
  });
@@ -1,4 +1,4 @@
1
- import type { KProductRowAction } from '@katlux/providers';
1
+ import type { KProductRowAction } from '../../types/product.js';
2
2
  import { ADataProvider } from '@katlux/providers';
3
3
  type __VLS_Props = {
4
4
  dataProvider: ADataProvider;
@@ -19,14 +19,17 @@ type __VLS_Props = {
19
19
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
20
  "update:currentPage": (page: number) => any;
21
21
  "update:pageSize": (size: number) => any;
22
+ "page-change": (page: number) => any;
22
23
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
23
24
  "onUpdate:currentPage"?: ((page: number) => any) | undefined;
24
25
  "onUpdate:pageSize"?: ((size: number) => any) | undefined;
26
+ "onPage-change"?: ((page: number) => any) | undefined;
25
27
  }>, {
26
28
  locale: string;
27
29
  currentPage: number;
28
30
  pageSize: number;
29
31
  buffer: number;
32
+ viewportHeight: number;
30
33
  layout: "grid" | "list";
31
34
  rowActions: KProductRowAction[];
32
35
  gridColumns: number | string;
@@ -34,7 +37,6 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
34
37
  emptyText: string;
35
38
  virtualScroll: boolean;
36
39
  itemHeight: number;
37
- viewportHeight: number;
38
40
  urlPageParam: string;
39
41
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
40
42
  declare const _default: typeof __VLS_export;
@@ -1,4 +1,4 @@
1
- import type { KProductItemData, KProductRowAction } from '@katlux/providers';
1
+ import type { KProductItemData, KProductRowAction } from '../../types/product.js';
2
2
  type __VLS_Props = {
3
3
  item: KProductItemData;
4
4
  rowActions?: KProductRowAction[];
@@ -1,5 +1,5 @@
1
1
  import { type PropType } from 'vue';
2
- import type { KProductItemData, KProductRowAction } from '@katlux/providers';
2
+ import type { KProductItemData, KProductRowAction } from '../../types/product.js';
3
3
  export interface KProductListItemProps {
4
4
  item: KProductItemData;
5
5
  rowActions?: KProductRowAction[];
@@ -1,4 +1,4 @@
1
- import type { KProductItemData, KProductRowAction } from '@katlux/providers';
1
+ import type { KProductItemData, KProductRowAction } from '../../types/product.js';
2
2
  type __VLS_Props = {
3
3
  item: KProductItemData;
4
4
  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.120",
3
+ "version": "0.1.1-alpha.122",
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.133",
32
- "@katlux/toolkit": "^0.1.1-alpha.146",
31
+ "@katlux/providers": "^0.1.1-alpha.135",
32
+ "@katlux/toolkit": "^0.1.1-alpha.148",
33
33
  "@nuxt/kit": "^3.12.0",
34
34
  "pug": "^3.0.0",
35
35
  "sass": "^1.80.0"