@wix/headless-stores 0.0.77 → 0.0.79

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.
Files changed (43) hide show
  1. package/cjs/dist/react/Category.d.ts +4 -8
  2. package/cjs/dist/react/Category.js +35 -29
  3. package/cjs/dist/react/CategoryList.d.ts +3 -2
  4. package/cjs/dist/react/CategoryList.js +4 -3
  5. package/cjs/dist/react/Product.d.ts +86 -0
  6. package/cjs/dist/react/Product.js +83 -2
  7. package/cjs/dist/react/ProductList.d.ts +1 -1
  8. package/cjs/dist/react/ProductList.js +1 -1
  9. package/cjs/dist/react/core/CategoryList.d.ts +11 -5
  10. package/cjs/dist/react/core/CategoryList.js +9 -4
  11. package/cjs/dist/react/core/ProductListFilters.d.ts +1 -1
  12. package/cjs/dist/react/index.d.ts +0 -1
  13. package/cjs/dist/react/index.js +0 -1
  14. package/cjs/dist/services/categories-list-service.d.ts +2 -1
  15. package/cjs/dist/services/index.d.ts +0 -1
  16. package/cjs/dist/services/index.js +0 -1
  17. package/cjs/dist/services/products-list-service.d.ts +2 -1
  18. package/dist/react/Category.d.ts +4 -8
  19. package/dist/react/Category.js +35 -29
  20. package/dist/react/CategoryList.d.ts +3 -2
  21. package/dist/react/CategoryList.js +4 -3
  22. package/dist/react/Product.d.ts +86 -0
  23. package/dist/react/Product.js +83 -2
  24. package/dist/react/ProductList.d.ts +1 -1
  25. package/dist/react/ProductList.js +1 -1
  26. package/dist/react/core/CategoryList.d.ts +11 -5
  27. package/dist/react/core/CategoryList.js +9 -4
  28. package/dist/react/core/ProductListFilters.d.ts +1 -1
  29. package/dist/react/index.d.ts +0 -1
  30. package/dist/react/index.js +0 -1
  31. package/dist/services/categories-list-service.d.ts +2 -1
  32. package/dist/services/index.d.ts +0 -1
  33. package/dist/services/index.js +0 -1
  34. package/dist/services/products-list-service.d.ts +2 -1
  35. package/package.json +1 -1
  36. package/cjs/dist/react/core/Category.d.ts +0 -98
  37. package/cjs/dist/react/core/Category.js +0 -81
  38. package/cjs/dist/services/category-service.d.ts +0 -161
  39. package/cjs/dist/services/category-service.js +0 -149
  40. package/dist/react/core/Category.d.ts +0 -98
  41. package/dist/react/core/Category.js +0 -81
  42. package/dist/services/category-service.d.ts +0 -161
  43. package/dist/services/category-service.js +0 -149
@@ -1,161 +0,0 @@
1
- import { categories } from '@wix/categories';
2
- import { type Signal } from '@wix/services-definitions/core-services/signals';
3
- /**
4
- * Type representing a category from the Wix Categories API.
5
- * This type is used to define the structure of category objects in the service.
6
- *
7
- * @type Category
8
- */
9
- export type Category = categories.Category;
10
- export interface CategoryServiceAPI {
11
- /** Reactive signal containing the current category data */
12
- category: Signal<Category>;
13
- /** Reactive signal indicating if a category is currently selected */
14
- isSelected: Signal<boolean>;
15
- }
16
- /**
17
- * Service definition for the Category service.
18
- * This defines the reactive API contract for managing a single product category.
19
- *
20
- * @constant
21
- */
22
- export declare const CategoryServiceDefinition: string & {
23
- __api: CategoryServiceAPI;
24
- __config: {};
25
- isServiceDefinition?: boolean;
26
- } & CategoryServiceAPI;
27
- /**
28
- * Configuration interface for the Category service.
29
- * Contains the initial category data that will be loaded into the service.
30
- *
31
- * @interface CategoryServiceConfig
32
- */
33
- export type CategoryServiceConfig = {
34
- /** The category object to initialize the service with */
35
- category: Category;
36
- /** Whether the category is currently selected */
37
- isSelected?: boolean;
38
- };
39
- /**
40
- * Implementation of the Category service that manages reactive category data.
41
- * This service provides a signal for category data and maintains it in a reactive state.
42
- * The service is initialized with pre-loaded category data.
43
- *
44
- * @example
45
- * ```tsx
46
- * import { CategoryService, CategoryServiceDefinition } from '@wix/stores/services';
47
- * import { useService } from '@wix/services-manager-react';
48
- *
49
- * function CategoryComponent({ categoryConfig }) {
50
- * return (
51
- * <ServiceProvider services={createServicesMap([
52
- * [CategoryServiceDefinition, CategoryService.withConfig(categoryConfig)]
53
- * ])}>
54
- * <CategoryDisplay />
55
- * </ServiceProvider>
56
- * );
57
- * }
58
- *
59
- * function CategoryDisplay() {
60
- * const categoryService = useService(CategoryServiceDefinition);
61
- * const category = categoryService.category.get();
62
- *
63
- * return (
64
- * <div>
65
- * <h1>{category.name}</h1>
66
- * <p>{category.description}</p>
67
- * </div>
68
- * );
69
- * }
70
- * ```
71
- */
72
- export declare const CategoryService: import("@wix/services-definitions").ServiceFactory<string & {
73
- __api: CategoryServiceAPI;
74
- __config: {};
75
- isServiceDefinition?: boolean;
76
- } & CategoryServiceAPI, CategoryServiceConfig>;
77
- /**
78
- * Loads category service configuration from the Wix Categories API for SSR initialization.
79
- * This function is designed to be used during Server-Side Rendering (SSR) to preload
80
- * a specific category by slug that will be used to configure the CategoryService.
81
- *
82
- * @param {string} slug - The category slug to load
83
- * @returns {Promise} Promise that resolves to either success with config or not-found result
84
- *
85
- * @example
86
- * ```astro
87
- * ---
88
- * // Astro page example - pages/category/[slug].astro
89
- * import { loadCategoryServiceConfig } from '@wix/stores/services';
90
- * import { Category } from '@wix/stores/components/react';
91
- *
92
- * // Get category slug from URL params
93
- * const { slug } = Astro.params;
94
- *
95
- * // Load category data during SSR
96
- * const categoryResult = await loadCategoryServiceConfig(slug);
97
- *
98
- * // Handle not found case
99
- * if (categoryResult.type === 'not-found') {
100
- * return Astro.redirect('/404');
101
- * }
102
- * ---
103
- *
104
- * <Category.Root categoryConfig={categoryResult.config}>
105
- * <Category.Name>
106
- * {({ name }) => <h1>{name}</h1>}
107
- * </Category.Name>
108
- * </Category.Root>
109
- * ```
110
- *
111
- * @example
112
- * ```tsx
113
- * // Next.js page example - pages/category/[slug].tsx
114
- * import { GetServerSideProps } from 'next';
115
- * import { loadCategoryServiceConfig } from '@wix/stores/services';
116
- * import { Category } from '@wix/stores/components/react';
117
- *
118
- * interface CategoryPageProps {
119
- * categoryConfig: Awaited<ReturnType<typeof loadCategoryServiceConfig>>['config'];
120
- * }
121
- *
122
- * export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async ({ params }) => {
123
- * const slug = params?.slug as string;
124
- *
125
- * // Load category data during SSR
126
- * const categoryResult = await loadCategoryServiceConfig(slug);
127
- *
128
- * // Handle not found case
129
- * if (categoryResult.type === 'not-found') {
130
- * return {
131
- * notFound: true,
132
- * };
133
- * }
134
- *
135
- * return {
136
- * props: {
137
- * categoryConfig: categoryResult.config,
138
- * },
139
- * };
140
- * };
141
- *
142
- * export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
143
- * return (
144
- * <Category.Root categoryConfig={categoryConfig}>
145
- * <Category.Name>
146
- * {({ name }) => <h1>{name}</h1>}
147
- * </Category.Name>
148
- * </Category.Root>
149
- * );
150
- * }
151
- * ```
152
- */
153
- export declare function loadCategoryServiceConfig(slug: string): Promise<{
154
- /** Type "success" means that the category was found and the config is valid */
155
- type: 'success';
156
- /** The category config containing the loaded category data */
157
- config: CategoryServiceConfig;
158
- } | {
159
- /** Type "not-found" means that the category was not found */
160
- type: 'not-found';
161
- }>;
@@ -1,149 +0,0 @@
1
- import { defineService, implementService } from '@wix/services-definitions';
2
- import { categories } from '@wix/categories';
3
- import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
4
- /**
5
- * Service definition for the Category service.
6
- * This defines the reactive API contract for managing a single product category.
7
- *
8
- * @constant
9
- */
10
- export const CategoryServiceDefinition = defineService('category');
11
- /**
12
- * Implementation of the Category service that manages reactive category data.
13
- * This service provides a signal for category data and maintains it in a reactive state.
14
- * The service is initialized with pre-loaded category data.
15
- *
16
- * @example
17
- * ```tsx
18
- * import { CategoryService, CategoryServiceDefinition } from '@wix/stores/services';
19
- * import { useService } from '@wix/services-manager-react';
20
- *
21
- * function CategoryComponent({ categoryConfig }) {
22
- * return (
23
- * <ServiceProvider services={createServicesMap([
24
- * [CategoryServiceDefinition, CategoryService.withConfig(categoryConfig)]
25
- * ])}>
26
- * <CategoryDisplay />
27
- * </ServiceProvider>
28
- * );
29
- * }
30
- *
31
- * function CategoryDisplay() {
32
- * const categoryService = useService(CategoryServiceDefinition);
33
- * const category = categoryService.category.get();
34
- *
35
- * return (
36
- * <div>
37
- * <h1>{category.name}</h1>
38
- * <p>{category.description}</p>
39
- * </div>
40
- * );
41
- * }
42
- * ```
43
- */
44
- export const CategoryService = implementService.withConfig()(CategoryServiceDefinition, ({ getService, config }) => {
45
- const signalsService = getService(SignalsServiceDefinition);
46
- const categorySignal = signalsService.signal(config.category);
47
- const isSelectedSignal = signalsService.signal(config.isSelected ?? false);
48
- return {
49
- category: categorySignal,
50
- isSelected: isSelectedSignal,
51
- };
52
- });
53
- /**
54
- * Loads category service configuration from the Wix Categories API for SSR initialization.
55
- * This function is designed to be used during Server-Side Rendering (SSR) to preload
56
- * a specific category by slug that will be used to configure the CategoryService.
57
- *
58
- * @param {string} slug - The category slug to load
59
- * @returns {Promise} Promise that resolves to either success with config or not-found result
60
- *
61
- * @example
62
- * ```astro
63
- * ---
64
- * // Astro page example - pages/category/[slug].astro
65
- * import { loadCategoryServiceConfig } from '@wix/stores/services';
66
- * import { Category } from '@wix/stores/components/react';
67
- *
68
- * // Get category slug from URL params
69
- * const { slug } = Astro.params;
70
- *
71
- * // Load category data during SSR
72
- * const categoryResult = await loadCategoryServiceConfig(slug);
73
- *
74
- * // Handle not found case
75
- * if (categoryResult.type === 'not-found') {
76
- * return Astro.redirect('/404');
77
- * }
78
- * ---
79
- *
80
- * <Category.Root categoryConfig={categoryResult.config}>
81
- * <Category.Name>
82
- * {({ name }) => <h1>{name}</h1>}
83
- * </Category.Name>
84
- * </Category.Root>
85
- * ```
86
- *
87
- * @example
88
- * ```tsx
89
- * // Next.js page example - pages/category/[slug].tsx
90
- * import { GetServerSideProps } from 'next';
91
- * import { loadCategoryServiceConfig } from '@wix/stores/services';
92
- * import { Category } from '@wix/stores/components/react';
93
- *
94
- * interface CategoryPageProps {
95
- * categoryConfig: Awaited<ReturnType<typeof loadCategoryServiceConfig>>['config'];
96
- * }
97
- *
98
- * export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async ({ params }) => {
99
- * const slug = params?.slug as string;
100
- *
101
- * // Load category data during SSR
102
- * const categoryResult = await loadCategoryServiceConfig(slug);
103
- *
104
- * // Handle not found case
105
- * if (categoryResult.type === 'not-found') {
106
- * return {
107
- * notFound: true,
108
- * };
109
- * }
110
- *
111
- * return {
112
- * props: {
113
- * categoryConfig: categoryResult.config,
114
- * },
115
- * };
116
- * };
117
- *
118
- * export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
119
- * return (
120
- * <Category.Root categoryConfig={categoryConfig}>
121
- * <Category.Name>
122
- * {({ name }) => <h1>{name}</h1>}
123
- * </Category.Name>
124
- * </Category.Root>
125
- * );
126
- * }
127
- * ```
128
- */
129
- export async function loadCategoryServiceConfig(slug) {
130
- const category = await categories
131
- .queryCategories({
132
- treeReference: {
133
- appNamespace: '@wix/stores',
134
- },
135
- })
136
- .eq('slug', slug)
137
- .find();
138
- if (category.items.length === 0) {
139
- return {
140
- type: 'not-found',
141
- };
142
- }
143
- return {
144
- type: 'success',
145
- config: {
146
- category: category.items[0],
147
- },
148
- };
149
- }