@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,81 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createServicesMap } from '@wix/services-manager';
3
- import { useService, WixServices } from '@wix/services-manager-react';
4
- import { CategoryService, CategoryServiceDefinition, } from '../../services/category-service.js';
5
- /**
6
- * Root component that provides the Category service context to its children.
7
- * This component sets up the necessary services for managing category state.
8
- *
9
- * @order 1
10
- * @component
11
- * @example
12
- * ```tsx
13
- * import { CategoryCore } from '@wix/stores/components';
14
- *
15
- * function CategoryPage() {
16
- * return (
17
- * <Category.Root categoryServiceConfig={{ category: myCategory }}>
18
- * <Category.Name>
19
- * {({ name }) => <h1>{name}</h1>}
20
- * </Category.Name>
21
- * <Category.Slug>
22
- * {({ slug }) => <p>Slug: {slug}</p>}
23
- * </Category.Slug>
24
- * </Category.Root>
25
- * );
26
- * }
27
- * ```
28
- */
29
- export function Root(props) {
30
- return (_jsx(WixServices, { servicesMap: createServicesMap().addService(CategoryServiceDefinition, CategoryService, props.categoryServiceConfig), children: props.children }));
31
- }
32
- /**
33
- * Headless component for category name display
34
- *
35
- * @component
36
- * @example
37
- * ```tsx
38
- * import { CategoryCore } from '@wix/stores/components';
39
- *
40
- * function CategoryHeader() {
41
- * return (
42
- * <Category.Name>
43
- * {({ name }) => (
44
- * <h1 className="category-title">{name}</h1>
45
- * )}
46
- * </Category.Name>
47
- * );
48
- * }
49
- * ```
50
- */
51
- export function Name(props) {
52
- const categoryService = useService(CategoryServiceDefinition);
53
- return typeof props.children === 'function'
54
- ? props.children({ name: categoryService.category.get().name })
55
- : props.children;
56
- }
57
- /**
58
- * Headless component for category slug display
59
- *
60
- * @component
61
- * @example
62
- * ```tsx
63
- * import { CategoryCore } from '@wix/stores/components';
64
- *
65
- * function CategoryInfo() {
66
- * return (
67
- * <Category.Slug>
68
- * {({ slug }) => (
69
- * <p className="category-slug">Category slug: {slug}</p>
70
- * )}
71
- * </Category.Slug>
72
- * );
73
- * }
74
- * ```
75
- */
76
- export function Slug(props) {
77
- const categoryService = useService(CategoryServiceDefinition);
78
- return typeof props.children === 'function'
79
- ? props.children({ slug: categoryService.category.get().slug })
80
- : props.children;
81
- }
@@ -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
- }
@@ -1,98 +0,0 @@
1
- import { type CategoryServiceConfig } from '../../services/category-service.js';
2
- export interface RootProps {
3
- children: React.ReactNode;
4
- categoryServiceConfig: CategoryServiceConfig;
5
- }
6
- /**
7
- * Root component that provides the Category service context to its children.
8
- * This component sets up the necessary services for managing category state.
9
- *
10
- * @order 1
11
- * @component
12
- * @example
13
- * ```tsx
14
- * import { CategoryCore } from '@wix/stores/components';
15
- *
16
- * function CategoryPage() {
17
- * return (
18
- * <Category.Root categoryServiceConfig={{ category: myCategory }}>
19
- * <Category.Name>
20
- * {({ name }) => <h1>{name}</h1>}
21
- * </Category.Name>
22
- * <Category.Slug>
23
- * {({ slug }) => <p>Slug: {slug}</p>}
24
- * </Category.Slug>
25
- * </Category.Root>
26
- * );
27
- * }
28
- * ```
29
- */
30
- export declare function Root(props: RootProps): React.ReactNode;
31
- /**
32
- * Props for Name headless component
33
- */
34
- export interface NameProps {
35
- /** Content to display (can be a render function receiving name data or ReactNode) */
36
- children: ((props: NameRenderProps) => React.ReactNode) | React.ReactNode;
37
- }
38
- /**
39
- * Render props for Name component
40
- */
41
- export interface NameRenderProps {
42
- /** Category name */
43
- name: string;
44
- }
45
- /**
46
- * Headless component for category name display
47
- *
48
- * @component
49
- * @example
50
- * ```tsx
51
- * import { CategoryCore } from '@wix/stores/components';
52
- *
53
- * function CategoryHeader() {
54
- * return (
55
- * <Category.Name>
56
- * {({ name }) => (
57
- * <h1 className="category-title">{name}</h1>
58
- * )}
59
- * </Category.Name>
60
- * );
61
- * }
62
- * ```
63
- */
64
- export declare function Name(props: NameProps): import("react").ReactNode;
65
- /**
66
- * Props for Slug headless component
67
- */
68
- export interface SlugProps {
69
- /** Content to display (can be a render function receiving slug data or ReactNode) */
70
- children: ((props: SlugRenderProps) => React.ReactNode) | React.ReactNode;
71
- }
72
- /**
73
- * Render props for Slug component
74
- */
75
- export interface SlugRenderProps {
76
- /** Category slug */
77
- slug: string;
78
- }
79
- /**
80
- * Headless component for category slug display
81
- *
82
- * @component
83
- * @example
84
- * ```tsx
85
- * import { CategoryCore } from '@wix/stores/components';
86
- *
87
- * function CategoryInfo() {
88
- * return (
89
- * <Category.Slug>
90
- * {({ slug }) => (
91
- * <p className="category-slug">Category slug: {slug}</p>
92
- * )}
93
- * </Category.Slug>
94
- * );
95
- * }
96
- * ```
97
- */
98
- export declare function Slug(props: SlugProps): import("react").ReactNode;
@@ -1,81 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createServicesMap } from '@wix/services-manager';
3
- import { useService, WixServices } from '@wix/services-manager-react';
4
- import { CategoryService, CategoryServiceDefinition, } from '../../services/category-service.js';
5
- /**
6
- * Root component that provides the Category service context to its children.
7
- * This component sets up the necessary services for managing category state.
8
- *
9
- * @order 1
10
- * @component
11
- * @example
12
- * ```tsx
13
- * import { CategoryCore } from '@wix/stores/components';
14
- *
15
- * function CategoryPage() {
16
- * return (
17
- * <Category.Root categoryServiceConfig={{ category: myCategory }}>
18
- * <Category.Name>
19
- * {({ name }) => <h1>{name}</h1>}
20
- * </Category.Name>
21
- * <Category.Slug>
22
- * {({ slug }) => <p>Slug: {slug}</p>}
23
- * </Category.Slug>
24
- * </Category.Root>
25
- * );
26
- * }
27
- * ```
28
- */
29
- export function Root(props) {
30
- return (_jsx(WixServices, { servicesMap: createServicesMap().addService(CategoryServiceDefinition, CategoryService, props.categoryServiceConfig), children: props.children }));
31
- }
32
- /**
33
- * Headless component for category name display
34
- *
35
- * @component
36
- * @example
37
- * ```tsx
38
- * import { CategoryCore } from '@wix/stores/components';
39
- *
40
- * function CategoryHeader() {
41
- * return (
42
- * <Category.Name>
43
- * {({ name }) => (
44
- * <h1 className="category-title">{name}</h1>
45
- * )}
46
- * </Category.Name>
47
- * );
48
- * }
49
- * ```
50
- */
51
- export function Name(props) {
52
- const categoryService = useService(CategoryServiceDefinition);
53
- return typeof props.children === 'function'
54
- ? props.children({ name: categoryService.category.get().name })
55
- : props.children;
56
- }
57
- /**
58
- * Headless component for category slug display
59
- *
60
- * @component
61
- * @example
62
- * ```tsx
63
- * import { CategoryCore } from '@wix/stores/components';
64
- *
65
- * function CategoryInfo() {
66
- * return (
67
- * <Category.Slug>
68
- * {({ slug }) => (
69
- * <p className="category-slug">Category slug: {slug}</p>
70
- * )}
71
- * </Category.Slug>
72
- * );
73
- * }
74
- * ```
75
- */
76
- export function Slug(props) {
77
- const categoryService = useService(CategoryServiceDefinition);
78
- return typeof props.children === 'function'
79
- ? props.children({ slug: categoryService.category.get().slug })
80
- : props.children;
81
- }