@scayle/storefront-product-listing 0.6.0 → 1.0.0

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-product-listing",
3
3
  "configKey": "product-listing",
4
- "version": "0.0.1",
4
+ "version": "1.0.0",
5
5
  "compatibility": {
6
6
  "bridge": false,
7
7
  "nuxt": ">=3.13"
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ const module = defineNuxtModule({
4
4
  meta: {
5
5
  name: "@scayle/storefront-product-listing",
6
6
  configKey: "product-listing",
7
- version: "0.0.1",
7
+ version: "1.0.0",
8
8
  compatibility: {
9
9
  bridge: false,
10
10
  nuxt: ">=3.13"
@@ -7,34 +7,24 @@ export interface AppliedFiltersOptions {
7
7
  filtersPrefix: string;
8
8
  }
9
9
  export interface UseAppliedFiltersReturn {
10
+ /** A computed property returning a `ProductSearchQuery` object based on the route's query parameters. */
10
11
  appliedFilter: ComputedRef<ProductSearchQuery>;
12
+ /** A computed property that returns the total count of applied filters. Counts minPrice/maxPrice as one and counts each attribute filter separately. */
11
13
  appliedFiltersCount: ComputedRef<number>;
14
+ /** A computed property that returns a record mapping attribute keys to their boolean values for boolean filters. */
12
15
  appliedBooleanValues: ComputedRef<AppliedBooleanValues>;
16
+ /** A computed property that returns a record mapping attribute keys to arrays of numbers representing selected values for each attribute. */
13
17
  appliedAttributeValues: ComputedRef<AppliedAttributeValues>;
18
+ /** A computed property that returns `true` if any filters are currently applied, otherwise `false`. */
14
19
  areFiltersApplied: ComputedRef<boolean>;
15
20
  }
16
21
  /**
17
22
  * Composable to manage applied filters based on route query parameters.
18
23
  *
19
- * @param {RouteLocationNormalizedLoadedGeneric} [route] - Route object to handle the queries.
20
- * @param {AppliedFiltersOptions} options - Configuration options for applied filters.
21
- * @param {string} options.filtersPrefix - The prefix used to identify filter-related query parameters.
24
+ * @param route Route object to handle the queries.
25
+ * @param options Configuration options for applied filters.
26
+ * @param options.filtersPrefix The prefix used to identify filter-related query parameters.
22
27
  *
23
- * @returns {UseAppliedFiltersReturn} - An object containing reactive data and computed properties for managing applied filters:
24
- *
25
- * - `appliedFilter` {ComputedRef<ProductSearchQuery>}: A computed property returning a `ProductSearchQuery` object based on the route's query parameters.
26
- * - `attributes`: An array of attribute filters, where each filter has:
27
- * - `type`: A string, either 'boolean' or 'attributes'.
28
- * - `key`: The name of the attribute.
29
- * - `value`: A boolean for boolean filters.
30
- * - `values`: An array of numbers for attribute filters.
31
- * - `minPrice`: (Optional) The minimum price filter as a number.
32
- * - `maxPrice`: (Optional) The maximum price filter as a number.
33
- * - `term`: (Optional) A search term filter as a string.
34
- *
35
- * - `appliedFiltersCount` {ComputedRef<number>}: A computed property that returns the total count of applied filters. Counts minPrice/maxPrice as one and counts each attribute filter separately.
36
- * - `appliedAttributeValues` {ComputedRef<AppliedAttributeValues>}: A computed property that returns a record mapping attribute keys to arrays of numbers representing selected values for each attribute.
37
- * - `appliedBooleanValues` {ComputedRef<appliedBooleanValues>}: A computed property that returns a record mapping attribute keys to their boolean values for boolean filters.
38
- * - `areFiltersApplied` {ComputedRef<boolean>}: A computed property that returns `true` if any filters are currently applied, otherwise `false`.
28
+ * @returns An object containing reactive data and computed properties for managing applied filters:
39
29
  */
40
30
  export declare function useAppliedFilters(route: RouteLocationNormalizedLoadedGeneric, { filtersPrefix }?: AppliedFiltersOptions): UseAppliedFiltersReturn;
@@ -11,23 +11,19 @@ export type FiltersForListingOptions = Partial<{
11
11
  fetchingKey: string;
12
12
  }>;
13
13
  export type UseFiltersForListingReturn = Pick<Awaited<ReturnType<typeof useFilters>>, 'error' | 'status' | 'refresh'> & {
14
+ /** Returns computed available filters. */
14
15
  availableFilters: ComputedRef<FilterItemWithValues[]>;
16
+ /** Returns the count of the products which the applied filter returns. */
15
17
  filteredProductCount: ComputedRef<number>;
16
18
  };
17
19
  /**
18
20
  * Composable to manage filters based on current category ID and route query parameters.
19
21
  *
20
- * @param {FiltersForListingOptions} options - Configuration options for fetching products.
21
- * @param {Partial<FetchFiltersParams>} options.params - Parameters to control product fetch behavior, excluding `category`.
22
- * @param {Partial<{ lazy: boolean; immediate: boolean }>} options.fetchingOptions - Options for fetch timing, such as lazy loading or immediate fetching.
23
- * @param {string} [options.fetchingKey] - Optional unique key to control the fetching cache.
22
+ * @param options Configuration options for fetching products.
23
+ * @param options.params Parameters to control product fetch behavior, excluding `category`.
24
+ * @param options.fetchingOptions Options for fetch timing, such as lazy loading or immediate fetching.
25
+ * @param options.fetchingKey Optional unique key to control the fetching cache.
24
26
  *
25
27
  * @returns {UseFiltersForListingReturn} - An object containing reactive data, computed properties and async RPC call for managing filters:
26
- * - `fetch`: call for fetching the filters.
27
- * - `error`: returns "useFilters" error.
28
- * - `status`: returns "useFilters" status.
29
- * - `fetching`: returns "useFilters" fetching flag.
30
- * - `availableFilters` {ComputedRef<FilterItemWithValues[]>}: returns computed available filters.
31
- * - `filteredProductCount` {ComputedRef<number>}: returns the count of the products which the applied filter returns.
32
28
  */
33
29
  export declare function useFiltersForListing({ params, fetchingKey, fetchingOptions, }?: FiltersForListingOptions): UseFiltersForListingReturn & Promise<UseFiltersForListingReturn>;
@@ -9,8 +9,11 @@ type SortLink = SelectedSort & {
9
9
  to: RouteLocationRaw;
10
10
  };
11
11
  export interface UseProductListSortReturn {
12
+ /** The currently selected sorting option. */
12
13
  selectedSort: ComputedRef<SelectedSort | undefined>;
14
+ /** Links with updated query parameters for each sorting option. */
13
15
  sortLinks: ComputedRef<SortLink[]>;
16
+ /** Indicating if the default sort is selected. */
14
17
  isDefaultSortSelected: ComputedRef<boolean>;
15
18
  }
16
19
  export interface ProductListSortOptions {
@@ -20,16 +23,12 @@ export interface ProductListSortOptions {
20
23
  /**
21
24
  * Custom composable to handle product list sorting.
22
25
  *
23
- * @param {RouteLocationNormalizedLoadedGeneric} [route] - Route object to handle the queries and path.
24
- * @param {ProductListSortOptions} [options] - Options for configuring the sorting behavior.
25
- * @param {SelectedSort[]} [options.sortingOptions] - Array of available sorting options.
26
- * @param {string} [options.defaultSortingKey] - Default sorting key to be applied if no specific sort is selected.
26
+ * @param route Route object to handle the queries and path.
27
+ * @param options Options for configuring the sorting behavior.
28
+ * @param options.sortingOptions Array of available sorting options.
29
+ * @param options.defaultSortingKey Default sorting key to be applied if no specific sort is selected.
27
30
  *
28
- * @returns - computed properties and methods related to sorting:
29
- *
30
- * - {ComputedRef<SelectedSort | undefined>} selectedSort - The currently selected sorting option.
31
- * - {ComputedRef<SortLink[]>} sortLinks - Links with updated query parameters for each sorting option.
32
- * - {ComputedRef<boolean>} isDefaultSortSelected - Boolean indicating if the default sort is selected.
31
+ * @returns Computed properties and methods related to sorting
33
32
  */
34
33
  export declare function useProductListSort(route: RouteLocationNormalizedLoadedGeneric, { sortingOptions, defaultSortingKey }?: ProductListSortOptions): UseProductListSortReturn;
35
34
  export {};
@@ -5,24 +5,25 @@ import type { RouteLocationNormalizedLoadedGeneric } from 'vue-router';
5
5
  type CanonicalLink = Record<'rel' | 'key' | 'href', string>;
6
6
  type UrlParams = Record<'baseUrl' | 'fullPath', string>;
7
7
  export interface UseProductListingSeoDataReturn {
8
+ /** A computed string that is constructed from breadcrumb values. */
8
9
  title: ComputedRef<string>;
10
+ /** A computed robots. Value can be `index,follow` or `noindex,follow`. */
9
11
  robots: ComputedRef<string>;
12
+ /** A computed canonical link. */
10
13
  canonicalLink: ComputedRef<CanonicalLink[]>;
14
+ /** A computed breadcrumb schema. */
11
15
  categoryBreadcrumbSchema: ComputedRef<WithContext<BreadcrumbList> | []>;
12
16
  }
13
17
  /**
14
18
  * Composable for handling product listing SEO data.
15
19
  *
16
- * @param {MaybeRefOrGetter<BreadcrumbItem[]>} breadcrumbs - Breadcrumb items.
17
- * @param {RouteLocationNormalizedLoadedGeneric} [route] - route object to handle queries.
18
- * @param {UrlParams} URL params - URL data for constructing the canonical link.
20
+ * @param breadcrumbs Breadcrumb items.
21
+ * @param route The route object to handle queries.
22
+ * @param params - URL data for constructing the canonical link.
23
+ * @param params.baseUrl The base URL of the application.
24
+ * @param params.fullPath - The full path of the current route.
19
25
  *
20
- * @returns {UseProductListingSeoDataReturn} An object containing reactive data and computed properties for managing SEO data.
21
- *
22
- * @property {ComputedRef<string>} title - A computed string that is constructed from breadcrumb values.
23
- * @property {ComputedRef<string>} robots - A computed robots. Value can be "index,follow" or "noindex,follow".
24
- * @property {ComputedRef<CanonicalLink[]>} canonicalLink - A computed canonical link.
25
- * @property {ComputedRef<WithContext<BreadcrumbList> | []>} categoryBreadcrumbSchema - A computed breadcrumb schema.
26
+ * @returns An object containing reactive data and computed properties for managing SEO data.
26
27
  */
27
28
  export declare function useProductListingSeoData(breadcrumbs: MaybeRefOrGetter<BreadcrumbItem[]>, route: RouteLocationNormalizedLoadedGeneric, { baseUrl, fullPath }: UrlParams): UseProductListingSeoDataReturn;
28
29
  export {};
@@ -3,8 +3,11 @@ import { type MaybeRefOrGetter, type ComputedRef } from 'vue';
3
3
  import { useProducts } from '@scayle/storefront-nuxt/composables';
4
4
  import type { Pagination } from '@scayle/storefront-api';
5
5
  export type UseProductsForListingReturn = Pick<Awaited<ReturnType<typeof useProducts>>, 'error' | 'status'> & {
6
+ /** A computed array of products in the specified category. */
6
7
  products: ComputedRef<Product[]>;
8
+ /** A computed object containing pagination details for the product list. */
7
9
  pagination: ComputedRef<Pagination | undefined>;
10
+ /** A computed offset for the current page based on the pagination data. */
8
11
  totalProductsCount: ComputedRef<number>;
9
12
  paginationOffset: ComputedRef<number>;
10
13
  };
@@ -19,17 +22,11 @@ export interface ProductsForListingOptions {
19
22
  /**
20
23
  * Composable to fetch and manage products by category with configurable options.
21
24
  *
22
- * @param {ProductsForListingOptions} options - Configuration options for fetching products.
23
- * @param {Partial<FetchProductsByCategoryParams>} options.params - Parameters to control product fetch behavior, excluding `category`.
24
- * @param {Partial<{ lazy: boolean; immediate: boolean }>} options.fetchingOptions - Options for fetch timing, such as lazy loading or immediate fetching.
25
- * @param {string} [options.fetchingKey] - Optional unique key to control the fetching cache.
25
+ * @param options Configuration options for fetching products.
26
+ * @param options.params Parameters to control product fetch behavior, excluding `category`.
27
+ * @param options.fetchingOptions Options for fetch timing, such as lazy loading or immediate fetching.
28
+ * @param options.fetchingKey Optional unique key to control the fetching cache.
26
29
  *
27
- * @returns {UseProductsByCategoryReturn} - An object containing reactive data and computed properties for managing products by category.
28
- * @property {ComputedRef<Product[]>} products - A computed array of products in the specified category.
29
- * @property {ComputedRef<Pagination>} pagination - A computed object containing pagination details for the product list.
30
- * @property {ComputedRef<number>} totalProductsCount - A computed total count of products in the category.
31
- * @property {ComputedRef<number>} paginationOffset - A computed offset for the current page based on the pagination data.
32
- * @property {Ref<boolean>} fetching - A reactive boolean indicating if products are currently being fetched.
33
- * @property {Ref<Error | null>} error - A reactive error object, null if no error occurred.
30
+ * @returns An object containing reactive data and computed properties for managing products by category.
34
31
  */
35
32
  export declare function useProductsForListing({ params, fetchingKey, fetchingOptions, }?: Partial<ProductsForListingOptions>): UseProductsForListingReturn & Promise<UseProductsForListingReturn>;
@@ -1,14 +1,61 @@
1
1
  import type { LocationQuery, RouteLocationNormalizedLoadedGeneric } from 'vue-router';
2
2
  import type { ProductSearchQuery } from '@scayle/storefront-api';
3
3
  import type { RangeTuple } from '~/src';
4
+ /**
5
+ * Parses filter data from a Vue Router route object.
6
+ *
7
+ * @param route The Vue Router route object.
8
+ * @param filtersPrefix The prefix used for filter query parameters.
9
+ *
10
+ * @returns An object representing the parsed product search query.
11
+ */
4
12
  export declare const parseFilterDataFromRoute: (route: RouteLocationNormalizedLoadedGeneric, filtersPrefix: string) => ProductSearchQuery;
13
+ /**
14
+ * Creates a new attribute filter query object.
15
+ *
16
+ * @param route The Vue Router route object.
17
+ * @param appliedFilter The currently applied filter.
18
+ * @param param An object containing the slug and ID of the attribute.
19
+ * @param param.slug The slug of the attribute.
20
+ * @param param.id The ID of the attribute.
21
+ *
22
+ * @returns A new query object with the updated attribute filter.
23
+ */
5
24
  export declare const createNewAttributeQuery: (route: RouteLocationNormalizedLoadedGeneric, appliedFilter: ProductSearchQuery, { slug, id }: {
6
25
  slug: string;
7
26
  id: number;
8
27
  }) => LocationQuery;
28
+ /**
29
+ * Creates a new price filter query object.
30
+ *
31
+ * @param {RouteLocationNormalizedLoadedGeneric} route - The Vue Router route object.
32
+ * @param {ProductSearchQuery} appliedFilter - The currently applied filter.
33
+ * @param {RangeTuple} prices - The new price range.
34
+ *
35
+ * @returns {LocationQuery} A new query object with the updated price filter.
36
+ */
9
37
  export declare const createNewPriceQuery: (route: RouteLocationNormalizedLoadedGeneric, appliedFilter: ProductSearchQuery, prices: RangeTuple) => LocationQuery;
38
+ /**
39
+ * Creates a new boolean attribute filter query object.
40
+ *
41
+ * @param route - The Vue Router route object.
42
+ * @param appliedFilter - The currently applied filter.
43
+ * @param param - An object containing the slug and value of the boolean attribute.
44
+ * @param param.slug - The slug of the attribute.
45
+ * @param param.value - The value of the attribute.
46
+ *
47
+ * @returns A new query object with the updated boolean attribute filter.
48
+ */
10
49
  export declare const createNewBoolAttributeQuery: (route: RouteLocationNormalizedLoadedGeneric, appliedFilter: ProductSearchQuery, { slug, value }: {
11
50
  slug: string;
12
51
  value: boolean;
13
52
  }) => LocationQuery;
53
+ /**
54
+ * Returns a new query object with the filter for the specified key cleared.
55
+ *
56
+ * @param route - The Vue Router route object.
57
+ * @param key - The key of the filter to clear.
58
+ *
59
+ * @returns A new query object with the filter cleared.
60
+ */
14
61
  export declare const getClearedFilterQueryByKey: (route: RouteLocationNormalizedLoadedGeneric, key: string) => LocationQuery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-product-listing",
3
- "version": "0.6.0",
3
+ "version": "1.0.0",
4
4
  "description": "Collection of essential composables and utilities to work with product listing",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@nuxt/kit": "^3.13.0",
48
- "@scayle/storefront-nuxt": "^7.93.0 || ^8.0.0",
48
+ "@scayle/storefront-nuxt": "^8.0.0",
49
49
  "@vue/test-utils": "2.4.6",
50
50
  "@vueuse/core": "12.0.0",
51
51
  "fishery": "2.2.2",
@@ -57,8 +57,8 @@
57
57
  "@nuxt/schema": "3.13.2",
58
58
  "@nuxt/test-utils": "3.15.1",
59
59
  "@scayle/eslint-config-storefront": "4.3.2",
60
- "@scayle/storefront-nuxt": "8.1.1",
61
- "@types/node": "22.10.1",
60
+ "@scayle/storefront-nuxt": "8.1.3",
61
+ "@types/node": "22.10.2",
62
62
  "@vue/test-utils": "2.4.6",
63
63
  "@vueuse/core": "12.0.0",
64
64
  "dprint": "0.47.6",