@adara-cs/hooks 1.1.1 → 1.1.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Adara Cloud
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) 2024 Adara Cloud
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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # @adara-cs/hooks
2
-
3
- Hooks for Adara UI Kit Web
1
+ # @adara-cs/hooks
2
+
3
+ Hooks for Adara UI Kit Web
@@ -1 +1 @@
1
- {"version":3,"file":"useControlledState.js","sources":["../src/useControlledState.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\r\nimport { useLatest } from './useLatest';\r\n\r\nexport type UseControlled = <T>(\r\n value: T | undefined,\r\n defaultValue: T,\r\n onChange?: ((v: T, ...args: never[]) => void) | undefined\r\n) => [T, (value: T) => void]\r\n\r\nexport const useControlledState: UseControlled = <T>(\r\n value: T | undefined,\r\n defaultValue: T,\r\n onChange?: (v: T, ...args: never[]) => void,\r\n): [T, (value: T) => void] => {\r\n const [stateValue, setStateValue] = useState(\r\n value !== undefined ? value : defaultValue,\r\n )\r\n const isControlled = value !== undefined\r\n\r\n const onChangeRef = useLatest(onChange)\r\n const setValue = useCallback(\r\n (newValue: T) => {\r\n if (!isControlled) {\r\n setStateValue(newValue)\r\n }\r\n onChangeRef.current?.(newValue)\r\n },\r\n [isControlled, onChangeRef],\r\n )\r\n\r\n return [isControlled ? value : stateValue, setValue]\r\n}\r\n"],"names":["useControlledState","value","defaultValue","onChange","stateValue","setStateValue","useState","isControlled","onChangeRef","useLatest","setValue","useCallback","newValue","_a"],"mappings":";;AASO,MAAMA,IAAoC,CAC/CC,GACAC,GACAC,MAC4B;AACtB,QAAA,CAACC,GAAYC,CAAa,IAAIC;AAAA,IAClCL,MAAU,SAAYA,IAAQC;AAAA,EAChC,GACMK,IAAeN,MAAU,QAEzBO,IAAcC,EAAUN,CAAQ,GAChCO,IAAWC;AAAA,IACf,CAACC,MAAgB;;AACf,MAAKL,KACHF,EAAcO,CAAQ,IAExBC,IAAAL,EAAY,YAAZ,QAAAK,EAAA,KAAAL,GAAsBI;AAAA,IACxB;AAAA,IACA,CAACL,GAAcC,CAAW;AAAA,EAC5B;AAEA,SAAO,CAACD,IAAeN,IAAQG,GAAYM,CAAQ;AACrD;"}
1
+ {"version":3,"file":"useControlledState.js","sources":["../src/useControlledState.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useLatest } from './useLatest';\n\nexport type UseControlled = <T>(\n value: T | undefined,\n defaultValue: T,\n onChange?: ((v: T, ...args: never[]) => void) | undefined\n) => [T, (value: T) => void]\n\nexport const useControlledState: UseControlled = <T>(\n value: T | undefined,\n defaultValue: T,\n onChange?: (v: T, ...args: never[]) => void,\n): [T, (value: T) => void] => {\n const [stateValue, setStateValue] = useState(\n value !== undefined ? value : defaultValue,\n )\n const isControlled = value !== undefined\n\n const onChangeRef = useLatest(onChange)\n const setValue = useCallback(\n (newValue: T) => {\n if (!isControlled) {\n setStateValue(newValue)\n }\n onChangeRef.current?.(newValue)\n },\n [isControlled, onChangeRef],\n )\n\n return [isControlled ? value : stateValue, setValue]\n}\n"],"names":["useControlledState","value","defaultValue","onChange","stateValue","setStateValue","useState","isControlled","onChangeRef","useLatest","setValue","useCallback","newValue","_a"],"mappings":";;AASO,MAAMA,IAAoC,CAC/CC,GACAC,GACAC,MAC4B;AACtB,QAAA,CAACC,GAAYC,CAAa,IAAIC;AAAA,IAClCL,MAAU,SAAYA,IAAQC;AAAA,EAChC,GACMK,IAAeN,MAAU,QAEzBO,IAAcC,EAAUN,CAAQ,GAChCO,IAAWC;AAAA,IACf,CAACC,MAAgB;;AACf,MAAKL,KACHF,EAAcO,CAAQ,IAExBC,IAAAL,EAAY,YAAZ,QAAAK,EAAA,KAAAL,GAAsBI;AAAA,IACxB;AAAA,IACA,CAACL,GAAcC,CAAW;AAAA,EAC5B;AAEA,SAAO,CAACD,IAAeN,IAAQG,GAAYM,CAAQ;AACrD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIsomophicLayoutEffect.js","sources":["../src/useIsomophicLayoutEffect.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from 'react';\r\n\r\nexport const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useLayoutEffect : useEffect"],"names":["useIsomorphicLayoutEffect","useLayoutEffect","useEffect"],"mappings":";AAEO,MAAMA,IAA4B,OAAO,SAAW,MAAcC,IAAkBC;"}
1
+ {"version":3,"file":"useIsomophicLayoutEffect.js","sources":["../src/useIsomophicLayoutEffect.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from 'react';\n\nexport const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useLayoutEffect : useEffect"],"names":["useIsomorphicLayoutEffect","useLayoutEffect","useEffect"],"mappings":";AAEO,MAAMA,IAA4B,OAAO,SAAW,MAAcC,IAAkBC;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLatest.js","sources":["../src/useLatest.ts"],"sourcesContent":["import type { MutableRefObject } from 'react'\r\nimport { useRef } from 'react'\r\nimport { useIsomorphicLayoutEffect } from './useIsomophicLayoutEffect.ts'\r\n\r\nexport const useLatest = <T>(value: T): MutableRefObject<T> => {\r\n const ref = useRef(value)\r\n\r\n useIsomorphicLayoutEffect(() => {\r\n ref.current = value\r\n }, [value])\r\n\r\n return ref\r\n}"],"names":["useLatest","value","ref","useRef","useIsomorphicLayoutEffect"],"mappings":";;AAIa,MAAAA,IAAY,CAAIC,MAAkC;AACvD,QAAAC,IAAMC,EAAOF,CAAK;AAExB,SAAAG,EAA0B,MAAM;AAC9B,IAAAF,EAAI,UAAUD;AAAA,EAAA,GACb,CAACA,CAAK,CAAC,GAEHC;AACT;"}
1
+ {"version":3,"file":"useLatest.js","sources":["../src/useLatest.ts"],"sourcesContent":["import type { MutableRefObject } from 'react'\nimport { useRef } from 'react'\nimport { useIsomorphicLayoutEffect } from './useIsomophicLayoutEffect.ts'\n\nexport const useLatest = <T>(value: T): MutableRefObject<T> => {\n const ref = useRef(value)\n\n useIsomorphicLayoutEffect(() => {\n ref.current = value\n }, [value])\n\n return ref\n}"],"names":["useLatest","value","ref","useRef","useIsomorphicLayoutEffect"],"mappings":";;AAIa,MAAAA,IAAY,CAAIC,MAAkC;AACvD,QAAAC,IAAMC,EAAOF,CAAK;AAExB,SAAAG,EAA0B,MAAM;AAC9B,IAAAF,EAAI,UAAUD;AAAA,EAAA,GACb,CAACA,CAAK,CAAC,GAEHC;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useResize.js","sources":["../src/useResize.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\r\n\r\nexport const useResize = () => {\r\n const [height, setHeight] = useState<number>(typeof window !== 'undefined' ? window.innerHeight : 0);\r\n const [width, setWidth] = useState<number>(typeof window !== 'undefined' ? window.innerWidth : 0)\r\n\r\n useEffect(() => {\r\n const controller = new AbortController()\r\n\r\n const onChange = () => {\r\n setWidth(window.innerWidth)\r\n setHeight(window.innerHeight)\r\n }\r\n\r\n if (height === 0 || width === 0) onChange()\r\n\r\n window.addEventListener('resize', onChange, { signal: controller.signal })\r\n\r\n return () => {\r\n controller.abort()\r\n }\r\n }, [])\r\n\r\n return { height, width }\r\n}"],"names":["useResize","height","setHeight","useState","width","setWidth","useEffect","controller","onChange"],"mappings":";AAEO,MAAMA,IAAY,MAAM;AACvB,QAAA,CAACC,GAAQC,CAAS,IAAIC,EAAiB,OAAO,SAAW,MAAc,OAAO,cAAc,CAAC,GAC7F,CAACC,GAAOC,CAAQ,IAAIF,EAAiB,OAAO,SAAW,MAAc,OAAO,aAAa,CAAC;AAEhG,SAAAG,EAAU,MAAM;AACR,UAAAC,IAAa,IAAI,gBAAgB,GAEjCC,IAAW,MAAM;AACrB,MAAAH,EAAS,OAAO,UAAU,GAC1BH,EAAU,OAAO,WAAW;AAAA,IAC9B;AAEA,YAAID,MAAW,KAAKG,MAAU,MAAYI,EAAA,GAE1C,OAAO,iBAAiB,UAAUA,GAAU,EAAE,QAAQD,EAAW,QAAQ,GAElE,MAAM;AACX,MAAAA,EAAW,MAAM;AAAA,IACnB;AAAA,EACF,GAAG,EAAE,GAEE,EAAE,QAAAN,GAAQ,OAAAG,EAAM;AACzB;"}
1
+ {"version":3,"file":"useResize.js","sources":["../src/useResize.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport const useResize = () => {\n const [height, setHeight] = useState<number>(typeof window !== 'undefined' ? window.innerHeight : 0);\n const [width, setWidth] = useState<number>(typeof window !== 'undefined' ? window.innerWidth : 0)\n\n useEffect(() => {\n const controller = new AbortController()\n\n const onChange = () => {\n setWidth(window.innerWidth)\n setHeight(window.innerHeight)\n }\n\n if (height === 0 || width === 0) onChange()\n\n window.addEventListener('resize', onChange, { signal: controller.signal })\n\n return () => {\n controller.abort()\n }\n }, [])\n\n return { height, width }\n}"],"names":["useResize","height","setHeight","useState","width","setWidth","useEffect","controller","onChange"],"mappings":";AAEO,MAAMA,IAAY,MAAM;AACvB,QAAA,CAACC,GAAQC,CAAS,IAAIC,EAAiB,OAAO,SAAW,MAAc,OAAO,cAAc,CAAC,GAC7F,CAACC,GAAOC,CAAQ,IAAIF,EAAiB,OAAO,SAAW,MAAc,OAAO,aAAa,CAAC;AAEhG,SAAAG,EAAU,MAAM;AACR,UAAAC,IAAa,IAAI,gBAAgB,GAEjCC,IAAW,MAAM;AACrB,MAAAH,EAAS,OAAO,UAAU,GAC1BH,EAAU,OAAO,WAAW;AAAA,IAC9B;AAEA,YAAID,MAAW,KAAKG,MAAU,MAAYI,EAAA,GAE1C,OAAO,iBAAiB,UAAUA,GAAU,EAAE,QAAQD,EAAW,QAAQ,GAElE,MAAM;AACX,MAAAA,EAAW,MAAM;AAAA,IACnB;AAAA,EACF,GAAG,EAAE,GAEE,EAAE,QAAAN,GAAQ,OAAAG,EAAM;AACzB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adara-cs/hooks",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "AdaraCloud UI Kit for Web",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -16,14 +16,14 @@
16
16
  },
17
17
  "homepage": "https://github.com/adara-cs/ui-kit-web#readme",
18
18
  "type": "module",
19
- "main": "./src/index.ts",
20
- "types": "./src/index.d.ts",
19
+ "main": "./index.ts",
20
+ "types": "./index.d.ts",
21
21
  "exports": {
22
22
  ".": {
23
23
  "source": "./src/index.ts",
24
24
  "import": {
25
- "types": "./dist/index.d.ts",
26
- "default": "./dist/index.js"
25
+ "types": "./index.d.ts",
26
+ "default": "./index.js"
27
27
  }
28
28
  }
29
29
  },
@@ -38,15 +38,14 @@
38
38
  "react": "^18.3.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@testing-library/react": "^16.1.0",
42
41
  "@types/react": "^18.3.12",
43
42
  "@types/react-dom": "^18.3.1",
44
- "fast-glob": "^3.3.3",
45
43
  "rollup-preserve-directives": "^1.1.3",
46
44
  "vite": "^6.0.1",
47
45
  "vite-plugin-dts": "^4.3.0",
48
46
  "vite-plugin-svgr": "^4.3.0",
49
- "@vitejs/plugin-react": "^4.3.4"
47
+ "@vitejs/plugin-react": "^4.3.4",
48
+ "vitest": "^2.1.8"
50
49
  },
51
50
  "config": {
52
51
  "commitizen": {
@@ -62,6 +61,7 @@
62
61
  "access": "public"
63
62
  },
64
63
  "scripts": {
64
+ "dev": "vite build --watch",
65
65
  "build": "vite build",
66
66
  "check-types": "tsc --noEmit"
67
67
  }
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './useResize'
2
- export * from './useIsomophicLayoutEffect'
3
- export * from './useLatest'
4
- export * from './useControlledState'