@ssa-ui-kit/hooks 2.0.0 → 2.1.0-canary-afe713f-20250306

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 SSA Group
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 SSA Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -4,4 +4,8 @@ export { useClickOutside } from './useClickOutside';
4
4
  export { usePaginationRange } from './pagination/usePaginationRange';
5
5
  export { useTextSizeDecrease } from './text/useTextSizeDecrease';
6
6
  export { useDeviceType } from './useDeviceType';
7
+ export { useToggle } from './useToggle';
8
+ export { useUncontrolled } from './useUncontrolled';
9
+ export { createSafeContext } from './useSafeContext';
10
+ export { useResizeObserver, useElementSize } from './useResizeObserver';
7
11
  export * from './mediaQueries';
@@ -0,0 +1,8 @@
1
+ type ObserverRect = Omit<DOMRectReadOnly, 'toJSON'>;
2
+ export declare function useResizeObserver<T extends HTMLElement>(options?: ResizeObserverOptions): readonly [import("react").RefObject<T>, ObserverRect];
3
+ export declare function useElementSize<T extends HTMLElement>(options?: ResizeObserverOptions): {
4
+ ref: import("react").RefObject<T>;
5
+ width: number;
6
+ height: number;
7
+ };
8
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare function createSafeContext<ContextValue>(errorMessage: string): readonly [({ children, value, }: {
2
+ value: ContextValue;
3
+ children: React.ReactNode;
4
+ }) => import("react").FunctionComponentElement<import("react").ProviderProps<ContextValue | null>>, () => ContextValue & ({} | undefined)];
@@ -0,0 +1 @@
1
+ export declare function useToggle<T = boolean>(options?: readonly T[]): readonly [T, (value?: React.SetStateAction<T>) => void];
@@ -0,0 +1,12 @@
1
+ interface UseUncontrolledInput<T, P extends unknown[]> {
2
+ value?: T;
3
+ defaultValue?: T;
4
+ finalValue?: T;
5
+ onChange?: (value: T, ...payload: P) => void;
6
+ }
7
+ export declare function useUncontrolled<T, P extends unknown[]>({ value, defaultValue, finalValue, onChange, }: UseUncontrolledInput<T, P>): [
8
+ T,
9
+ (value: T, ...payload: P) => void,
10
+ boolean
11
+ ];
12
+ export {};
package/dist/index.js CHANGED
@@ -49,15 +49,20 @@ __webpack_require__.r(__webpack_exports__);
49
49
 
50
50
  // EXPORTS
51
51
  __webpack_require__.d(__webpack_exports__, {
52
+ createSafeContext: () => (/* reexport */ createSafeContext),
52
53
  useApi: () => (/* reexport */ useApi),
53
54
  useClickOutside: () => (/* reexport */ useClickOutside),
54
55
  useDeviceType: () => (/* reexport */ useDeviceType),
56
+ useElementSize: () => (/* reexport */ useElementSize),
55
57
  useMinLGMediaQuery: () => (/* reexport */ useMinLGMediaQuery),
56
58
  useMinMDMediaQuery: () => (/* reexport */ useMinMDMediaQuery),
57
59
  useMinXLGMediaQuery: () => (/* reexport */ useMinXLGMediaQuery),
58
60
  usePaginationRange: () => (/* reexport */ usePaginationRange),
61
+ useResizeObserver: () => (/* reexport */ useResizeObserver),
59
62
  useSMMediaQuery: () => (/* reexport */ useSMMediaQuery),
60
63
  useTextSizeDecrease: () => (/* reexport */ useTextSizeDecrease),
64
+ useToggle: () => (/* reexport */ useToggle),
65
+ useUncontrolled: () => (/* reexport */ useUncontrolled),
61
66
  useUpToMDMediaQuery: () => (/* reexport */ useUpToMDMediaQuery),
62
67
  useWindowSize: () => (/* reexport */ useWindowSize),
63
68
  useXSMediaQuery: () => (/* reexport */ useXSMediaQuery)
@@ -152,12 +157,12 @@ const resize = (el, step) => {
152
157
  }
153
158
  };
154
159
 
155
- /**
156
- * The hook does N attempts to decrease the font size
157
- * if its text content doesn't fit its parent's width.
158
- * If the text still overflows, it sets the `word-break` css rule.
159
- * The hook doesn't enlarge the font size if the parent's
160
- * width becomes wider.
160
+ /**
161
+ * The hook does N attempts to decrease the font size
162
+ * if its text content doesn't fit its parent's width.
163
+ * If the text still overflows, it sets the `word-break` css rule.
164
+ * The hook doesn't enlarge the font size if the parent's
165
+ * width becomes wider.
161
166
  * */
162
167
  const useTextSizeDecrease = (maxAttempts = 5, step = 1) => {
163
168
  const textContainerRef = (0,external_react_namespaceObject.useRef)(null);
@@ -205,6 +210,106 @@ const useDeviceType = () => {
205
210
  }
206
211
  return 'mobile';
207
212
  };
213
+ ;// ./src/hooks/useToggle.ts
214
+
215
+ function useToggle(options = [false, true]) {
216
+ const [[option], toggle] = (0,external_react_namespaceObject.useReducer)((state, action) => {
217
+ const value = action instanceof Function ? action(state[0]) : action;
218
+ const index = Math.abs(state.indexOf(value));
219
+ return state.slice(index).concat(state.slice(0, index));
220
+ }, options);
221
+ return [option, toggle];
222
+ }
223
+ ;// ./src/hooks/useUncontrolled.ts
224
+
225
+ function useUncontrolled({
226
+ value,
227
+ defaultValue,
228
+ finalValue,
229
+ onChange = () => {}
230
+ }) {
231
+ const [uncontrolledValue, setUncontrolledValue] = (0,external_react_namespaceObject.useState)(defaultValue !== undefined ? defaultValue : finalValue);
232
+ const handleUncontrolledChange = (val, ...payload) => {
233
+ setUncontrolledValue(val);
234
+ onChange?.(val, ...payload);
235
+ };
236
+ if (value !== undefined) {
237
+ return [value, onChange, true];
238
+ }
239
+ return [uncontrolledValue, handleUncontrolledChange, false];
240
+ }
241
+ ;// ./src/hooks/useSafeContext.tsx
242
+
243
+ function createSafeContext(errorMessage) {
244
+ const Context = /*#__PURE__*/(0,external_react_namespaceObject.createContext)(null);
245
+ const useSafeContext = () => {
246
+ const ctx = (0,external_react_namespaceObject.useContext)(Context);
247
+ if (ctx === null) {
248
+ throw new Error(errorMessage);
249
+ }
250
+ return ctx;
251
+ };
252
+ const Provider = ({
253
+ children,
254
+ value
255
+ }) => {
256
+ return /*#__PURE__*/(0,external_react_namespaceObject.createElement)(Context.Provider, {
257
+ value
258
+ }, children);
259
+ };
260
+ return [Provider, useSafeContext];
261
+ }
262
+ ;// ./src/hooks/useResizeObserver.tsx
263
+
264
+ const defaultState = {
265
+ x: 0,
266
+ y: 0,
267
+ width: 0,
268
+ height: 0,
269
+ top: 0,
270
+ left: 0,
271
+ bottom: 0,
272
+ right: 0
273
+ };
274
+ function useResizeObserver(options) {
275
+ const frameID = (0,external_react_namespaceObject.useRef)(0);
276
+ const ref = (0,external_react_namespaceObject.useRef)(null);
277
+ const [rect, setRect] = (0,external_react_namespaceObject.useState)(defaultState);
278
+ const observer = (0,external_react_namespaceObject.useMemo)(() => typeof window !== 'undefined' ? new ResizeObserver(entries => {
279
+ const entry = entries[0];
280
+ if (entry) {
281
+ cancelAnimationFrame(frameID.current);
282
+ frameID.current = requestAnimationFrame(() => {
283
+ if (ref.current) {
284
+ setRect(entry.contentRect);
285
+ }
286
+ });
287
+ }
288
+ }) : null, []);
289
+ (0,external_react_namespaceObject.useEffect)(() => {
290
+ if (ref.current) {
291
+ observer?.observe(ref.current, options);
292
+ }
293
+ return () => {
294
+ observer?.disconnect();
295
+ if (frameID.current) {
296
+ cancelAnimationFrame(frameID.current);
297
+ }
298
+ };
299
+ }, [ref.current]);
300
+ return [ref, rect];
301
+ }
302
+ function useElementSize(options) {
303
+ const [ref, {
304
+ width,
305
+ height
306
+ }] = useResizeObserver(options);
307
+ return {
308
+ ref,
309
+ width,
310
+ height
311
+ };
312
+ }
208
313
  ;// ./src/hooks/mediaQueries.ts
209
314
 
210
315
  const useXSMediaQuery = () => {
@@ -233,6 +338,10 @@ const useMinXLGMediaQuery = () => {
233
338
 
234
339
 
235
340
 
341
+
342
+
343
+
344
+
236
345
  ;// ./src/index.ts
237
346
 
238
347
  /******/ return __webpack_exports__;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;;UCVA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WAC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AAC;;ACxBiC;AACgB;AACE;AACiB;AACJ;AACjB","sources":["webpack://SSAHooks/webpack/universalModuleDefinition","webpack://SSAHooks/webpack/bootstrap","webpack://SSAHooks/webpack/runtime/define property getters","webpack://SSAHooks/webpack/runtime/hasOwnProperty shorthand","webpack://SSAHooks/webpack/runtime/make namespace object","webpack://SSAHooks/external commonjs \"react\"","webpack://SSAHooks/./src/hooks/useApi.tsx","webpack://SSAHooks/./src/hooks/useWindowResize.tsx","webpack://SSAHooks/./src/hooks/useClickOutside.tsx","webpack://SSAHooks/external commonjs \"@ssa-ui-kit/utils\"","webpack://SSAHooks/./src/hooks/pagination/usePaginationRange.tsx","webpack://SSAHooks/./src/hooks/text/useTextSizeDecrease.ts","webpack://SSAHooks/external commonjs \"usehooks-ts\"","webpack://SSAHooks/./src/hooks/useDeviceType.ts","webpack://SSAHooks/./src/hooks/mediaQueries.ts","webpack://SSAHooks/./src/hooks/index.ts","webpack://SSAHooks/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SSAHooks\"] = factory();\n\telse\n\t\troot[\"SSAHooks\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","import { useState } from 'react';\r\n\r\nexport function useApi<T extends unknown[], D>(\r\n fetcherFn: (...args: T) => Promise<D>,\r\n initialValue?: D,\r\n) {\r\n const [isLoading, setIsLoading] = useState<boolean>(false);\r\n const [error, setError] = useState<unknown | null>(null);\r\n const [data, setData] = useState<D | undefined>(initialValue);\r\n\r\n const query = async (...args: Parameters<typeof fetcherFn>) => {\r\n setIsLoading(true);\r\n setError(null);\r\n\r\n try {\r\n const respData = await fetcherFn(...args);\r\n setData(respData);\r\n } catch (err) {\r\n setError(err);\r\n } finally {\r\n setIsLoading(false);\r\n }\r\n };\r\n\r\n return {\r\n isLoading,\r\n error,\r\n // TODO: useApi users should use type guards instead of \"data as D\"\r\n data: data as D,\r\n query,\r\n };\r\n}\r\n","import { useEffect, useState } from 'react';\r\n\r\nexport const useWindowSize = () => {\r\n const [windowSize, setWindowSize] = useState({\r\n width: window.innerWidth,\r\n height: window.innerHeight,\r\n });\r\n\r\n useEffect(() => {\r\n function handleResize() {\r\n setWindowSize({ width: window.innerWidth, height: window.innerHeight });\r\n }\r\n\r\n window.addEventListener('resize', handleResize);\r\n\r\n handleResize();\r\n\r\n return () => window.removeEventListener('resize', handleResize);\r\n }, []);\r\n\r\n return windowSize;\r\n};\r\n","import { useEffect } from 'react';\r\n\r\ntype UseClickOutsideType = (\r\n ref: React.RefObject<HTMLElement | null>,\r\n fn: (e: Event) => void,\r\n) => void;\r\n\r\nexport const useClickOutside: UseClickOutsideType = (ref, onClickOutside) => {\r\n const events = ['mousedown', 'touchstart'];\r\n\r\n useEffect(() => {\r\n const handler = (e: Event) => {\r\n if (\r\n ref.current == null ||\r\n ref.current.contains(e.target as HTMLElement)\r\n ) {\r\n return;\r\n }\r\n onClickOutside(e);\r\n };\r\n\r\n events.forEach((eventName) =>\r\n document.addEventListener(eventName, handler),\r\n );\r\n\r\n return () =>\r\n events.forEach((eventName) =>\r\n document.removeEventListener(eventName, handler),\r\n );\r\n }, [ref, onClickOutside]);\r\n};\r\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@ssa-ui-kit/utils\");","import { useMemo } from 'react';\r\nimport { generateRange } from '@ssa-ui-kit/utils';\r\nimport { UsePaginationRangeProps } from './types';\r\n\r\nconst usePaginationRange = ({\r\n pagesCount,\r\n selectedPage,\r\n}: UsePaginationRangeProps) => {\r\n return useMemo(\r\n () => generateRange(pagesCount, selectedPage),\r\n [pagesCount, selectedPage],\r\n );\r\n};\r\n\r\nexport { usePaginationRange };\r\n","import { useEffect, useRef } from 'react';\r\nimport { useWindowSize } from '@hooks/useWindowResize';\r\n\r\nconst FONT_SIZE_REG_EXP = /(\\d+\\.?\\d+)(\\S+)/;\r\n\r\nconst isOverflowing = (\r\n el: HTMLElement,\r\n container: HTMLElement | null,\r\n): boolean => el.scrollWidth > Number(container?.clientWidth);\r\n\r\nconst resize = (el: HTMLElement, step: number) => {\r\n const fontSize = window.getComputedStyle(el).fontSize;\r\n const matchResults = fontSize.match(FONT_SIZE_REG_EXP);\r\n\r\n if (matchResults) {\r\n const [, fsValue, fsUnit] = matchResults;\r\n el.style.fontSize = `${Number(fsValue) - step}${fsUnit}`;\r\n }\r\n};\r\n\r\n/**\r\n * The hook does N attempts to decrease the font size\r\n * if its text content doesn't fit its parent's width.\r\n * If the text still overflows, it sets the `word-break` css rule.\r\n * The hook doesn't enlarge the font size if the parent's\r\n * width becomes wider.\r\n * */\r\nexport const useTextSizeDecrease = (maxAttempts = 5, step = 1) => {\r\n const textContainerRef = useRef<HTMLElement>(null);\r\n const attemptsRef = useRef<number>(0);\r\n const { width } = useWindowSize();\r\n\r\n const checkAndResize = () => {\r\n if (textContainerRef.current == null) {\r\n return;\r\n }\r\n\r\n const node = textContainerRef.current;\r\n const parentNode = node.parentNode as unknown as HTMLElement;\r\n\r\n let isLarger = isOverflowing(node, parentNode);\r\n\r\n while (attemptsRef.current < maxAttempts && isLarger) {\r\n resize(node, step);\r\n isLarger = isOverflowing(node, parentNode);\r\n ++attemptsRef.current;\r\n }\r\n\r\n if (isLarger) {\r\n node.style.wordBreak = 'break-all';\r\n }\r\n };\r\n\r\n useEffect(() => {\r\n checkAndResize();\r\n }, [textContainerRef, width]);\r\n\r\n return textContainerRef;\r\n};\r\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"usehooks-ts\");","import { useMediaQuery } from 'usehooks-ts';\r\n\r\nexport const useDeviceType = () => {\r\n const isMD = useMediaQuery('(min-width: 900px)');\r\n const isLG = useMediaQuery('(min-width: 1440px)');\r\n const isXLG = useMediaQuery('(min-width: 1920px)');\r\n if (isXLG) {\r\n return 'xlg';\r\n }\r\n if (isLG) {\r\n return 'lg';\r\n }\r\n if (isMD) {\r\n return 'md';\r\n }\r\n return 'mobile';\r\n};\r\n","import { useMediaQuery } from 'usehooks-ts';\r\n\r\nexport const useXSMediaQuery = () => {\r\n return useMediaQuery('(max-width: 389.99px)');\r\n};\r\n\r\nexport const useSMMediaQuery = () => {\r\n return useMediaQuery('(min-width: 390px)');\r\n};\r\n\r\nexport const useUpToMDMediaQuery = () => {\r\n return useMediaQuery('(max-width: 899.99px)');\r\n};\r\n\r\nexport const useMinMDMediaQuery = () => {\r\n return useMediaQuery('(min-width: 900px)');\r\n};\r\n\r\nexport const useMinLGMediaQuery = () => {\r\n return useMediaQuery('(min-width: 1440px)');\r\n};\r\n\r\nexport const useMinXLGMediaQuery = () => {\r\n return useMediaQuery('(min-width: 1920px)');\r\n};\r\n","export { useApi } from './useApi';\r\nexport { useWindowSize } from './useWindowResize';\r\nexport { useClickOutside } from './useClickOutside';\r\nexport { usePaginationRange } from './pagination/usePaginationRange';\r\nexport { useTextSizeDecrease } from './text/useTextSizeDecrease';\r\nexport { useDeviceType } from './useDeviceType';\r\nexport * from './mediaQueries';\r\n","export * from './hooks';\r\n"],"names":["useState","useApi","fetcherFn","initialValue","isLoading","setIsLoading","error","setError","data","setData","query","args","respData","err","useEffect","useWindowSize","windowSize","setWindowSize","width","window","innerWidth","height","innerHeight","handleResize","addEventListener","removeEventListener","useClickOutside","ref","onClickOutside","events","handler","e","current","contains","target","forEach","eventName","document","useMemo","generateRange","usePaginationRange","pagesCount","selectedPage","useRef","FONT_SIZE_REG_EXP","isOverflowing","el","container","scrollWidth","Number","clientWidth","resize","step","fontSize","getComputedStyle","matchResults","match","fsValue","fsUnit","style","useTextSizeDecrease","maxAttempts","textContainerRef","attemptsRef","checkAndResize","node","parentNode","isLarger","wordBreak","useMediaQuery","useDeviceType","isMD","isLG","isXLG","useXSMediaQuery","useSMMediaQuery","useUpToMDMediaQuery","useMinMDMediaQuery","useMinLGMediaQuery","useMinXLGMediaQuery"],"sourceRoot":""}
1
+ {"version":3,"file":"index.js","mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;;UCVA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNA,MAAM,8BAA4B;;ACAD;AAE1B,SAASC,MAAMA,CACpBC,SAAqC,EACrCC,YAAgB,EAChB;EACA,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGL,2CAAQ,CAAU,KAAK,CAAC;EAC1D,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGP,2CAAQ,CAAiB,IAAI,CAAC;EACxD,MAAM,CAACQ,IAAI,EAAEC,OAAO,CAAC,GAAGT,2CAAQ,CAAgBG,YAAY,CAAC;EAE7D,MAAMO,KAAK,GAAG,MAAAA,CAAO,GAAGC,IAAkC,KAAK;IAC7DN,YAAY,CAAC,IAAI,CAAC;IAClBE,QAAQ,CAAC,IAAI,CAAC;IAEd,IAAI;MACF,MAAMK,QAAQ,GAAG,MAAMV,SAAS,CAA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AA,KAAM;EACtC,OAAOjE,sDAAa,CAAC,oBAAoB,CAAC;AAC5C,CAAC;AAEM,MAAMkE,kBAAkB,GAAGA,CAAA,KAAM;EACtC,OAAOlE,sDAAa,CAAC,qBAAqB,CAAC;AAC7C,CAAC;AAEM,MAAMmE,mBAAmB,GAAGA,CAAA,KAAM;EACvC,OAAOnE,sDAAa,CAAC,qBAAqB,CAAC;AAC7C,CAAC;;ACxBiC;AACgB;AACE;AACiB;AACJ;AACjB;AACR;AACY;AACC;AACmB","sources":["webpack://SSAHooks/webpack/universalModuleDefinition","webpack://SSAHooks/webpack/bootstrap","webpack://SSAHooks/webpack/runtime/define property getters","webpack://SSAHooks/webpack/runtime/hasOwnProperty shorthand","webpack://SSAHooks/webpack/runtime/make namespace object","webpack://SSAHooks/external commonjs \"react\"","webpack://SSAHooks/./src/hooks/useApi.tsx","webpack://SSAHooks/./src/hooks/useWindowResize.tsx","webpack://SSAHooks/./src/hooks/useClickOutside.tsx","webpack://SSAHooks/external commonjs \"@ssa-ui-kit/utils\"","webpack://SSAHooks/./src/hooks/pagination/usePaginationRange.tsx","webpack://SSAHooks/./src/hooks/text/useTextSizeDecrease.ts","webpack://SSAHooks/external commonjs \"usehooks-ts\"","webpack://SSAHooks/./src/hooks/useDeviceType.ts","webpack://SSAHooks/./src/hooks/useToggle.ts","webpack://SSAHooks/./src/hooks/useUncontrolled.ts","webpack://SSAHooks/./src/hooks/useSafeContext.tsx","webpack://SSAHooks/./src/hooks/useResizeObserver.tsx","webpack://SSAHooks/./src/hooks/mediaQueries.ts","webpack://SSAHooks/./src/hooks/index.ts","webpack://SSAHooks/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SSAHooks\"] = factory();\n\telse\n\t\troot[\"SSAHooks\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","import { useState } from 'react';\n\nexport function useApi<T extends unknown[], D>(\n fetcherFn: (...args: T) => Promise<D>,\n initialValue?: D,\n) {\n const [isLoading, setIsLoading] = useState<boolean>(false);\n const [error, setError] = useState<unknown | null>(null);\n const [data, setData] = useState<D | undefined>(initialValue);\n\n const query = async (...args: Parameters<typeof fetcherFn>) => {\n setIsLoading(true);\n setError(null);\n\n try {\n const respData = await fetcherFn(...args);\n setData(respData);\n } catch (err) {\n setError(err);\n } finally {\n setIsLoading(false);\n }\n };\n\n return {\n isLoading,\n error,\n // TODO: useApi users should use type guards instead of \"data as D\"\n data: data as D,\n query,\n };\n}\n","import { useEffect, useState } from 'react';\n\nexport const useWindowSize = () => {\n const [windowSize, setWindowSize] = useState({\n width: window.innerWidth,\n height: window.innerHeight,\n });\n\n useEffect(() => {\n function handleResize() {\n setWindowSize({ width: window.innerWidth, height: window.innerHeight });\n }\n\n window.addEventListener('resize', handleResize);\n\n handleResize();\n\n return () => window.removeEventListener('resize', handleResize);\n }, []);\n\n return windowSize;\n};\n","import { useEffect } from 'react';\n\ntype UseClickOutsideType = (\n ref: React.RefObject<HTMLElement | null>,\n fn: (e: Event) => void,\n) => void;\n\nexport const useClickOutside: UseClickOutsideType = (ref, onClickOutside) => {\n const events = ['mousedown', 'touchstart'];\n\n useEffect(() => {\n const handler = (e: Event) => {\n if (\n ref.current == null ||\n ref.current.contains(e.target as HTMLElement)\n ) {\n return;\n }\n onClickOutside(e);\n };\n\n events.forEach((eventName) =>\n document.addEventListener(eventName, handler),\n );\n\n return () =>\n events.forEach((eventName) =>\n document.removeEventListener(eventName, handler),\n );\n }, [ref, onClickOutside]);\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@ssa-ui-kit/utils\");","import { useMemo } from 'react';\nimport { generateRange } from '@ssa-ui-kit/utils';\nimport { UsePaginationRangeProps } from './types';\n\nconst usePaginationRange = ({\n pagesCount,\n selectedPage,\n}: UsePaginationRangeProps) => {\n return useMemo(\n () => generateRange(pagesCount, selectedPage),\n [pagesCount, selectedPage],\n );\n};\n\nexport { usePaginationRange };\n","import { useEffect, useRef } from 'react';\nimport { useWindowSize } from '@hooks/useWindowResize';\n\nconst FONT_SIZE_REG_EXP = /(\\d+\\.?\\d+)(\\S+)/;\n\nconst isOverflowing = (\n el: HTMLElement,\n container: HTMLElement | null,\n): boolean => el.scrollWidth > Number(container?.clientWidth);\n\nconst resize = (el: HTMLElement, step: number) => {\n const fontSize = window.getComputedStyle(el).fontSize;\n const matchResults = fontSize.match(FONT_SIZE_REG_EXP);\n\n if (matchResults) {\n const [, fsValue, fsUnit] = matchResults;\n el.style.fontSize = `${Number(fsValue) - step}${fsUnit}`;\n }\n};\n\n/**\n * The hook does N attempts to decrease the font size\n * if its text content doesn't fit its parent's width.\n * If the text still overflows, it sets the `word-break` css rule.\n * The hook doesn't enlarge the font size if the parent's\n * width becomes wider.\n * */\nexport const useTextSizeDecrease = (maxAttempts = 5, step = 1) => {\n const textContainerRef = useRef<HTMLElement>(null);\n const attemptsRef = useRef<number>(0);\n const { width } = useWindowSize();\n\n const checkAndResize = () => {\n if (textContainerRef.current == null) {\n return;\n }\n\n const node = textContainerRef.current;\n const parentNode = node.parentNode as unknown as HTMLElement;\n\n let isLarger = isOverflowing(node, parentNode);\n\n while (attemptsRef.current < maxAttempts && isLarger) {\n resize(node, step);\n isLarger = isOverflowing(node, parentNode);\n ++attemptsRef.current;\n }\n\n if (isLarger) {\n node.style.wordBreak = 'break-all';\n }\n };\n\n useEffect(() => {\n checkAndResize();\n }, [textContainerRef, width]);\n\n return textContainerRef;\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"usehooks-ts\");","import { useMediaQuery } from 'usehooks-ts';\n\nexport const useDeviceType = () => {\n const isMD = useMediaQuery('(min-width: 900px)');\n const isLG = useMediaQuery('(min-width: 1440px)');\n const isXLG = useMediaQuery('(min-width: 1920px)');\n if (isXLG) {\n return 'xlg';\n }\n if (isLG) {\n return 'lg';\n }\n if (isMD) {\n return 'md';\n }\n return 'mobile';\n};\n","import { useReducer } from 'react';\n\nexport function useToggle<T = boolean>(\n options: readonly T[] = [false, true] as T[],\n) {\n const [[option], toggle] = useReducer(\n (state: T[], action: React.SetStateAction<T>) => {\n const value = action instanceof Function ? action(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n\n return state.slice(index).concat(state.slice(0, index));\n },\n options as T[],\n );\n\n return [option, toggle as (value?: React.SetStateAction<T>) => void] as const;\n}\n","import { useState } from 'react';\n\ninterface UseUncontrolledInput<T, P extends unknown[]> {\n value?: T;\n defaultValue?: T;\n finalValue?: T;\n onChange?: (value: T, ...payload: P) => void;\n}\n\nexport function useUncontrolled<T, P extends unknown[]>({\n value,\n defaultValue,\n finalValue,\n onChange = () => {},\n}: UseUncontrolledInput<T, P>): [\n T,\n (value: T, ...payload: P) => void,\n boolean,\n] {\n const [uncontrolledValue, setUncontrolledValue] = useState(\n defaultValue !== undefined ? defaultValue : finalValue,\n );\n\n const handleUncontrolledChange = (val: T, ...payload: P) => {\n setUncontrolledValue(val);\n onChange?.(val, ...payload);\n };\n\n if (value !== undefined) {\n return [value as T, onChange, true];\n }\n\n return [uncontrolledValue as T, handleUncontrolledChange, false];\n}\n","import { createContext, useContext, createElement } from 'react';\n\nexport function createSafeContext<ContextValue>(errorMessage: string) {\n const Context = createContext<ContextValue | null>(null);\n\n const useSafeContext = () => {\n const ctx = useContext(Context);\n if (ctx === null) {\n throw new Error(errorMessage);\n }\n return ctx;\n };\n\n const Provider = ({\n children,\n value,\n }: {\n value: ContextValue;\n children: React.ReactNode;\n }) => {\n return createElement(\n Context.Provider,\n {\n value,\n },\n children,\n );\n };\n\n return [Provider, useSafeContext] as const;\n}\n","import { useEffect, useMemo, useRef, useState } from 'react';\n\ntype ObserverRect = Omit<DOMRectReadOnly, 'toJSON'>;\n\nconst defaultState: ObserverRect = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n};\n\nexport function useResizeObserver<T extends HTMLElement>(\n options?: ResizeObserverOptions,\n) {\n const frameID = useRef(0);\n const ref = useRef<T>(null);\n\n const [rect, setRect] = useState<ObserverRect>(defaultState);\n\n const observer = useMemo(\n () =>\n typeof window !== 'undefined'\n ? new ResizeObserver((entries) => {\n const entry = entries[0];\n\n if (entry) {\n cancelAnimationFrame(frameID.current);\n\n frameID.current = requestAnimationFrame(() => {\n if (ref.current) {\n setRect(entry.contentRect);\n }\n });\n }\n })\n : null,\n [],\n );\n\n useEffect(() => {\n if (ref.current) {\n observer?.observe(ref.current, options);\n }\n\n return () => {\n observer?.disconnect();\n\n if (frameID.current) {\n cancelAnimationFrame(frameID.current);\n }\n };\n }, [ref.current]);\n\n return [ref, rect] as const;\n}\n\nexport function useElementSize<T extends HTMLElement>(\n options?: ResizeObserverOptions,\n) {\n const [ref, { width, height }] = useResizeObserver<T>(options);\n return { ref, width, height };\n}\n","import { useMediaQuery } from 'usehooks-ts';\n\nexport const useXSMediaQuery = () => {\n return useMediaQuery('(max-width: 389.99px)');\n};\n\nexport const useSMMediaQuery = () => {\n return useMediaQuery('(min-width: 390px)');\n};\n\nexport const useUpToMDMediaQuery = () => {\n return useMediaQuery('(max-width: 899.99px)');\n};\n\nexport const useMinMDMediaQuery = () => {\n return useMediaQuery('(min-width: 900px)');\n};\n\nexport const useMinLGMediaQuery = () => {\n return useMediaQuery('(min-width: 1440px)');\n};\n\nexport const useMinXLGMediaQuery = () => {\n return useMediaQuery('(min-width: 1920px)');\n};\n","export { useApi } from './useApi';\nexport { useWindowSize } from './useWindowResize';\nexport { useClickOutside } from './useClickOutside';\nexport { usePaginationRange } from './pagination/usePaginationRange';\nexport { useTextSizeDecrease } from './text/useTextSizeDecrease';\nexport { useDeviceType } from './useDeviceType';\nexport { useToggle } from './useToggle';\nexport { useUncontrolled } from './useUncontrolled';\nexport { createSafeContext } from './useSafeContext';\nexport { useResizeObserver, useElementSize } from './useResizeObserver';\nexport * from './mediaQueries';\n","export * from './hooks';\n"],"names":["useState","useApi","fetcherFn","initialValue","isLoading","setIsLoading","error","setError","data","setData","query","args","respData","err","useEffect","useWindowSize","windowSize","setWindowSize","width","window","innerWidth","height","innerHeight","handleResize","addEventListener","removeEventListener","useClickOutside","ref","onClickOutside","events","handler","e","current","contains","target","forEach","eventName","document","useMemo","generateRange","usePaginationRange","pagesCount","selectedPage","useRef","FONT_SIZE_REG_EXP","isOverflowing","el","container","scrollWidth","Number","clientWidth","resize","step","fontSize","getComputedStyle","matchResults","match","fsValue","fsUnit","style","useTextSizeDecrease","maxAttempts","textContainerRef","attemptsRef","checkAndResize","node","parentNode","isLarger","wordBreak","useMediaQuery","useDeviceType","isMD","isLG","isXLG","useReducer","useToggle","options","option","toggle","state","action","value","Function","index","Math","abs","indexOf","slice","concat","useUncontrolled","defaultValue","finalValue","onChange","uncontrolledValue","setUncontrolledValue","undefined","handleUncontrolledChange","val","payload","createContext","useContext","createElement","createSafeContext","errorMessage","Context","useSafeContext","ctx","Error","Provider","children","defaultState","x","y","top","left","bottom","right","useResizeObserver","frameID","rect","setRect","observer","ResizeObserver","entries","entry","cancelAnimationFrame","requestAnimationFrame","contentRect","observe","disconnect","useElementSize","useXSMediaQuery","useSMMediaQuery","useUpToMDMediaQuery","useMinMDMediaQuery","useMinLGMediaQuery","useMinXLGMediaQuery"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/hooks",
3
- "version": "2.0.0",
3
+ "version": "2.1.0-canary-afe713f-20250306",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "usehooks-ts": "3.1.0",
26
- "@ssa-ui-kit/utils": "^2.0.0"
26
+ "@ssa-ui-kit/utils": "^2.1.0-canary-afe713f-20250306"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": "18.x"