@websolutespa/bom-mixer-hooks 1.4.0 → 1.4.2

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/CHANGELOG.md CHANGED
@@ -1,69 +1,89 @@
1
1
  # @websolutespa/bom-mixer-hooks
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: IFeatureType
8
+ - Updated dependencies
9
+ - @websolutespa/bom-mixer-models@1.5.4
10
+ - @websolutespa/bom-mixer-store@1.4.3
11
+ - @websolutespa/bom-core@0.6.5
12
+
13
+ ## 1.4.1
14
+
15
+ ### Patch Changes
16
+
17
+ - Added: useCollectionApi, useExtra
18
+ - Modified: usePagination, useSearchParamsQs
19
+ - Updated dependencies
20
+ - @websolutespa/bom-mixer-models@1.5.2
21
+ - @websolutespa/bom-core@0.6.2
22
+
3
23
  ## 1.4.0
4
24
 
5
25
  ### Minor Changes
6
26
 
7
- - Added useLazyModules.
27
+ - Added useLazyModules
8
28
 
9
29
  ## 1.3.0
10
30
 
11
31
  ### Minor Changes
12
32
 
13
- - Added: useSearchParamsQs.
14
- - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo.
33
+ - Added: useSearchParamsQs
34
+ - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo
15
35
 
16
36
  ## 1.2.1
17
37
 
18
38
  ### Patch Changes
19
39
 
20
- - Added: LabelService.
21
- - Modified: useLabels, useScrollTo.
40
+ - Added: LabelService
41
+ - Modified: useLabels, useScrollTo
22
42
 
23
43
  ## 1.2.0
24
44
 
25
45
  ### Minor Changes
26
46
 
27
- - Updating: next 13.
47
+ - Updating: next 13
28
48
 
29
49
  ## 1.1.0
30
50
 
31
51
  ### Minor Changes
32
52
 
33
- - Modified: useHttp, useApi.
53
+ - Modified: useHttp, useApi
34
54
 
35
55
  ## 1.0.0
36
56
 
37
57
  ### Minor Changes
38
58
 
39
- - Added: useScrolled.
59
+ - Added: useScrolled
40
60
 
41
61
  ## 0.2.2
42
62
 
43
63
  ### Patch Changes
44
64
 
45
- - Modified: useBreakpoint theme mediaQuery.
65
+ - Modified: useBreakpoint theme mediaQuery
46
66
 
47
67
  ## 0.2.1
48
68
 
49
69
  ### Patch Changes
50
70
 
51
- - Added: source files.
71
+ - Added: source files
52
72
 
53
73
  ## 0.2.0
54
74
 
55
75
  ### Minor Changes
56
76
 
57
- - Added: splat routes.
77
+ - Added: splat routes
58
78
 
59
79
  ## 0.1.0
60
80
 
61
81
  ### Minor Changes
62
82
 
63
- - Added: @websolutespa/bom-core.
83
+ - Added: @websolutespa/bom-core
64
84
 
65
85
  ## 0.0.2
66
86
 
67
87
  ### Patch Changes
68
88
 
69
- - Added: first release.
89
+ - Added: first release
package/dist/index.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- import * as React$1 from 'react';
2
- import React__default, { RefObject, Dispatch, SetStateAction, MutableRefObject, ComponentProps, useEffect } from 'react';
1
+ import * as react from 'react';
2
+ import react__default, { RefObject, Dispatch, SetStateAction, MutableRefObject, ComponentProps, useEffect } from 'react';
3
3
  import { ApiRequestOptions } from '@websolutespa/bom-mixer-store';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import * as zustand_middleware from 'zustand/middleware';
6
6
  import { StateStorage } from 'zustand/middleware';
7
7
  import * as zustand from 'zustand';
8
- import { ISchema, IEquatable, ILabel, ILocalizable, ILayout, IPage } from '@websolutespa/bom-core';
9
- import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, IFeatureType, ILazyModules, IUser } from '@websolutespa/bom-mixer-models';
8
+ import { ISchema, QueryParams, IEquatable, IFeatureType, ILabel, ILocalizable, ILayout, IPage } from '@websolutespa/bom-core';
9
+ import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, ILazyModules, IUser } from '@websolutespa/bom-mixer-models';
10
10
  import { NextRouter } from 'next/router';
11
11
 
12
- declare function useApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
13
- declare function useApiGet<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
14
- declare function useApiPost<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
15
- declare function useApiPut<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
16
- declare function useApiPatch<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
17
- declare function useApiDelete<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
12
+ declare function useApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
13
+ declare function useApiGet<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
14
+ declare function useApiPost<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
15
+ declare function useApiPut<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
16
+ declare function useApiPatch<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
17
+ declare function useApiDelete<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
18
18
  type Api = {
19
19
  get: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;
20
20
  post: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
@@ -60,7 +60,7 @@ type CartActions = {
60
60
  type CartState = CartProps & {
61
61
  actions: CartActions;
62
62
  };
63
- declare const CartContext: React$1.Context<(Omit<zustand.StoreApi<CartState>, "persist"> & {
63
+ declare const CartContext: react.Context<(Omit<zustand.StoreApi<CartState>, "persist"> & {
64
64
  persist: {
65
65
  setOptions: (options: Partial<zustand_middleware.PersistOptions<CartState, unknown>>) => void;
66
66
  clearStorage: () => void;
@@ -89,7 +89,7 @@ type CheckoutActions = {
89
89
  type CheckoutState = CheckoutProps & {
90
90
  actions: CheckoutActions;
91
91
  };
92
- declare const CheckoutContext: React$1.Context<(Omit<zustand.StoreApi<CheckoutState>, "persist"> & {
92
+ declare const CheckoutContext: react.Context<(Omit<zustand.StoreApi<CheckoutState>, "persist"> & {
93
93
  persist: {
94
94
  setOptions: (options: Partial<zustand_middleware.PersistOptions<CheckoutState, unknown>>) => void;
95
95
  clearStorage: () => void;
@@ -113,6 +113,45 @@ declare function useClickAnyWhere(handler: (event: MouseEvent) => void): void;
113
113
  type ClickOutGetContainer = () => HTMLElement | null;
114
114
  declare function useClickOut(ref: MutableRefObject<HTMLElement | null>, handler: (event: MouseEvent) => void): void;
115
115
 
116
+ declare function localCollectionFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
117
+ locale: string;
118
+ market: string;
119
+ }): Promise<T>;
120
+ declare function localCollectionGet<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
121
+ locale: string;
122
+ market: string;
123
+ }): Promise<T>;
124
+ declare function localCollectionPost<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
125
+ locale: string;
126
+ market: string;
127
+ }): Promise<T>;
128
+ declare function localCollectionPut<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
129
+ locale: string;
130
+ market: string;
131
+ }): Promise<T>;
132
+ declare function localCollectionPatch<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
133
+ locale: string;
134
+ market: string;
135
+ }): Promise<T>;
136
+ declare function localCollectionDelete<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
137
+ locale: string;
138
+ market: string;
139
+ }): Promise<T>;
140
+
141
+ type CollectionApi = {
142
+ get: <T = unknown>(pathname: string, params?: QueryParams, options?: ApiRequestOptions) => Promise<T>;
143
+ post: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
144
+ put: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
145
+ patch: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
146
+ delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;
147
+ };
148
+ declare function useCollectionApi(): CollectionApi;
149
+ declare function useCollectionApiGet<T = unknown>(pathname: string, params?: QueryParams, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
150
+ declare function useCollectionApiPost<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
151
+ declare function useCollectionApiPut<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
152
+ declare function useCollectionApiPatch<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
153
+ declare function useCollectionApiDelete<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, react.Dispatch<any>];
154
+
116
155
  declare function useCurrency(currency?: string, locale?: string): (value: number) => string;
117
156
 
118
157
  declare function useCurrentState<S>(initialState: S | (() => S)): CurrentStateType<S>;
@@ -161,6 +200,13 @@ declare function useEventListener_<K extends keyof HTMLElementEventMap, T extend
161
200
  declare function useEventListener_<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: RefObject<Document>, options?: boolean | AddEventListenerOptions): void;
162
201
  declare const useEventListener: typeof useEventListener_;
163
202
 
203
+ type IExtra = Record<string, any>;
204
+ declare const useExtra: () => IExtra;
205
+ declare function ExtraProvider({ children, extra }: {
206
+ children?: react__default.ReactNode;
207
+ extra: IExtra;
208
+ }): react_jsx_runtime.JSX.Element;
209
+
164
210
  type FilterParams = {
165
211
  [key: string]: IEquatable[] | null;
166
212
  };
@@ -219,7 +265,7 @@ type UseFiltersResultType<T> = {
219
265
  itemsWithOmittedKeys: (...keys: string[]) => T[];
220
266
  };
221
267
 
222
- declare const createGenericContext: <T>(defaultContext?: T | null) => readonly [() => NonNullable<T>, React$1.Provider<T | undefined>];
268
+ declare const createGenericContext: <T>(defaultContext?: T | null) => readonly [() => NonNullable<T>, react.Provider<T | undefined>];
223
269
 
224
270
  /**
225
271
  * @desc Made compatible with {GeolocationPositionError} and {PositionError} cause
@@ -360,21 +406,21 @@ type KeyboardOptions = {
360
406
  };
361
407
  type KeyboardResult = {
362
408
  bindings: {
363
- onKeyDown: React__default.KeyboardEventHandler;
364
- onKeyDownCapture: React__default.KeyboardEventHandler;
365
- onKeyPress: React__default.KeyboardEventHandler;
366
- onKeyPressCapture: React__default.KeyboardEventHandler;
367
- onKeyUp: React__default.KeyboardEventHandler;
368
- onKeyUpCapture: React__default.KeyboardEventHandler;
409
+ onKeyDown: react__default.KeyboardEventHandler;
410
+ onKeyDownCapture: react__default.KeyboardEventHandler;
411
+ onKeyPress: react__default.KeyboardEventHandler;
412
+ onKeyPressCapture: react__default.KeyboardEventHandler;
413
+ onKeyUp: react__default.KeyboardEventHandler;
414
+ onKeyUpCapture: react__default.KeyboardEventHandler;
369
415
  };
370
416
  };
371
- type UseKeyboardHandler = (event: React__default.KeyboardEvent | KeyboardEvent) => void;
417
+ type UseKeyboardHandler = (event: react__default.KeyboardEvent | KeyboardEvent) => void;
372
418
  type UseKeyboard = (handler: UseKeyboardHandler, keyBindings: Array<number> | number, options?: KeyboardOptions) => KeyboardResult;
373
419
 
374
420
  type ILabelContext = (key: string, params?: Record<string, any>) => string;
375
421
  declare const useLabel: () => ILabelContext;
376
422
  declare function LabelProvider({ children }: {
377
- children?: React__default.ReactNode;
423
+ children?: react__default.ReactNode;
378
424
  }): react_jsx_runtime.JSX.Element;
379
425
  declare class LabelService {
380
426
  labels: ILabel[];
@@ -388,14 +434,14 @@ declare function parseParams(label: string, params: Record<string, any>): string
388
434
  type ILayoutContext = ILayout;
389
435
  declare const useLayout: () => ILayout;
390
436
  declare function LayoutProvider({ children, layout }: {
391
- children?: React__default.ReactNode;
437
+ children?: react__default.ReactNode;
392
438
  layout: ILayout;
393
439
  }): react_jsx_runtime.JSX.Element;
394
440
 
395
441
  type ILazyModulesContext = ILazyModules;
396
442
  declare const useLazyModules: () => ILazyModules;
397
443
  declare function LazyModulesProvider({ children, modules }: {
398
- children?: React__default.ReactNode;
444
+ children?: react__default.ReactNode;
399
445
  modules: ILazyModules;
400
446
  }): react_jsx_runtime.JSX.Element;
401
447
 
@@ -408,18 +454,20 @@ declare function useNumber(options?: Intl.NumberFormatOptions, locale?: string):
408
454
  type IPageContext = IPage;
409
455
  declare const usePage: () => NonNullable<IPage>;
410
456
  declare function PageProvider({ children, page }: {
411
- children?: React__default.ReactNode;
457
+ children?: react__default.ReactNode;
412
458
  page: IPage;
413
459
  }): react_jsx_runtime.JSX.Element;
414
460
 
415
- type IPaginationInfo<T> = {
461
+ type IPaginationInfo<T = any> = {
416
462
  items: T[];
417
- total: number;
418
- pages: number;
419
463
  page: number;
464
+ pages: number;
420
465
  perPage: number;
466
+ total: number;
421
467
  };
468
+ declare function isPaginationInfo(item: unknown): item is IPaginationInfo<any>;
422
469
  declare function getPagedItems<T>(items: T[], page: number, perPage: number): T[];
470
+ declare function getPaginationInfo<T>(items: T[], page?: number, perPage?: number): IPaginationInfo<T>;
423
471
 
424
472
  declare function usePagination<T>($items: T[], $page?: number, $perPage?: number): {
425
473
  items: T[];
@@ -513,22 +561,20 @@ type IUseSearchParamsEncodedResult = {
513
561
  };
514
562
  declare function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedResult;
515
563
 
516
- declare function getSearchParamsQs(url: string, key?: string): {} | null;
517
- declare function updateSearchParamsQs(currentPath: string, value: IParamsQs, key?: string): {
564
+ type IParamsQs = Record<string, any>;
565
+ type IUseSearchParamsQsResult = {
566
+ params: IParamsQs;
567
+ replaceParamsSilently: (params: IParamsQs) => void;
568
+ replaceParams: (params: IParamsQs) => void;
569
+ };
570
+ declare function getSearchParamsQs(url: string, key?: string): IParamsQs;
571
+ declare function updateSearchParamsQs(url: string, value: IParamsQs, key?: string): {
518
572
  pathname: string;
519
- query: {
520
- [key: string]: string;
521
- };
573
+ query: string;
522
574
  };
523
575
  declare function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
524
576
  declare function pushSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
525
577
  declare function replaceSearchParamsQsSilently(value: IParamsQs, key?: string): void;
526
- type IParamsQs = {};
527
- type IUseSearchParamsQsResult = {
528
- params: Record<string, any> | null;
529
- replaceParamsSilently: (params: IParamsQs) => void;
530
- replaceParams: (params: IParamsQs) => void;
531
- };
532
578
  declare function useSearchParamsQs(key?: string): IUseSearchParamsQsResult;
533
579
 
534
580
  type Sorting<T> = {
@@ -578,4 +624,4 @@ type WindowSize = {
578
624
  };
579
625
  declare function useWindowSize(): WindowSize;
580
626
 
581
- export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, ClickOutGetContainer, CurrentStateType, ElementStackItem, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IPageContext, IPaginationInfo, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, LazyModulesProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, parseLabel, parseParams, pushSearchParams, pushSearchParamsEncoded, pushSearchParamsQs, replaceSearchParams, replaceSearchParamsEncoded, replaceSearchParamsEncodedSilently, replaceSearchParamsQs, replaceSearchParamsQsSilently, replaceSearchParamsSilently, scrollToRelativeY, scrollToSelector, scrollToY, setFilters, updateSearchParams, updateSearchParamsEncoded, updateSearchParamsQs, useApi, useApiDelete, useApiFetch, useApiGet, useApiPatch, useApiPost, useApiPut, useBodyScroll, useBreakpoint, useCart, useCheckout, useClickAnyWhere, useClickOut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useFilters, useGeolocation, useIdle, useInfiniteLoader, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useModal, useMounted, useNumber, usePage, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSwiperIndex, useSyncedRef, useUI, useUnit, useUnmountEffect, useUser, useWindowSize };
627
+ export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, ClickOutGetContainer, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IPageContext, IPaginationInfo, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, LazyModulesProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getPaginationInfo, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, isPaginationInfo, localCollectionDelete, localCollectionFetch, localCollectionGet, localCollectionPatch, localCollectionPost, localCollectionPut, parseLabel, parseParams, pushSearchParams, pushSearchParamsEncoded, pushSearchParamsQs, replaceSearchParams, replaceSearchParamsEncoded, replaceSearchParamsEncodedSilently, replaceSearchParamsQs, replaceSearchParamsQsSilently, replaceSearchParamsSilently, scrollToRelativeY, scrollToSelector, scrollToY, setFilters, updateSearchParams, updateSearchParamsEncoded, updateSearchParamsQs, useApi, useApiDelete, useApiFetch, useApiGet, useApiPatch, useApiPost, useApiPut, useBodyScroll, useBreakpoint, useCart, useCheckout, useClickAnyWhere, useClickOut, useCollectionApi, useCollectionApiDelete, useCollectionApiGet, useCollectionApiPatch, useCollectionApiPost, useCollectionApiPut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useExtra, useFilters, useGeolocation, useIdle, useInfiniteLoader, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useModal, useMounted, useNumber, usePage, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSwiperIndex, useSyncedRef, useUI, useUnit, useUnmountEffect, useUser, useWindowSize };