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