@websolutespa/bom-mixer-hooks 1.3.0 → 1.4.0

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,63 +1,69 @@
1
- # @websolutespa/bom-mixer-hooks
2
-
3
- ## 1.3.0
4
-
5
- ### Minor Changes
6
-
7
- - Added: useSearchParamsQs.
8
- - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo.
9
-
10
- ## 1.2.1
11
-
12
- ### Patch Changes
13
-
14
- - Added: LabelService.
15
- - Modified: useLabels, useScrollTo.
16
-
17
- ## 1.2.0
18
-
19
- ### Minor Changes
20
-
21
- - Updating: next 13.
22
-
23
- ## 1.1.0
24
-
25
- ### Minor Changes
26
-
27
- - Modified: useHttp, useApi.
28
-
29
- ## 1.0.0
30
-
31
- ### Minor Changes
32
-
33
- - Added: useScrolled.
34
-
35
- ## 0.2.2
36
-
37
- ### Patch Changes
38
-
39
- - Modified: useBreakpoint theme mediaQuery.
40
-
41
- ## 0.2.1
42
-
43
- ### Patch Changes
44
-
45
- - Added: source files.
46
-
47
- ## 0.2.0
48
-
49
- ### Minor Changes
50
-
51
- - Added: splat routes.
52
-
53
- ## 0.1.0
54
-
55
- ### Minor Changes
56
-
57
- - Added: @websolutespa/bom-core.
58
-
59
- ## 0.0.2
60
-
61
- ### Patch Changes
62
-
63
- - Added: first release.
1
+ # @websolutespa/bom-mixer-hooks
2
+
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added useLazyModules.
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Added: useSearchParamsQs.
14
+ - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo.
15
+
16
+ ## 1.2.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Added: LabelService.
21
+ - Modified: useLabels, useScrollTo.
22
+
23
+ ## 1.2.0
24
+
25
+ ### Minor Changes
26
+
27
+ - Updating: next 13.
28
+
29
+ ## 1.1.0
30
+
31
+ ### Minor Changes
32
+
33
+ - Modified: useHttp, useApi.
34
+
35
+ ## 1.0.0
36
+
37
+ ### Minor Changes
38
+
39
+ - Added: useScrolled.
40
+
41
+ ## 0.2.2
42
+
43
+ ### Patch Changes
44
+
45
+ - Modified: useBreakpoint theme mediaQuery.
46
+
47
+ ## 0.2.1
48
+
49
+ ### Patch Changes
50
+
51
+ - Added: source files.
52
+
53
+ ## 0.2.0
54
+
55
+ ### Minor Changes
56
+
57
+ - Added: splat routes.
58
+
59
+ ## 0.1.0
60
+
61
+ ### Minor Changes
62
+
63
+ - Added: @websolutespa/bom-core.
64
+
65
+ ## 0.0.2
66
+
67
+ ### Patch Changes
68
+
69
+ - Added: first release.
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import * as zustand_middleware from 'zustand/middleware';
6
6
  import { StateStorage } from 'zustand/middleware';
7
7
  import * as zustand from 'zustand';
8
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';
9
+ import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, IFeatureType, ILazyModules, IUser } from '@websolutespa/bom-mixer-models';
10
10
  import { NextRouter } from 'next/router';
11
11
 
12
12
  declare function useApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
@@ -392,6 +392,13 @@ declare function LayoutProvider({ children, layout }: {
392
392
  layout: ILayout;
393
393
  }): react_jsx_runtime.JSX.Element;
394
394
 
395
+ type ILazyModulesContext = ILazyModules;
396
+ declare const useLazyModules: () => ILazyModules;
397
+ declare function LazyModulesProvider({ children, modules }: {
398
+ children?: React__default.ReactNode;
399
+ modules: ILazyModules;
400
+ }): react_jsx_runtime.JSX.Element;
401
+
395
402
  declare function useModal(): [modal: UIValue, open: (value?: string) => void, close: () => void];
396
403
 
397
404
  declare function useMounted(): boolean;
@@ -571,4 +578,4 @@ type WindowSize = {
571
578
  };
572
579
  declare function useWindowSize(): WindowSize;
573
580
 
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 };
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 };
package/dist/index.js CHANGED
@@ -80,6 +80,7 @@ __export(src_exports, {
80
80
  LabelProvider: () => LabelProvider,
81
81
  LabelService: () => LabelService,
82
82
  LayoutProvider: () => LayoutProvider,
83
+ LazyModulesProvider: () => LazyModulesProvider,
83
84
  PageProvider: () => PageProvider,
84
85
  createElementWithId: () => createElementWithId,
85
86
  createGenericContext: () => createGenericContext,
@@ -146,6 +147,7 @@ __export(src_exports, {
146
147
  useKeyboard: () => useKeyboard,
147
148
  useLabel: () => useLabel,
148
149
  useLayout: () => useLayout,
150
+ useLazyModules: () => useLazyModules,
149
151
  useModal: () => useModal,
150
152
  useMounted: () => useMounted,
151
153
  useNumber: () => useNumber,
@@ -1384,6 +1386,13 @@ function parseParams(label, params) {
1384
1386
  });
1385
1387
  }
1386
1388
 
1389
+ // src/useLazyModules/useLazyModules.tsx
1390
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1391
+ var [useLazyModules, LazyModulesContextProvider] = createGenericContext({});
1392
+ function LazyModulesProvider({ children, modules }) {
1393
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LazyModulesContextProvider, { value: modules, children });
1394
+ }
1395
+
1387
1396
  // src/useModal/useModal.ts
1388
1397
  function useModal() {
1389
1398
  const modal = useUI((state) => state.views.modal);
@@ -1411,10 +1420,10 @@ function useMounted() {
1411
1420
  }
1412
1421
 
1413
1422
  // src/usePage/usePage.tsx
1414
- var import_jsx_runtime5 = require("react/jsx-runtime");
1423
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1415
1424
  var [usePage, PageContextProvider] = createGenericContext();
1416
1425
  function PageProvider({ children, page }) {
1417
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PageContextProvider, { value: page, children });
1426
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PageContextProvider, { value: page, children });
1418
1427
  }
1419
1428
 
1420
1429
  // src/usePagination/pagination.service.ts
@@ -2026,6 +2035,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
2026
2035
  LabelProvider,
2027
2036
  LabelService,
2028
2037
  LayoutProvider,
2038
+ LazyModulesProvider,
2029
2039
  PageProvider,
2030
2040
  createElementWithId,
2031
2041
  createGenericContext,
@@ -2092,6 +2102,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
2092
2102
  useKeyboard,
2093
2103
  useLabel,
2094
2104
  useLayout,
2105
+ useLazyModules,
2095
2106
  useModal,
2096
2107
  useMounted,
2097
2108
  useNumber,
package/dist/index.mjs CHANGED
@@ -1260,6 +1260,13 @@ function parseParams(label, params) {
1260
1260
  });
1261
1261
  }
1262
1262
 
1263
+ // src/useLazyModules/useLazyModules.tsx
1264
+ import { jsx as jsx5 } from "react/jsx-runtime";
1265
+ var [useLazyModules, LazyModulesContextProvider] = createGenericContext({});
1266
+ function LazyModulesProvider({ children, modules }) {
1267
+ return /* @__PURE__ */ jsx5(LazyModulesContextProvider, { value: modules, children });
1268
+ }
1269
+
1263
1270
  // src/useModal/useModal.ts
1264
1271
  function useModal() {
1265
1272
  const modal = useUI((state) => state.views.modal);
@@ -1287,10 +1294,10 @@ function useMounted() {
1287
1294
  }
1288
1295
 
1289
1296
  // src/usePage/usePage.tsx
1290
- import { jsx as jsx5 } from "react/jsx-runtime";
1297
+ import { jsx as jsx6 } from "react/jsx-runtime";
1291
1298
  var [usePage, PageContextProvider] = createGenericContext();
1292
1299
  function PageProvider({ children, page }) {
1293
- return /* @__PURE__ */ jsx5(PageContextProvider, { value: page, children });
1300
+ return /* @__PURE__ */ jsx6(PageContextProvider, { value: page, children });
1294
1301
  }
1295
1302
 
1296
1303
  // src/usePagination/pagination.service.ts
@@ -1901,6 +1908,7 @@ export {
1901
1908
  LabelProvider,
1902
1909
  LabelService,
1903
1910
  LayoutProvider,
1911
+ LazyModulesProvider,
1904
1912
  PageProvider,
1905
1913
  createElementWithId,
1906
1914
  createGenericContext,
@@ -1967,6 +1975,7 @@ export {
1967
1975
  useKeyboard,
1968
1976
  useLabel,
1969
1977
  useLayout,
1978
+ useLazyModules,
1970
1979
  useModal,
1971
1980
  useMounted,
1972
1981
  useNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-hooks",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Mixer Hooks module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
package/src/index.ts CHANGED
@@ -27,6 +27,7 @@ export * from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
27
27
  export * from './useKeyboard/useKeyboard';
28
28
  export * from './useLabel/useLabel';
29
29
  export * from './useLayout/useLayout';
30
+ export * from './useLazyModules/useLazyModules';
30
31
  export * from './useModal/useModal';
31
32
  export * from './useMounted/useMounted';
32
33
  export * from './useNumber/useNumber';
@@ -0,0 +1,13 @@
1
+ import { getClassNames } from '@websolutespa/bom-core';
2
+ import { ILazyableProps } from '@websolutespa/bom-mixer-models';
3
+
4
+ export type ComponentItem = {
5
+ title: string;
6
+ };
7
+
8
+ export const Component = ({ item }: ILazyableProps<ComponentItem>) => {
9
+ const classNames = getClassNames('component');
10
+ return (
11
+ <div className={classNames}>Component {item.title}</div>
12
+ );
13
+ };
@@ -0,0 +1,40 @@
1
+ // readme https://testing-library.com/
2
+ import { renderHook } from '@testing-library/react';
3
+ import { ILazyModules, ILazyProps } from '@websolutespa/bom-mixer-models';
4
+ import dynamic from 'next/dynamic';
5
+ import { ComponentItem } from './component';
6
+ import { LazyModulesProvider, useLazyModules } from './useLazyModules';
7
+
8
+ const LAZY_MODULES: ILazyModules = {
9
+ 'component': dynamic<ILazyProps<ComponentItem>>(() => import('./component').then(
10
+ module => module.Component
11
+ )),
12
+ };
13
+
14
+ const wrapper = (props: { children: React.ReactNode }) => (
15
+ <LazyModulesProvider modules={LAZY_MODULES}>{props.children}</LazyModulesProvider>
16
+ );
17
+
18
+ describe('useLazyModules', () => {
19
+ beforeEach(() => {
20
+ jest.spyOn(console, 'error').mockImplementation(() => { });
21
+ });
22
+
23
+ test('should not throw without provider', () => {
24
+ expect(() => {
25
+ renderHook(() => useLazyModules());
26
+ }).not.toThrow();
27
+ });
28
+
29
+ test('should not throw with provider', () => {
30
+ expect(() => {
31
+ renderHook(() => useLazyModules(), { wrapper });
32
+ }).not.toThrow();
33
+ });
34
+
35
+ test('should return modules', () => {
36
+ const { result } = renderHook(() => useLazyModules(), { wrapper });
37
+ expect(result.current).toBe(LAZY_MODULES);
38
+ });
39
+
40
+ });
@@ -0,0 +1,18 @@
1
+ import { createGenericContext } from '@websolutespa/bom-mixer-hooks';
2
+ import { ILazyModules } from '@websolutespa/bom-mixer-models';
3
+ import React from 'react';
4
+
5
+ export type ILazyModulesContext = ILazyModules;
6
+
7
+ const [useLazyModules, LazyModulesContextProvider] = createGenericContext<ILazyModulesContext>({});
8
+
9
+ function LazyModulesProvider({ children, modules }: { children?: React.ReactNode, modules: ILazyModules }) {
10
+ return (
11
+ <LazyModulesContextProvider value={modules}>
12
+ {children}
13
+ </LazyModulesContextProvider>
14
+ );
15
+ }
16
+
17
+ export { LazyModulesProvider, useLazyModules };
18
+