@cronocode/react-box 1.4.7 → 1.5.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),v=require("react-dom"),d=require("../box.cjs"),s=require("react"),h=require("../utils/utils.cjs");require("../box.module.css.cjs");require("../theme.cjs");const u=2;function x(f){const{onPositionChange:l}=f,i=s.useRef(null),[e,p]=s.useState(),w=h.usePortalContainer(),b=s.useCallback((n,t)=>{const r=o=>{o.target.contains(n)&&t(n)};return document.addEventListener("scroll",r,{capture:!0}),()=>{document.removeEventListener("scroll",r,{capture:!0})}},[]),m=s.useCallback((n,t)=>{const r=o=>{t(n)};return window.addEventListener("resize",r,{capture:!0}),()=>{window.removeEventListener("resize",r,{capture:!0})}},[]),a=s.useCallback(n=>{const t=n.getBoundingClientRect(),r=Math.round((t.top+window.scrollY)*u)/u,o=Math.round((t.left+window.scrollX)*u)/u;((e==null?void 0:e.top)!==r||(e==null?void 0:e.left)!==o)&&(l==null||l({top:r,left:o}),p({top:r,left:o,width:t.width>0?t.width:void 0}))},[]);return s.useLayoutEffect(()=>{if(i.current){a(i.current);const n=b(i.current,a),t=m(i.current,a);return()=>{n(),t()}}},[]),c.jsxs(c.Fragment,{children:[c.jsx(d.default,{ref:i}),e&&v.createPortal(c.jsx(d.default,{position:"absolute",top:0,left:0,style:{transform:`translate(${e.left}px,${e.top}px)`,width:e.width},children:c.jsx(d.default,{position:"absolute",width:"fit",...f})}),w)]})}exports.default=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),v=require("react-dom"),d=require("../box.cjs"),s=require("react"),h=require("../utils/utils.cjs");require("../box.module.css.cjs");require("../theme.cjs");const u=2;function x(f){const{onPositionChange:l}=f,i=s.useRef(null),[e,p]=s.useState(),w=h.usePortalContainer(),b=s.useCallback((n,t)=>{const r=o=>{o.target.contains(n)&&t(n)};return document.addEventListener("scroll",r,{capture:!0}),()=>{document.removeEventListener("scroll",r,{capture:!0})}},[e]),m=s.useCallback((n,t)=>{const r=o=>{t(n)};return window.addEventListener("resize",r,{capture:!0}),()=>{window.removeEventListener("resize",r,{capture:!0})}},[e]),a=s.useCallback(n=>{const t=n.getBoundingClientRect(),r=Math.round((t.top+window.scrollY)*u)/u,o=Math.round((t.left+window.scrollX)*u)/u;((e==null?void 0:e.top)!==r||(e==null?void 0:e.left)!==o)&&(l==null||l({top:r,left:o}),p({top:r,left:o,width:t.width>0?t.width:void 0}))},[e]);return s.useLayoutEffect(()=>{if(i.current){a(i.current);const n=b(i.current,a),t=m(i.current,a);return()=>{n(),t()}}},[e]),c.jsxs(c.Fragment,{children:[c.jsx(d.default,{ref:i}),e&&v.createPortal(c.jsx(d.default,{position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${e.left}px,${e.top}px)`,width:e.width},children:c.jsx(d.default,{position:"absolute",width:"fit",...f})}),w)]})}exports.default=x;
@@ -1,30 +1,39 @@
1
- import { jsxs as v, Fragment as x, jsx as u } from "react/jsx-runtime";
1
+ import { jsxs as v, Fragment as x, jsx as a } from "react/jsx-runtime";
2
2
  import { createPortal as b } from "react-dom";
3
- import a from "../box.mjs";
3
+ import u from "../box.mjs";
4
4
  import { useRef as E, useState as L, useCallback as d, useLayoutEffect as g } from "react";
5
5
  import { u as z } from "../utils/utils.mjs";
6
6
  import "../box.module.css.mjs";
7
7
  import "../theme.mjs";
8
8
  const i = 2;
9
9
  function M(f) {
10
- const { onPositionChange: c } = f, s = E(null), [t, p] = L(), m = z(), w = d((o, e) => {
11
- const r = (n) => {
12
- n.target.contains(o) && e(o);
13
- };
14
- return document.addEventListener("scroll", r, { capture: !0 }), () => {
15
- document.removeEventListener("scroll", r, { capture: !0 });
16
- };
17
- }, []), h = d((o, e) => {
18
- const r = (n) => {
19
- e(o);
20
- };
21
- return window.addEventListener("resize", r, { capture: !0 }), () => {
22
- window.removeEventListener("resize", r, { capture: !0 });
23
- };
24
- }, []), l = d((o) => {
25
- const e = o.getBoundingClientRect(), r = Math.round((e.top + window.scrollY) * i) / i, n = Math.round((e.left + window.scrollX) * i) / i;
26
- ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== n) && (c == null || c({ top: r, left: n }), p({ top: r, left: n, width: e.width > 0 ? e.width : void 0 }));
27
- }, []);
10
+ const { onPositionChange: c } = f, s = E(null), [t, p] = L(), m = z(), w = d(
11
+ (o, e) => {
12
+ const r = (n) => {
13
+ n.target.contains(o) && e(o);
14
+ };
15
+ return document.addEventListener("scroll", r, { capture: !0 }), () => {
16
+ document.removeEventListener("scroll", r, { capture: !0 });
17
+ };
18
+ },
19
+ [t]
20
+ ), h = d(
21
+ (o, e) => {
22
+ const r = (n) => {
23
+ e(o);
24
+ };
25
+ return window.addEventListener("resize", r, { capture: !0 }), () => {
26
+ window.removeEventListener("resize", r, { capture: !0 });
27
+ };
28
+ },
29
+ [t]
30
+ ), l = d(
31
+ (o) => {
32
+ const e = o.getBoundingClientRect(), r = Math.round((e.top + window.scrollY) * i) / i, n = Math.round((e.left + window.scrollX) * i) / i;
33
+ ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== n) && (c == null || c({ top: r, left: n }), p({ top: r, left: n, width: e.width > 0 ? e.width : void 0 }));
34
+ },
35
+ [t]
36
+ );
28
37
  return g(() => {
29
38
  if (s.current) {
30
39
  l(s.current);
@@ -33,17 +42,18 @@ function M(f) {
33
42
  o(), e();
34
43
  };
35
44
  }
36
- }, []), /* @__PURE__ */ v(x, { children: [
37
- /* @__PURE__ */ u(a, { ref: s }),
45
+ }, [t]), /* @__PURE__ */ v(x, { children: [
46
+ /* @__PURE__ */ a(u, { ref: s }),
38
47
  t && b(
39
- /* @__PURE__ */ u(
40
- a,
48
+ /* @__PURE__ */ a(
49
+ u,
41
50
  {
42
51
  position: "absolute",
43
52
  top: 0,
44
53
  left: 0,
54
+ transition: "none",
45
55
  style: { transform: `translate(${t.left}px,${t.top}px)`, width: t.width },
46
- children: /* @__PURE__ */ u(a, { position: "absolute", width: "fit", ...f })
56
+ children: /* @__PURE__ */ a(u, { position: "absolute", width: "fit", ...f })
47
57
  }
48
58
  ),
49
59
  m
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "1.4.7",
3
+ "version": "1.5.1",
4
4
  "main": "./box.cjs",
5
5
  "module": "./box.mjs",
6
6
  "types": "./box.d.ts",