@23blocks/react 1.1.2 → 1.1.3
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/index.d.ts +1 -0
- package/dist/index.esm.js +1306 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/context.d.ts +114 -0
- package/dist/src/lib/context.d.ts.map +1 -0
- package/dist/src/lib/hooks/index.d.ts +5 -0
- package/dist/src/lib/hooks/index.d.ts.map +1 -0
- package/dist/src/lib/hooks/use-auth.d.ts +52 -0
- package/dist/src/lib/hooks/use-auth.d.ts.map +1 -0
- package/dist/src/lib/hooks/use-favorites.d.ts +41 -0
- package/dist/src/lib/hooks/use-favorites.d.ts.map +1 -0
- package/dist/src/lib/hooks/use-search.d.ts +55 -0
- package/dist/src/lib/hooks/use-search.d.ts.map +1 -0
- package/dist/src/lib/hooks/use-users.d.ts +44 -0
- package/dist/src/lib/hooks/use-users.d.ts.map +1 -0
- package/dist/src/lib/index.d.ts +4 -0
- package/dist/src/lib/index.d.ts.map +1 -0
- package/dist/src/lib/simple-provider.d.ts +281 -0
- package/dist/src/lib/simple-provider.d.ts.map +1 -0
- package/package.json +10 -8
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/lib/context.js +0 -208
- package/dist/lib/context.js.map +0 -1
- package/dist/lib/hooks/index.js +0 -8
- package/dist/lib/hooks/index.js.map +0 -1
- package/dist/lib/hooks/use-auth.js +0 -159
- package/dist/lib/hooks/use-auth.js.map +0 -1
- package/dist/lib/hooks/use-favorites.js +0 -114
- package/dist/lib/hooks/use-favorites.js.map +0 -1
- package/dist/lib/hooks/use-search.js +0 -120
- package/dist/lib/hooks/use-search.js.map +0 -1
- package/dist/lib/hooks/use-users.js +0 -115
- package/dist/lib/hooks/use-users.js.map +0 -1
- package/dist/lib/index.js +0 -17
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/simple-provider.js +0 -622
- package/dist/lib/simple-provider.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@23blocks/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "React bindings for 23blocks SDK - hooks and context providers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "23blocks <hello@23blocks.com>",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"provider"
|
|
23
23
|
],
|
|
24
24
|
"type": "module",
|
|
25
|
-
"main": "./dist/index.js",
|
|
26
|
-
"module": "./dist/index.js",
|
|
25
|
+
"main": "./dist/index.esm.js",
|
|
26
|
+
"module": "./dist/index.esm.js",
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"exports": {
|
|
29
29
|
"./package.json": "./package.json",
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
|
-
"import": "./dist/index.js",
|
|
33
|
-
"default": "./dist/index.js"
|
|
32
|
+
"import": "./dist/index.esm.js",
|
|
33
|
+
"default": "./dist/index.esm.js"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"sourceRoot": "packages/react/src",
|
|
42
42
|
"targets": {
|
|
43
43
|
"build": {
|
|
44
|
-
"executor": "@nx/
|
|
44
|
+
"executor": "@nx/rollup:rollup",
|
|
45
45
|
"outputs": [
|
|
46
46
|
"{options.outputPath}"
|
|
47
47
|
],
|
|
@@ -49,8 +49,10 @@
|
|
|
49
49
|
"outputPath": "packages/react/dist",
|
|
50
50
|
"main": "packages/react/src/index.ts",
|
|
51
51
|
"tsConfig": "packages/react/tsconfig.lib.json",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
52
|
+
"compiler": "swc",
|
|
53
|
+
"format": [
|
|
54
|
+
"esm"
|
|
55
|
+
]
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './lib/index.js';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,iBAAiB"}
|
package/dist/lib/context.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
-
import { createAuthenticationBlock } from '@23blocks/block-authentication';
|
|
4
|
-
import { createSearchBlock } from '@23blocks/block-search';
|
|
5
|
-
import { createProductsBlock } from '@23blocks/block-products';
|
|
6
|
-
import { createCrmBlock } from '@23blocks/block-crm';
|
|
7
|
-
import { createContentBlock } from '@23blocks/block-content';
|
|
8
|
-
import { createGeolocationBlock } from '@23blocks/block-geolocation';
|
|
9
|
-
import { createConversationsBlock } from '@23blocks/block-conversations';
|
|
10
|
-
import { createFilesBlock } from '@23blocks/block-files';
|
|
11
|
-
import { createFormsBlock } from '@23blocks/block-forms';
|
|
12
|
-
import { createAssetsBlock } from '@23blocks/block-assets';
|
|
13
|
-
import { createCampaignsBlock } from '@23blocks/block-campaigns';
|
|
14
|
-
import { createCompanyBlock } from '@23blocks/block-company';
|
|
15
|
-
import { createRewardsBlock } from '@23blocks/block-rewards';
|
|
16
|
-
import { createSalesBlock } from '@23blocks/block-sales';
|
|
17
|
-
import { createWalletBlock } from '@23blocks/block-wallet';
|
|
18
|
-
import { createJarvisBlock } from '@23blocks/block-jarvis';
|
|
19
|
-
import { createOnboardingBlock } from '@23blocks/block-onboarding';
|
|
20
|
-
import { createUniversityBlock } from '@23blocks/block-university';
|
|
21
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
22
|
-
// Context
|
|
23
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
24
|
-
const Blocks23ContextInternal = /*#__PURE__*/ createContext(null);
|
|
25
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
26
|
-
// Provider Component
|
|
27
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
28
|
-
/**
|
|
29
|
-
* Provider component for 23blocks services.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```tsx
|
|
33
|
-
* import { Blocks23Provider } from '@23blocks/react';
|
|
34
|
-
* import { createHttpTransport } from '@23blocks/transport-http';
|
|
35
|
-
*
|
|
36
|
-
* const transport = createHttpTransport({
|
|
37
|
-
* baseUrl: 'https://api.example.com',
|
|
38
|
-
* headers: () => ({
|
|
39
|
-
* 'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
|
40
|
-
* }),
|
|
41
|
-
* });
|
|
42
|
-
*
|
|
43
|
-
* function App() {
|
|
44
|
-
* return (
|
|
45
|
-
* <Blocks23Provider
|
|
46
|
-
* transport={transport}
|
|
47
|
-
* authentication={{ appId: 'my-app' }}
|
|
48
|
-
* search={{ appId: 'my-app' }}
|
|
49
|
-
* products={{ appId: 'my-app' }}
|
|
50
|
-
* crm={{ appId: 'my-app' }}
|
|
51
|
-
* >
|
|
52
|
-
* <MyApp />
|
|
53
|
-
* </Blocks23Provider>
|
|
54
|
-
* );
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/ export function Blocks23Provider({ children, transport, authentication, search, products, crm, content, geolocation, conversations, files, forms, assets, campaigns, company, rewards, sales, wallet, jarvis, onboarding, university }) {
|
|
58
|
-
const value = useMemo(()=>({
|
|
59
|
-
transport,
|
|
60
|
-
authentication: authentication ? createAuthenticationBlock(transport, authentication) : null,
|
|
61
|
-
search: search ? createSearchBlock(transport, search) : null,
|
|
62
|
-
products: products ? createProductsBlock(transport, products) : null,
|
|
63
|
-
crm: crm ? createCrmBlock(transport, crm) : null,
|
|
64
|
-
content: content ? createContentBlock(transport, content) : null,
|
|
65
|
-
geolocation: geolocation ? createGeolocationBlock(transport, geolocation) : null,
|
|
66
|
-
conversations: conversations ? createConversationsBlock(transport, conversations) : null,
|
|
67
|
-
files: files ? createFilesBlock(transport, files) : null,
|
|
68
|
-
forms: forms ? createFormsBlock(transport, forms) : null,
|
|
69
|
-
assets: assets ? createAssetsBlock(transport, assets) : null,
|
|
70
|
-
campaigns: campaigns ? createCampaignsBlock(transport, campaigns) : null,
|
|
71
|
-
company: company ? createCompanyBlock(transport, company) : null,
|
|
72
|
-
rewards: rewards ? createRewardsBlock(transport, rewards) : null,
|
|
73
|
-
sales: sales ? createSalesBlock(transport, sales) : null,
|
|
74
|
-
wallet: wallet ? createWalletBlock(transport, wallet) : null,
|
|
75
|
-
jarvis: jarvis ? createJarvisBlock(transport, jarvis) : null,
|
|
76
|
-
onboarding: onboarding ? createOnboardingBlock(transport, onboarding) : null,
|
|
77
|
-
university: university ? createUniversityBlock(transport, university) : null
|
|
78
|
-
}), [
|
|
79
|
-
transport,
|
|
80
|
-
authentication,
|
|
81
|
-
search,
|
|
82
|
-
products,
|
|
83
|
-
crm,
|
|
84
|
-
content,
|
|
85
|
-
geolocation,
|
|
86
|
-
conversations,
|
|
87
|
-
files,
|
|
88
|
-
forms,
|
|
89
|
-
assets,
|
|
90
|
-
campaigns,
|
|
91
|
-
company,
|
|
92
|
-
rewards,
|
|
93
|
-
sales,
|
|
94
|
-
wallet,
|
|
95
|
-
jarvis,
|
|
96
|
-
onboarding,
|
|
97
|
-
university
|
|
98
|
-
]);
|
|
99
|
-
return /*#__PURE__*/ _jsx(Blocks23ContextInternal.Provider, {
|
|
100
|
-
value: value,
|
|
101
|
-
children: children
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
105
|
-
// Context Hook
|
|
106
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
107
|
-
export function use23Blocks() {
|
|
108
|
-
const context = useContext(Blocks23ContextInternal);
|
|
109
|
-
if (!context) {
|
|
110
|
-
throw new Error('use23Blocks must be used within a Blocks23Provider');
|
|
111
|
-
}
|
|
112
|
-
return context;
|
|
113
|
-
}
|
|
114
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
115
|
-
// Block-specific hooks
|
|
116
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
117
|
-
export function useAuthenticationBlock() {
|
|
118
|
-
const { authentication } = use23Blocks();
|
|
119
|
-
if (!authentication) throw new Error('Authentication block not configured. Pass `authentication` prop to Blocks23Provider.');
|
|
120
|
-
return authentication;
|
|
121
|
-
}
|
|
122
|
-
export function useSearchBlock() {
|
|
123
|
-
const { search } = use23Blocks();
|
|
124
|
-
if (!search) throw new Error('Search block not configured. Pass `search` prop to Blocks23Provider.');
|
|
125
|
-
return search;
|
|
126
|
-
}
|
|
127
|
-
export function useProductsBlock() {
|
|
128
|
-
const { products } = use23Blocks();
|
|
129
|
-
if (!products) throw new Error('Products block not configured. Pass `products` prop to Blocks23Provider.');
|
|
130
|
-
return products;
|
|
131
|
-
}
|
|
132
|
-
export function useCrmBlock() {
|
|
133
|
-
const { crm } = use23Blocks();
|
|
134
|
-
if (!crm) throw new Error('CRM block not configured. Pass `crm` prop to Blocks23Provider.');
|
|
135
|
-
return crm;
|
|
136
|
-
}
|
|
137
|
-
export function useContentBlock() {
|
|
138
|
-
const { content } = use23Blocks();
|
|
139
|
-
if (!content) throw new Error('Content block not configured. Pass `content` prop to Blocks23Provider.');
|
|
140
|
-
return content;
|
|
141
|
-
}
|
|
142
|
-
export function useGeolocationBlock() {
|
|
143
|
-
const { geolocation } = use23Blocks();
|
|
144
|
-
if (!geolocation) throw new Error('Geolocation block not configured. Pass `geolocation` prop to Blocks23Provider.');
|
|
145
|
-
return geolocation;
|
|
146
|
-
}
|
|
147
|
-
export function useConversationsBlock() {
|
|
148
|
-
const { conversations } = use23Blocks();
|
|
149
|
-
if (!conversations) throw new Error('Conversations block not configured. Pass `conversations` prop to Blocks23Provider.');
|
|
150
|
-
return conversations;
|
|
151
|
-
}
|
|
152
|
-
export function useFilesBlock() {
|
|
153
|
-
const { files } = use23Blocks();
|
|
154
|
-
if (!files) throw new Error('Files block not configured. Pass `files` prop to Blocks23Provider.');
|
|
155
|
-
return files;
|
|
156
|
-
}
|
|
157
|
-
export function useFormsBlock() {
|
|
158
|
-
const { forms } = use23Blocks();
|
|
159
|
-
if (!forms) throw new Error('Forms block not configured. Pass `forms` prop to Blocks23Provider.');
|
|
160
|
-
return forms;
|
|
161
|
-
}
|
|
162
|
-
export function useAssetsBlock() {
|
|
163
|
-
const { assets } = use23Blocks();
|
|
164
|
-
if (!assets) throw new Error('Assets block not configured. Pass `assets` prop to Blocks23Provider.');
|
|
165
|
-
return assets;
|
|
166
|
-
}
|
|
167
|
-
export function useCampaignsBlock() {
|
|
168
|
-
const { campaigns } = use23Blocks();
|
|
169
|
-
if (!campaigns) throw new Error('Campaigns block not configured. Pass `campaigns` prop to Blocks23Provider.');
|
|
170
|
-
return campaigns;
|
|
171
|
-
}
|
|
172
|
-
export function useCompanyBlock() {
|
|
173
|
-
const { company } = use23Blocks();
|
|
174
|
-
if (!company) throw new Error('Company block not configured. Pass `company` prop to Blocks23Provider.');
|
|
175
|
-
return company;
|
|
176
|
-
}
|
|
177
|
-
export function useRewardsBlock() {
|
|
178
|
-
const { rewards } = use23Blocks();
|
|
179
|
-
if (!rewards) throw new Error('Rewards block not configured. Pass `rewards` prop to Blocks23Provider.');
|
|
180
|
-
return rewards;
|
|
181
|
-
}
|
|
182
|
-
export function useSalesBlock() {
|
|
183
|
-
const { sales } = use23Blocks();
|
|
184
|
-
if (!sales) throw new Error('Sales block not configured. Pass `sales` prop to Blocks23Provider.');
|
|
185
|
-
return sales;
|
|
186
|
-
}
|
|
187
|
-
export function useWalletBlock() {
|
|
188
|
-
const { wallet } = use23Blocks();
|
|
189
|
-
if (!wallet) throw new Error('Wallet block not configured. Pass `wallet` prop to Blocks23Provider.');
|
|
190
|
-
return wallet;
|
|
191
|
-
}
|
|
192
|
-
export function useJarvisBlock() {
|
|
193
|
-
const { jarvis } = use23Blocks();
|
|
194
|
-
if (!jarvis) throw new Error('Jarvis block not configured. Pass `jarvis` prop to Blocks23Provider.');
|
|
195
|
-
return jarvis;
|
|
196
|
-
}
|
|
197
|
-
export function useOnboardingBlock() {
|
|
198
|
-
const { onboarding } = use23Blocks();
|
|
199
|
-
if (!onboarding) throw new Error('Onboarding block not configured. Pass `onboarding` prop to Blocks23Provider.');
|
|
200
|
-
return onboarding;
|
|
201
|
-
}
|
|
202
|
-
export function useUniversityBlock() {
|
|
203
|
-
const { university } = use23Blocks();
|
|
204
|
-
if (!university) throw new Error('University block not configured. Pass `university` prop to Blocks23Provider.');
|
|
205
|
-
return university;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
//# sourceMappingURL=context.js.map
|
package/dist/lib/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/context.tsx"],"sourcesContent":["import { createContext, useContext, useMemo, type ReactNode } from 'react';\nimport type { Transport, BlockConfig } from '@23blocks/contracts';\nimport { createAuthenticationBlock, type AuthenticationBlock, type AuthenticationBlockConfig } from '@23blocks/block-authentication';\nimport { createSearchBlock, type SearchBlock, type SearchBlockConfig } from '@23blocks/block-search';\nimport { createProductsBlock, type ProductsBlock, type ProductsBlockConfig } from '@23blocks/block-products';\nimport { createCrmBlock, type CrmBlock, type CrmBlockConfig } from '@23blocks/block-crm';\nimport { createContentBlock, type ContentBlock, type ContentBlockConfig } from '@23blocks/block-content';\nimport { createGeolocationBlock, type GeolocationBlock, type GeolocationBlockConfig } from '@23blocks/block-geolocation';\nimport { createConversationsBlock, type ConversationsBlock, type ConversationsBlockConfig } from '@23blocks/block-conversations';\nimport { createFilesBlock, type FilesBlock, type FilesBlockConfig } from '@23blocks/block-files';\nimport { createFormsBlock, type FormsBlock, type FormsBlockConfig } from '@23blocks/block-forms';\nimport { createAssetsBlock, type AssetsBlock, type AssetsBlockConfig } from '@23blocks/block-assets';\nimport { createCampaignsBlock, type CampaignsBlock, type CampaignsBlockConfig } from '@23blocks/block-campaigns';\nimport { createCompanyBlock, type CompanyBlock, type CompanyBlockConfig } from '@23blocks/block-company';\nimport { createRewardsBlock, type RewardsBlock, type RewardsBlockConfig } from '@23blocks/block-rewards';\nimport { createSalesBlock, type SalesBlock, type SalesBlockConfig } from '@23blocks/block-sales';\nimport { createWalletBlock, type WalletBlock, type WalletBlockConfig } from '@23blocks/block-wallet';\nimport { createJarvisBlock, type JarvisBlock, type JarvisBlockConfig } from '@23blocks/block-jarvis';\nimport { createOnboardingBlock, type OnboardingBlock, type OnboardingBlockConfig } from '@23blocks/block-onboarding';\nimport { createUniversityBlock, type UniversityBlock, type UniversityBlockConfig } from '@23blocks/block-university';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Context Types\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface Blocks23Context {\n transport: Transport;\n authentication: AuthenticationBlock | null;\n search: SearchBlock | null;\n products: ProductsBlock | null;\n crm: CrmBlock | null;\n content: ContentBlock | null;\n geolocation: GeolocationBlock | null;\n conversations: ConversationsBlock | null;\n files: FilesBlock | null;\n forms: FormsBlock | null;\n assets: AssetsBlock | null;\n campaigns: CampaignsBlock | null;\n company: CompanyBlock | null;\n rewards: RewardsBlock | null;\n sales: SalesBlock | null;\n wallet: WalletBlock | null;\n jarvis: JarvisBlock | null;\n onboarding: OnboardingBlock | null;\n university: UniversityBlock | null;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Context\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst Blocks23ContextInternal = createContext<Blocks23Context | null>(null);\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider Props\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface Blocks23ProviderProps {\n children: ReactNode;\n transport: Transport;\n authentication?: AuthenticationBlockConfig;\n search?: SearchBlockConfig;\n products?: ProductsBlockConfig;\n crm?: CrmBlockConfig;\n content?: ContentBlockConfig;\n geolocation?: GeolocationBlockConfig;\n conversations?: ConversationsBlockConfig;\n files?: FilesBlockConfig;\n forms?: FormsBlockConfig;\n assets?: AssetsBlockConfig;\n campaigns?: CampaignsBlockConfig;\n company?: CompanyBlockConfig;\n rewards?: RewardsBlockConfig;\n sales?: SalesBlockConfig;\n wallet?: WalletBlockConfig;\n jarvis?: JarvisBlockConfig;\n onboarding?: OnboardingBlockConfig;\n university?: UniversityBlockConfig;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider Component\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Provider component for 23blocks services.\n *\n * @example\n * ```tsx\n * import { Blocks23Provider } from '@23blocks/react';\n * import { createHttpTransport } from '@23blocks/transport-http';\n *\n * const transport = createHttpTransport({\n * baseUrl: 'https://api.example.com',\n * headers: () => ({\n * 'Authorization': `Bearer ${localStorage.getItem('token')}`,\n * }),\n * });\n *\n * function App() {\n * return (\n * <Blocks23Provider\n * transport={transport}\n * authentication={{ appId: 'my-app' }}\n * search={{ appId: 'my-app' }}\n * products={{ appId: 'my-app' }}\n * crm={{ appId: 'my-app' }}\n * >\n * <MyApp />\n * </Blocks23Provider>\n * );\n * }\n * ```\n */\nexport function Blocks23Provider({\n children,\n transport,\n authentication,\n search,\n products,\n crm,\n content,\n geolocation,\n conversations,\n files,\n forms,\n assets,\n campaigns,\n company,\n rewards,\n sales,\n wallet,\n jarvis,\n onboarding,\n university,\n}: Blocks23ProviderProps) {\n const value = useMemo<Blocks23Context>(() => ({\n transport,\n authentication: authentication ? createAuthenticationBlock(transport, authentication) : null,\n search: search ? createSearchBlock(transport, search) : null,\n products: products ? createProductsBlock(transport, products) : null,\n crm: crm ? createCrmBlock(transport, crm) : null,\n content: content ? createContentBlock(transport, content) : null,\n geolocation: geolocation ? createGeolocationBlock(transport, geolocation) : null,\n conversations: conversations ? createConversationsBlock(transport, conversations) : null,\n files: files ? createFilesBlock(transport, files) : null,\n forms: forms ? createFormsBlock(transport, forms) : null,\n assets: assets ? createAssetsBlock(transport, assets) : null,\n campaigns: campaigns ? createCampaignsBlock(transport, campaigns) : null,\n company: company ? createCompanyBlock(transport, company) : null,\n rewards: rewards ? createRewardsBlock(transport, rewards) : null,\n sales: sales ? createSalesBlock(transport, sales) : null,\n wallet: wallet ? createWalletBlock(transport, wallet) : null,\n jarvis: jarvis ? createJarvisBlock(transport, jarvis) : null,\n onboarding: onboarding ? createOnboardingBlock(transport, onboarding) : null,\n university: university ? createUniversityBlock(transport, university) : null,\n }), [transport, authentication, search, products, crm, content, geolocation, conversations, files, forms, assets, campaigns, company, rewards, sales, wallet, jarvis, onboarding, university]);\n\n return (\n <Blocks23ContextInternal.Provider value={value}>\n {children}\n </Blocks23ContextInternal.Provider>\n );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Context Hook\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport function use23Blocks(): Blocks23Context {\n const context = useContext(Blocks23ContextInternal);\n if (!context) {\n throw new Error('use23Blocks must be used within a Blocks23Provider');\n }\n return context;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Block-specific hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport function useAuthenticationBlock(): AuthenticationBlock {\n const { authentication } = use23Blocks();\n if (!authentication) throw new Error('Authentication block not configured. Pass `authentication` prop to Blocks23Provider.');\n return authentication;\n}\n\nexport function useSearchBlock(): SearchBlock {\n const { search } = use23Blocks();\n if (!search) throw new Error('Search block not configured. Pass `search` prop to Blocks23Provider.');\n return search;\n}\n\nexport function useProductsBlock(): ProductsBlock {\n const { products } = use23Blocks();\n if (!products) throw new Error('Products block not configured. Pass `products` prop to Blocks23Provider.');\n return products;\n}\n\nexport function useCrmBlock(): CrmBlock {\n const { crm } = use23Blocks();\n if (!crm) throw new Error('CRM block not configured. Pass `crm` prop to Blocks23Provider.');\n return crm;\n}\n\nexport function useContentBlock(): ContentBlock {\n const { content } = use23Blocks();\n if (!content) throw new Error('Content block not configured. Pass `content` prop to Blocks23Provider.');\n return content;\n}\n\nexport function useGeolocationBlock(): GeolocationBlock {\n const { geolocation } = use23Blocks();\n if (!geolocation) throw new Error('Geolocation block not configured. Pass `geolocation` prop to Blocks23Provider.');\n return geolocation;\n}\n\nexport function useConversationsBlock(): ConversationsBlock {\n const { conversations } = use23Blocks();\n if (!conversations) throw new Error('Conversations block not configured. Pass `conversations` prop to Blocks23Provider.');\n return conversations;\n}\n\nexport function useFilesBlock(): FilesBlock {\n const { files } = use23Blocks();\n if (!files) throw new Error('Files block not configured. Pass `files` prop to Blocks23Provider.');\n return files;\n}\n\nexport function useFormsBlock(): FormsBlock {\n const { forms } = use23Blocks();\n if (!forms) throw new Error('Forms block not configured. Pass `forms` prop to Blocks23Provider.');\n return forms;\n}\n\nexport function useAssetsBlock(): AssetsBlock {\n const { assets } = use23Blocks();\n if (!assets) throw new Error('Assets block not configured. Pass `assets` prop to Blocks23Provider.');\n return assets;\n}\n\nexport function useCampaignsBlock(): CampaignsBlock {\n const { campaigns } = use23Blocks();\n if (!campaigns) throw new Error('Campaigns block not configured. Pass `campaigns` prop to Blocks23Provider.');\n return campaigns;\n}\n\nexport function useCompanyBlock(): CompanyBlock {\n const { company } = use23Blocks();\n if (!company) throw new Error('Company block not configured. Pass `company` prop to Blocks23Provider.');\n return company;\n}\n\nexport function useRewardsBlock(): RewardsBlock {\n const { rewards } = use23Blocks();\n if (!rewards) throw new Error('Rewards block not configured. Pass `rewards` prop to Blocks23Provider.');\n return rewards;\n}\n\nexport function useSalesBlock(): SalesBlock {\n const { sales } = use23Blocks();\n if (!sales) throw new Error('Sales block not configured. Pass `sales` prop to Blocks23Provider.');\n return sales;\n}\n\nexport function useWalletBlock(): WalletBlock {\n const { wallet } = use23Blocks();\n if (!wallet) throw new Error('Wallet block not configured. Pass `wallet` prop to Blocks23Provider.');\n return wallet;\n}\n\nexport function useJarvisBlock(): JarvisBlock {\n const { jarvis } = use23Blocks();\n if (!jarvis) throw new Error('Jarvis block not configured. Pass `jarvis` prop to Blocks23Provider.');\n return jarvis;\n}\n\nexport function useOnboardingBlock(): OnboardingBlock {\n const { onboarding } = use23Blocks();\n if (!onboarding) throw new Error('Onboarding block not configured. Pass `onboarding` prop to Blocks23Provider.');\n return onboarding;\n}\n\nexport function useUniversityBlock(): UniversityBlock {\n const { university } = use23Blocks();\n if (!university) throw new Error('University block not configured. Pass `university` prop to Blocks23Provider.');\n return university;\n}\n"],"names":["createContext","useContext","useMemo","createAuthenticationBlock","createSearchBlock","createProductsBlock","createCrmBlock","createContentBlock","createGeolocationBlock","createConversationsBlock","createFilesBlock","createFormsBlock","createAssetsBlock","createCampaignsBlock","createCompanyBlock","createRewardsBlock","createSalesBlock","createWalletBlock","createJarvisBlock","createOnboardingBlock","createUniversityBlock","Blocks23ContextInternal","Blocks23Provider","children","transport","authentication","search","products","crm","content","geolocation","conversations","files","forms","assets","campaigns","company","rewards","sales","wallet","jarvis","onboarding","university","value","Provider","use23Blocks","context","Error","useAuthenticationBlock","useSearchBlock","useProductsBlock","useCrmBlock","useContentBlock","useGeolocationBlock","useConversationsBlock","useFilesBlock","useFormsBlock","useAssetsBlock","useCampaignsBlock","useCompanyBlock","useRewardsBlock","useSalesBlock","useWalletBlock","useJarvisBlock","useOnboardingBlock","useUniversityBlock"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAwB,QAAQ;AAE3E,SAASC,yBAAyB,QAAkE,iCAAiC;AACrI,SAASC,iBAAiB,QAAkD,yBAAyB;AACrG,SAASC,mBAAmB,QAAsD,2BAA2B;AAC7G,SAASC,cAAc,QAA4C,sBAAsB;AACzF,SAASC,kBAAkB,QAAoD,0BAA0B;AACzG,SAASC,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;AACT;AAEA,OAAO,SAASwB;IACd,MAAM,EAAEvB,OAAO,EAAE,GAAGQ;IACpB,IAAI,CAACR,SAAS,MAAM,IAAIU,MAAM;IAC9B,OAAOV;AACT;AAEA,OAAO,SAASwB;IACd,MAAM,EAAEvB,KAAK,EAAE,GAAGO;IAClB,IAAI,CAACP,OAAO,MAAM,IAAIS,MAAM;IAC5B,OAAOT;AACT;AAEA,OAAO,SAASwB;IACd,MAAM,EAAEvB,MAAM,EAAE,GAAGM;IACnB,IAAI,CAACN,QAAQ,MAAM,IAAIQ,MAAM;IAC7B,OAAOR;AACT;AAEA,OAAO,SAASwB;IACd,MAAM,EAAEvB,MAAM,EAAE,GAAGK;IACnB,IAAI,CAACL,QAAQ,MAAM,IAAIO,MAAM;IAC7B,OAAOP;AACT;AAEA,OAAO,SAASwB;IACd,MAAM,EAAEvB,UAAU,EAAE,GAAGI;IACvB,IAAI,CAACJ,YAAY,MAAM,IAAIM,MAAM;IACjC,OAAON;AACT;AAEA,OAAO,SAASwB;IACd,MAAM,EAAEvB,UAAU,EAAE,GAAGG;IACvB,IAAI,CAACH,YAAY,MAAM,IAAIK,MAAM;IACjC,OAAOL;AACT"}
|
package/dist/lib/hooks/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Authentication hooks
|
|
2
|
-
export { useAuth } from './use-auth.js';
|
|
3
|
-
export { useUsers } from './use-users.js';
|
|
4
|
-
// Search hooks
|
|
5
|
-
export { useSearch } from './use-search.js';
|
|
6
|
-
export { useFavorites } from './use-favorites.js';
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/hooks/index.ts"],"sourcesContent":["// Authentication hooks\nexport { useAuth, type UseAuthReturn, type UseAuthState, type UseAuthActions } from './use-auth.js';\nexport { useUsers, type UseUsersReturn, type UseUsersState, type UseUsersActions } from './use-users.js';\n\n// Search hooks\nexport { useSearch, type UseSearchReturn, type UseSearchState, type UseSearchActions } from './use-search.js';\nexport { useFavorites, type UseFavoritesReturn, type UseFavoritesState, type UseFavoritesActions } from './use-favorites.js';\n"],"names":["useAuth","useUsers","useSearch","useFavorites"],"rangeMappings":";;;;;","mappings":"AAAA,uBAAuB;AACvB,SAASA,OAAO,QAAoE,gBAAgB;AACpG,SAASC,QAAQ,QAAuE,iBAAiB;AAEzG,eAAe;AACf,SAASC,SAAS,QAA0E,kBAAkB;AAC9G,SAASC,YAAY,QAAmF,qBAAqB"}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
2
|
-
import { useAuthenticationBlock } from '../context.js';
|
|
3
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
// Hook
|
|
5
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
-
/**
|
|
7
|
-
* Hook for authentication operations with state management.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* function LoginForm() {
|
|
12
|
-
* const { signIn, isLoading, error, user } = useAuth();
|
|
13
|
-
*
|
|
14
|
-
* const handleSubmit = async (e: FormEvent) => {
|
|
15
|
-
* e.preventDefault();
|
|
16
|
-
* try {
|
|
17
|
-
* await signIn({ email, password });
|
|
18
|
-
* navigate('/dashboard');
|
|
19
|
-
* } catch (err) {
|
|
20
|
-
* // Error is automatically captured in `error` state
|
|
21
|
-
* }
|
|
22
|
-
* };
|
|
23
|
-
*
|
|
24
|
-
* if (user) {
|
|
25
|
-
* return <p>Welcome, {user.email}!</p>;
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* return (
|
|
29
|
-
* <form onSubmit={handleSubmit}>
|
|
30
|
-
* {error && <p className="error">{error.message}</p>}
|
|
31
|
-
* <button disabled={isLoading}>
|
|
32
|
-
* {isLoading ? 'Signing in...' : 'Sign In'}
|
|
33
|
-
* </button>
|
|
34
|
-
* </form>
|
|
35
|
-
* );
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/ export function useAuth() {
|
|
39
|
-
const block = useAuthenticationBlock();
|
|
40
|
-
const [user, setUser] = useState(null);
|
|
41
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
42
|
-
const [error, setError] = useState(null);
|
|
43
|
-
const signIn = useCallback(async (request)=>{
|
|
44
|
-
setIsLoading(true);
|
|
45
|
-
setError(null);
|
|
46
|
-
try {
|
|
47
|
-
const response = await block.auth.signIn(request);
|
|
48
|
-
setUser(response.user);
|
|
49
|
-
return response;
|
|
50
|
-
} catch (err) {
|
|
51
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
52
|
-
setError(error);
|
|
53
|
-
throw error;
|
|
54
|
-
} finally{
|
|
55
|
-
setIsLoading(false);
|
|
56
|
-
}
|
|
57
|
-
}, [
|
|
58
|
-
block.auth
|
|
59
|
-
]);
|
|
60
|
-
const signUp = useCallback(async (request)=>{
|
|
61
|
-
setIsLoading(true);
|
|
62
|
-
setError(null);
|
|
63
|
-
try {
|
|
64
|
-
const response = await block.auth.signUp(request);
|
|
65
|
-
setUser(response.user);
|
|
66
|
-
return response;
|
|
67
|
-
} catch (err) {
|
|
68
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
69
|
-
setError(error);
|
|
70
|
-
throw error;
|
|
71
|
-
} finally{
|
|
72
|
-
setIsLoading(false);
|
|
73
|
-
}
|
|
74
|
-
}, [
|
|
75
|
-
block.auth
|
|
76
|
-
]);
|
|
77
|
-
const signOut = useCallback(async ()=>{
|
|
78
|
-
setIsLoading(true);
|
|
79
|
-
setError(null);
|
|
80
|
-
try {
|
|
81
|
-
await block.auth.signOut();
|
|
82
|
-
setUser(null);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
85
|
-
setError(error);
|
|
86
|
-
throw error;
|
|
87
|
-
} finally{
|
|
88
|
-
setIsLoading(false);
|
|
89
|
-
}
|
|
90
|
-
}, [
|
|
91
|
-
block.auth
|
|
92
|
-
]);
|
|
93
|
-
const requestPasswordReset = useCallback(async (request)=>{
|
|
94
|
-
setIsLoading(true);
|
|
95
|
-
setError(null);
|
|
96
|
-
try {
|
|
97
|
-
await block.auth.requestPasswordReset(request);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
100
|
-
setError(error);
|
|
101
|
-
throw error;
|
|
102
|
-
} finally{
|
|
103
|
-
setIsLoading(false);
|
|
104
|
-
}
|
|
105
|
-
}, [
|
|
106
|
-
block.auth
|
|
107
|
-
]);
|
|
108
|
-
const updatePassword = useCallback(async (request)=>{
|
|
109
|
-
setIsLoading(true);
|
|
110
|
-
setError(null);
|
|
111
|
-
try {
|
|
112
|
-
await block.auth.updatePassword(request);
|
|
113
|
-
} catch (err) {
|
|
114
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
115
|
-
setError(error);
|
|
116
|
-
throw error;
|
|
117
|
-
} finally{
|
|
118
|
-
setIsLoading(false);
|
|
119
|
-
}
|
|
120
|
-
}, [
|
|
121
|
-
block.auth
|
|
122
|
-
]);
|
|
123
|
-
const refreshUser = useCallback(async ()=>{
|
|
124
|
-
setIsLoading(true);
|
|
125
|
-
setError(null);
|
|
126
|
-
try {
|
|
127
|
-
const currentUser = await block.auth.getCurrentUser();
|
|
128
|
-
setUser(currentUser);
|
|
129
|
-
} catch (err) {
|
|
130
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
131
|
-
setError(error);
|
|
132
|
-
throw error;
|
|
133
|
-
} finally{
|
|
134
|
-
setIsLoading(false);
|
|
135
|
-
}
|
|
136
|
-
}, [
|
|
137
|
-
block.auth
|
|
138
|
-
]);
|
|
139
|
-
const clearError = useCallback(()=>{
|
|
140
|
-
setError(null);
|
|
141
|
-
}, []);
|
|
142
|
-
return {
|
|
143
|
-
// State
|
|
144
|
-
user,
|
|
145
|
-
isLoading,
|
|
146
|
-
error,
|
|
147
|
-
isAuthenticated: user !== null,
|
|
148
|
-
// Actions
|
|
149
|
-
signIn,
|
|
150
|
-
signUp,
|
|
151
|
-
signOut,
|
|
152
|
-
requestPasswordReset,
|
|
153
|
-
updatePassword,
|
|
154
|
-
refreshUser,
|
|
155
|
-
clearError
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
//# sourceMappingURL=use-auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/hooks/use-auth.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport type {\n User,\n SignInRequest,\n SignInResponse,\n SignUpRequest,\n SignUpResponse,\n PasswordResetRequest,\n PasswordUpdateRequest,\n} from '@23blocks/block-authentication';\nimport { useAuthenticationBlock } from '../context.js';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface UseAuthState {\n user: User | null;\n isLoading: boolean;\n error: Error | null;\n isAuthenticated: boolean;\n}\n\nexport interface UseAuthActions {\n signIn: (request: SignInRequest) => Promise<SignInResponse>;\n signUp: (request: SignUpRequest) => Promise<SignUpResponse>;\n signOut: () => Promise<void>;\n requestPasswordReset: (request: PasswordResetRequest) => Promise<void>;\n updatePassword: (request: PasswordUpdateRequest) => Promise<void>;\n refreshUser: () => Promise<void>;\n clearError: () => void;\n}\n\nexport type UseAuthReturn = UseAuthState & UseAuthActions;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Hook\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Hook for authentication operations with state management.\n *\n * @example\n * ```tsx\n * function LoginForm() {\n * const { signIn, isLoading, error, user } = useAuth();\n *\n * const handleSubmit = async (e: FormEvent) => {\n * e.preventDefault();\n * try {\n * await signIn({ email, password });\n * navigate('/dashboard');\n * } catch (err) {\n * // Error is automatically captured in `error` state\n * }\n * };\n *\n * if (user) {\n * return <p>Welcome, {user.email}!</p>;\n * }\n *\n * return (\n * <form onSubmit={handleSubmit}>\n * {error && <p className=\"error\">{error.message}</p>}\n * <button disabled={isLoading}>\n * {isLoading ? 'Signing in...' : 'Sign In'}\n * </button>\n * </form>\n * );\n * }\n * ```\n */\nexport function useAuth(): UseAuthReturn {\n const block = useAuthenticationBlock();\n\n const [user, setUser] = useState<User | null>(null);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const signIn = useCallback(async (request: SignInRequest): Promise<SignInResponse> => {\n setIsLoading(true);\n setError(null);\n try {\n const response = await block.auth.signIn(request);\n setUser(response.user);\n return response;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.auth]);\n\n const signUp = useCallback(async (request: SignUpRequest): Promise<SignUpResponse> => {\n setIsLoading(true);\n setError(null);\n try {\n const response = await block.auth.signUp(request);\n setUser(response.user);\n return response;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.auth]);\n\n const signOut = useCallback(async (): Promise<void> => {\n setIsLoading(true);\n setError(null);\n try {\n await block.auth.signOut();\n setUser(null);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.auth]);\n\n const requestPasswordReset = useCallback(async (request: PasswordResetRequest): Promise<void> => {\n setIsLoading(true);\n setError(null);\n try {\n await block.auth.requestPasswordReset(request);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.auth]);\n\n const updatePassword = useCallback(async (request: PasswordUpdateRequest): Promise<void> => {\n setIsLoading(true);\n setError(null);\n try {\n await block.auth.updatePassword(request);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.auth]);\n\n const refreshUser = useCallback(async (): Promise<void> => {\n setIsLoading(true);\n setError(null);\n try {\n const currentUser = await block.auth.getCurrentUser();\n setUser(currentUser);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.auth]);\n\n const clearError = useCallback(() => {\n setError(null);\n }, []);\n\n return {\n // State\n user,\n isLoading,\n error,\n isAuthenticated: user !== null,\n\n // Actions\n signIn,\n signUp,\n signOut,\n requestPasswordReset,\n updatePassword,\n refreshUser,\n clearError,\n };\n}\n"],"names":["useState","useCallback","useAuthenticationBlock","useAuth","block","user","setUser","isLoading","setIsLoading","error","setError","signIn","request","response","auth","err","Error","String","signUp","signOut","requestPasswordReset","updatePassword","refreshUser","currentUser","getCurrentUser","clearError","isAuthenticated"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,EAAEC,WAAW,QAAQ,QAAQ;AAU9C,SAASC,sBAAsB,QAAQ,gBAAgB;AAyBvD,gFAAgF;AAChF,OAAO;AACP,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCC,GACD,OAAO,SAASC;IACd,MAAMC,QAAQF;IAEd,MAAM,CAACG,MAAMC,QAAQ,GAAGN,SAAsB;IAC9C,MAAM,CAACO,WAAWC,aAAa,GAAGR,SAAS;IAC3C,MAAM,CAACS,OAAOC,SAAS,GAAGV,SAAuB;IAEjD,MAAMW,SAASV,YAAY,OAAOW;QAChCJ,aAAa;QACbE,SAAS;QACT,IAAI;YACF,MAAMG,WAAW,MAAMT,MAAMU,IAAI,CAACH,MAAM,CAACC;YACzCN,QAAQO,SAASR,IAAI;YACrB,OAAOQ;QACT,EAAE,OAAOE,KAAK;YACZ,MAA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Z,MAAMN,QAAQM,eAAeC,QAAQD,MAAM,IAAIC,MAAMC,OAAOF;YAC5DL,SAASD;YACT,MAAMA;QACR,SAAU;YACRD,aAAa;QACf;IACF,GAAG;QAACJ,MAAMU,IAAI;KAAC;IAEf,MAAMQ,cAAcrB,YAAY;QAC9BO,aAAa;QACbE,SAAS;QACT,IAAI;YACF,MAAMa,cAAc,MAAMnB,MAAMU,IAAI,CAACU,cAAc;YACnDlB,QAAQiB;QACV,EAAE,OAAOR,KAAK;YACZ,MAAMN,QAAQM,eAAeC,QAAQD,MAAM,IAAIC,MAAMC,OAAOF;YAC5DL,SAASD;YACT,MAAMA;QACR,SAAU;YACRD,aAAa;QACf;IACF,GAAG;QAACJ,MAAMU,IAAI;KAAC;IAEf,MAAMW,aAAaxB,YAAY;QAC7BS,SAAS;IACX,GAAG,EAAE;IAEL,OAAO;QACL,QAAQ;QACRL;QACAE;QACAE;QACAiB,iBAAiBrB,SAAS;QAE1B,UAAU;QACVM;QACAO;QACAC;QACAC;QACAC;QACAC;QACAG;IACF;AACF"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
2
|
-
import { useSearchBlock } from '../context.js';
|
|
3
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
// Hook
|
|
5
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
-
/**
|
|
7
|
-
* Hook for managing favorites.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* function FavoritesList() {
|
|
12
|
-
* const { favorites, listFavorites, removeFavorite, isLoading } = useFavorites();
|
|
13
|
-
*
|
|
14
|
-
* useEffect(() => {
|
|
15
|
-
* listFavorites();
|
|
16
|
-
* }, [listFavorites]);
|
|
17
|
-
*
|
|
18
|
-
* return (
|
|
19
|
-
* <ul>
|
|
20
|
-
* {favorites.map(fav => (
|
|
21
|
-
* <li key={fav.id}>
|
|
22
|
-
* {fav.entityDescription}
|
|
23
|
-
* <button onClick={() => removeFavorite(fav.id)}>Remove</button>
|
|
24
|
-
* </li>
|
|
25
|
-
* ))}
|
|
26
|
-
* </ul>
|
|
27
|
-
* );
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*/ export function useFavorites() {
|
|
31
|
-
const block = useSearchBlock();
|
|
32
|
-
const [favorites, setFavorites] = useState([]);
|
|
33
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
34
|
-
const [error, setError] = useState(null);
|
|
35
|
-
const listFavorites = useCallback(async ()=>{
|
|
36
|
-
setIsLoading(true);
|
|
37
|
-
setError(null);
|
|
38
|
-
try {
|
|
39
|
-
const result = await block.favorites.list();
|
|
40
|
-
setFavorites(result);
|
|
41
|
-
return result;
|
|
42
|
-
} catch (err) {
|
|
43
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
44
|
-
setError(error);
|
|
45
|
-
throw error;
|
|
46
|
-
} finally{
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
}
|
|
49
|
-
}, [
|
|
50
|
-
block.favorites
|
|
51
|
-
]);
|
|
52
|
-
const addFavorite = useCallback(async (request)=>{
|
|
53
|
-
setIsLoading(true);
|
|
54
|
-
setError(null);
|
|
55
|
-
try {
|
|
56
|
-
const favorite = await block.favorites.add(request);
|
|
57
|
-
setFavorites((prev)=>[
|
|
58
|
-
...prev,
|
|
59
|
-
favorite
|
|
60
|
-
]);
|
|
61
|
-
return favorite;
|
|
62
|
-
} catch (err) {
|
|
63
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
64
|
-
setError(error);
|
|
65
|
-
throw error;
|
|
66
|
-
} finally{
|
|
67
|
-
setIsLoading(false);
|
|
68
|
-
}
|
|
69
|
-
}, [
|
|
70
|
-
block.favorites
|
|
71
|
-
]);
|
|
72
|
-
const removeFavorite = useCallback(async (id)=>{
|
|
73
|
-
setIsLoading(true);
|
|
74
|
-
setError(null);
|
|
75
|
-
try {
|
|
76
|
-
await block.favorites.remove(id);
|
|
77
|
-
setFavorites((prev)=>prev.filter((f)=>f.id !== id));
|
|
78
|
-
} catch (err) {
|
|
79
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
80
|
-
setError(error);
|
|
81
|
-
throw error;
|
|
82
|
-
} finally{
|
|
83
|
-
setIsLoading(false);
|
|
84
|
-
}
|
|
85
|
-
}, [
|
|
86
|
-
block.favorites
|
|
87
|
-
]);
|
|
88
|
-
const isFavorite = useCallback(async (entityUniqueId)=>{
|
|
89
|
-
try {
|
|
90
|
-
return await block.favorites.isFavorite(entityUniqueId);
|
|
91
|
-
} catch (err) {
|
|
92
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
93
|
-
setError(error);
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
}, [
|
|
97
|
-
block.favorites
|
|
98
|
-
]);
|
|
99
|
-
const clearError = useCallback(()=>{
|
|
100
|
-
setError(null);
|
|
101
|
-
}, []);
|
|
102
|
-
return {
|
|
103
|
-
favorites,
|
|
104
|
-
isLoading,
|
|
105
|
-
error,
|
|
106
|
-
listFavorites,
|
|
107
|
-
addFavorite,
|
|
108
|
-
removeFavorite,
|
|
109
|
-
isFavorite,
|
|
110
|
-
clearError
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=use-favorites.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/hooks/use-favorites.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport type {\n FavoriteEntity,\n AddFavoriteRequest,\n} from '@23blocks/block-search';\nimport { useSearchBlock } from '../context.js';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface UseFavoritesState {\n favorites: FavoriteEntity[];\n isLoading: boolean;\n error: Error | null;\n}\n\nexport interface UseFavoritesActions {\n listFavorites: () => Promise<FavoriteEntity[]>;\n addFavorite: (request: AddFavoriteRequest) => Promise<FavoriteEntity>;\n removeFavorite: (id: string) => Promise<void>;\n isFavorite: (entityUniqueId: string) => Promise<boolean>;\n clearError: () => void;\n}\n\nexport type UseFavoritesReturn = UseFavoritesState & UseFavoritesActions;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Hook\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Hook for managing favorites.\n *\n * @example\n * ```tsx\n * function FavoritesList() {\n * const { favorites, listFavorites, removeFavorite, isLoading } = useFavorites();\n *\n * useEffect(() => {\n * listFavorites();\n * }, [listFavorites]);\n *\n * return (\n * <ul>\n * {favorites.map(fav => (\n * <li key={fav.id}>\n * {fav.entityDescription}\n * <button onClick={() => removeFavorite(fav.id)}>Remove</button>\n * </li>\n * ))}\n * </ul>\n * );\n * }\n * ```\n */\nexport function useFavorites(): UseFavoritesReturn {\n const block = useSearchBlock();\n\n const [favorites, setFavorites] = useState<FavoriteEntity[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const listFavorites = useCallback(async (): Promise<FavoriteEntity[]> => {\n setIsLoading(true);\n setError(null);\n try {\n const result = await block.favorites.list();\n setFavorites(result);\n return result;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.favorites]);\n\n const addFavorite = useCallback(async (\n request: AddFavoriteRequest\n ): Promise<FavoriteEntity> => {\n setIsLoading(true);\n setError(null);\n try {\n const favorite = await block.favorites.add(request);\n setFavorites(prev => [...prev, favorite]);\n return favorite;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.favorites]);\n\n const removeFavorite = useCallback(async (id: string): Promise<void> => {\n setIsLoading(true);\n setError(null);\n try {\n await block.favorites.remove(id);\n setFavorites(prev => prev.filter(f => f.id !== id));\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, [block.favorites]);\n\n const isFavorite = useCallback(async (entityUniqueId: string): Promise<boolean> => {\n try {\n return await block.favorites.isFavorite(entityUniqueId);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n }\n }, [block.favorites]);\n\n const clearError = useCallback(() => {\n setError(null);\n }, []);\n\n return {\n favorites,\n isLoading,\n error,\n listFavorites,\n addFavorite,\n removeFavorite,\n isFavorite,\n clearError,\n };\n}\n"],"names":["useState","useCallback","useSearchBlock","useFavorites","block","favorites","setFavorites","isLoading","setIsLoading","error","setError","listFavorites","result","list","err","Error","String","addFavorite","request","favorite","add","prev","removeFavorite","id","remove","filter","f","isFavorite","entityUniqueId","clearError"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,EAAEC,WAAW,QAAQ,QAAQ;AAK9C,SAASC,cAAc,QAAQ,gBAAgB;AAsB/C,gFAAgF;AAChF,OAAO;AACP,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,SAASC;IACd,MAAMC,QAAQF;IAEd,MAAM,CAACG,WAAWC,aAAa,GAAGN,SAA2B,EAAE;IAC/D,MAAM,CAACO,WAAWC,aAAa,GAAGR,SAAS;IAC3C,MAAM,CAACS,OAAOC,SAAS,GAAGV,SAAuB;IAEjD,MAAMW,gBAAgBV,YAAY;QAChCO,aAAa;QACbE,SAAS;QACT,IAAI;YACF,MAAME,SAAS,MAAMR,MAAMC,SAAS,CAACQ,IAAI;YACzCP,aAAaM;YACb,OAAOA;QACT,EAAE,OAAOE,KAAK;YACZ,MAAML,QAAQK,eAAeC,QAAQD,MAAM,IAAIC,MAAMC,OAAOF;YAC5DJ,SAASD;YACT,MAAMA;QACR,SAAU;YACRD,a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