@e1011/es-kit 1.0.0 → 1.0.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.
@@ -18,4 +18,5 @@ __exportStar(require("./useApi"), exports);
18
18
  __exportStar(require("./useToggle"), exports);
19
19
  __exportStar(require("./useTranslations"), exports);
20
20
  __exportStar(require("./useOutsideClick"), exports);
21
+ __exportStar(require("./useResize"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,8CAA2B;AAC3B,oDAAiC;AACjC,oDAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,8CAA2B;AAC3B,oDAAiC;AACjC,oDAAiC;AACjC,8CAA2B"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useResize = void 0;
7
+ const react_1 = require("react");
8
+ const debounce_1 = __importDefault(require("lodash-es/debounce"));
9
+ const useResize = (debounceDelay = 250) => {
10
+ const [containerSize, setContainerSize] = (0, react_1.useState)({ width: undefined, height: undefined });
11
+ const lastResizeWidthRef = (0, react_1.useRef)({ width: 0, height: 0 });
12
+ const containerRef = (0, react_1.useRef)();
13
+ // const [unobserver, setUnobserver] = useState<Unobserver>(DefaultUnobserver)
14
+ const unobserverRef = (0, react_1.useRef)();
15
+ const debouncedResizeWrapper = (0, react_1.useMemo)(() => (0, debounce_1.default)((entries) => {
16
+ const newResizeWidth = entries[0].contentRect.width;
17
+ const newResizeHeight = entries[0].contentRect.height;
18
+ if (lastResizeWidthRef.current?.width === newResizeWidth
19
+ && lastResizeWidthRef.current?.height === newResizeHeight) {
20
+ return;
21
+ }
22
+ lastResizeWidthRef.current = { width: newResizeWidth, height: newResizeHeight };
23
+ setContainerSize({
24
+ width: containerRef?.current?.clientWidth,
25
+ height: containerRef?.current?.clientHeight,
26
+ });
27
+ }, debounceDelay), [containerRef, debounceDelay]);
28
+ (0, react_1.useEffect)(() => {
29
+ let resizeObserver;
30
+ let containerElement;
31
+ if (containerRef?.current) {
32
+ containerElement = containerRef?.current;
33
+ resizeObserver = new ResizeObserver(debouncedResizeWrapper);
34
+ resizeObserver.observe(containerElement);
35
+ setContainerSize({
36
+ width: containerRef?.current?.clientWidth,
37
+ height: containerRef?.current?.clientHeight,
38
+ });
39
+ }
40
+ const unobserver = () => {
41
+ resizeObserver?.unobserve?.(containerElement);
42
+ };
43
+ // setUnobserver(unobserver)
44
+ unobserverRef.current = unobserver;
45
+ return unobserver;
46
+ }, [debouncedResizeWrapper, containerRef]);
47
+ return [containerRef, containerSize, unobserverRef.current];
48
+ };
49
+ exports.useResize = useResize;
50
+ //# sourceMappingURL=useResize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResize.js","sourceRoot":"","sources":["../../../../../src/core/hooks/useResize.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA8E;AAC9E,kEAAyC;AAQlC,MAAM,SAAS,GAAG,CAAC,aAAa,GAAG,GAAG,EAC4C,EAAE;IACzF,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GACrC,IAAA,gBAAQ,EAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;IAEhE,MAAM,kBAAkB,GAAG,IAAA,cAAM,EAAc,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;IACvE,MAAM,YAAY,GAAqD,IAAA,cAAM,GAAkC,CAAA;IAE/G,8EAA8E;IAC9E,MAAM,aAAa,GAAG,IAAA,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;QAC1D,CAAC,CAAA;QAED,4BAA4B;QAC5B,aAAa,CAAC,OAAO,GAAG,UAAU,CAAA;QAElC,OAAO,UAAU,CAAA;IACnB,CAAC,EAAE,CAAC,sBAAsB,EAAE,YAAY,CAAC,CAAC,CAAA;IAE1C,OAAO,CAAC,YAAY,EAAE,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;AAC7D,CAAC,CAAA;AApDY,QAAA,SAAS,aAoDrB"}
@@ -2,4 +2,5 @@ export * from './useApi';
2
2
  export * from './useToggle';
3
3
  export * from './useTranslations';
4
4
  export * from './useOutsideClick';
5
+ export * from './useResize';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { MutableRefObject } from 'react';
2
+ type WrapperSize = {
3
+ width: undefined | number;
4
+ height: undefined | number;
5
+ };
6
+ type Unobserver = () => (null | void);
7
+ export declare const useResize: (debounceDelay?: number) => [
8
+ MutableRefObject<HTMLElement | null | undefined>,
9
+ WrapperSize,
10
+ Unobserver | undefined
11
+ ];
12
+ export {};
13
+ //# sourceMappingURL=useResize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResize.d.ts","sourceRoot":"","sources":["../../../../../src/core/hooks/useResize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAwC,MAAM,OAAO,CAAA;AAG9E,KAAK,WAAW,GAAG;IAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAA;CAAC,CAAA;AAI1E,KAAK,UAAU,GAAG,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;AAErC,eAAO,MAAM,SAAS,8BAA0B;IAC9C,iBAAiB,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAAE,WAAW;IAAE,UAAU,GAAG,SAAS;CAmDtF,CAAA"}
@@ -45,7 +45,7 @@ export declare const FlexWrapper: import("react").MemoExoticComponent<import("st
45
45
  gap?: string | undefined;
46
46
  css?: string | undefined;
47
47
  borderRadius?: string | undefined;
48
- }, "direction" | "flex" | "flexGrow" | "alignText" | "flexShrink" | "flexBasis" | "flexWrap" | "justify" | "align" | "alignSelf" | "margin" | "padding" | "width" | "height" | "maxWidth" | "maxHeight" | "minWidth" | "minHeight" | "gap" | "css" | "borderRadius">>;
48
+ }, "width" | "height" | "direction" | "flex" | "flexGrow" | "alignText" | "flexShrink" | "flexBasis" | "flexWrap" | "justify" | "align" | "alignSelf" | "margin" | "padding" | "maxWidth" | "maxHeight" | "minWidth" | "minHeight" | "gap" | "css" | "borderRadius">>;
49
49
  export declare const FlexTight: import("react").MemoExoticComponent<import("styled-components").StyledComponent<import("react").MemoExoticComponent<import("styled-components").StyledComponent<"div", any, FlexProps, never>>, any, {
50
50
  flex?: string | undefined;
51
51
  flexGrow?: string | number | undefined;
@@ -69,5 +69,5 @@ export declare const FlexTight: import("react").MemoExoticComponent<import("styl
69
69
  css?: string | undefined;
70
70
  borderRadius?: string | undefined;
71
71
  size: string;
72
- }, "direction" | "flex" | "flexGrow" | "alignText" | "flexShrink" | "flexBasis" | "flexWrap" | "justify" | "align" | "alignSelf" | "margin" | "padding" | "width" | "height" | "maxWidth" | "maxHeight" | "minWidth" | "minHeight" | "gap" | "css" | "borderRadius" | "size">>;
72
+ }, "width" | "height" | "direction" | "flex" | "flexGrow" | "alignText" | "flexShrink" | "flexBasis" | "flexWrap" | "justify" | "align" | "alignSelf" | "margin" | "padding" | "maxWidth" | "maxHeight" | "minWidth" | "minHeight" | "gap" | "css" | "borderRadius" | "size">>;
73
73
  //# sourceMappingURL=Flex.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e1011/es-kit",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "dist/lib/cjs/src/index.js",
5
5
  "module": "dist/lib/esm/src/index.js",
6
6
  "sideEffects": false,