@websolutespa/bom-mixer-hooks 1.3.0 → 1.4.1

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,5 +1,21 @@
1
1
  # @websolutespa/bom-mixer-hooks
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: useCollectionApi, useExtra.
8
+ - Modified: usePagination, useSearchParamsQs.
9
+ - Updated dependencies
10
+ - @websolutespa/bom-mixer-models@1.5.2
11
+ - @websolutespa/bom-core@0.6.2
12
+
13
+ ## 1.4.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Added useLazyModules.
18
+
3
19
  ## 1.3.0
4
20
 
5
21
  ### Minor Changes
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, IUser } from '@websolutespa/bom-mixer-models';
8
+ import { ISchema, QueryParams, IEquatable, ILabel, ILocalizable, ILayout, IPage } from '@websolutespa/bom-core';
9
+ import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, IFeatureType, 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,10 +434,17 @@ 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
 
441
+ type ILazyModulesContext = ILazyModules;
442
+ declare const useLazyModules: () => ILazyModules;
443
+ declare function LazyModulesProvider({ children, modules }: {
444
+ children?: react__default.ReactNode;
445
+ modules: ILazyModules;
446
+ }): react_jsx_runtime.JSX.Element;
447
+
395
448
  declare function useModal(): [modal: UIValue, open: (value?: string) => void, close: () => void];
396
449
 
397
450
  declare function useMounted(): boolean;
@@ -401,18 +454,20 @@ declare function useNumber(options?: Intl.NumberFormatOptions, locale?: string):
401
454
  type IPageContext = IPage;
402
455
  declare const usePage: () => NonNullable<IPage>;
403
456
  declare function PageProvider({ children, page }: {
404
- children?: React__default.ReactNode;
457
+ children?: react__default.ReactNode;
405
458
  page: IPage;
406
459
  }): react_jsx_runtime.JSX.Element;
407
460
 
408
- type IPaginationInfo<T> = {
461
+ type IPaginationInfo<T = any> = {
409
462
  items: T[];
410
- total: number;
411
- pages: number;
412
463
  page: number;
464
+ pages: number;
413
465
  perPage: number;
466
+ total: number;
414
467
  };
468
+ declare function isPaginationInfo(item: unknown): item is IPaginationInfo<any>;
415
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>;
416
471
 
417
472
  declare function usePagination<T>($items: T[], $page?: number, $perPage?: number): {
418
473
  items: T[];
@@ -506,22 +561,20 @@ type IUseSearchParamsEncodedResult = {
506
561
  };
507
562
  declare function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedResult;
508
563
 
509
- declare function getSearchParamsQs(url: string, key?: string): {} | null;
510
- 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): {
511
572
  pathname: string;
512
- query: {
513
- [key: string]: string;
514
- };
573
+ query: string;
515
574
  };
516
575
  declare function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
517
576
  declare function pushSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
518
577
  declare function replaceSearchParamsQsSilently(value: IParamsQs, key?: string): void;
519
- type IParamsQs = {};
520
- type IUseSearchParamsQsResult = {
521
- params: Record<string, any> | null;
522
- replaceParamsSilently: (params: IParamsQs) => void;
523
- replaceParams: (params: IParamsQs) => void;
524
- };
525
578
  declare function useSearchParamsQs(key?: string): IUseSearchParamsQsResult;
526
579
 
527
580
  type Sorting<T> = {
@@ -571,4 +624,4 @@ type WindowSize = {
571
624
  };
572
625
  declare function useWindowSize(): WindowSize;
573
626
 
574
- export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, ClickOutGetContainer, CurrentStateType, ElementStackItem, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, IPageContext, IPaginationInfo, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, 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, 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 };