Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

selection-popover

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selection-popover - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

dist/index.js

@@ -1,1 +0,1 @@

var we=Object.create;var T=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var xe=(e,n)=>{for(var t in n)T(e,t,{get:n[t],enumerable:!0})},K=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Ce(n))!ve.call(e,r)&&r!==t&&T(e,r,{get:()=>n[r],enumerable:!(i=Re(n,r))||i.enumerable});return e};var Q=(e,n,t)=>(t=e!=null?we(ye(e)):{},K(n||!e||!e.__esModule?T(t,"default",{value:e,enumerable:!0}):t,e)),Ae=e=>K(T({},"__esModule",{value:!0}),e);var $e={};xe($e,{Arrow:()=>ce,Content:()=>le,Portal:()=>ie,Root:()=>be,Trigger:()=>re});module.exports=Ae($e);var o=Q(require("react")),b=require("@radix-ui/react-context"),H=require("@radix-ui/react-compose-refs"),L=require("@radix-ui/react-presence"),Z=require("@radix-ui/react-use-controllable-state"),E=require("@radix-ui/react-primitive"),ee=require("@radix-ui/react-use-size"),te=require("@radix-ui/react-portal"),ne=require("@radix-ui/react-use-layout-effect"),oe=Q(require("@radix-ui/react-arrow")),c=require("@floating-ui/react");var[Te,R]=(0,b.createContext)("Selection"),be=e=>{let{children:n,open:t,defaultOpen:i,onOpenChange:r,whileSelect:m=!1,disabled:s=!1}=e,[f,l]=o.useState({getBoundingClientRect:()=>DOMRect.fromRect()}),[a=!1,d]=(0,Z.useControllableState)({prop:t,defaultProp:i,onChange:r});return o.createElement(Te,{open:a,onOpenChange:d,whileSelect:m,virtualRef:f,onVirtualRefChange:l,disabled:s},n)},O="SelectionTrigger",re=o.forwardRef((e,n)=>R(O).whileSelect?o.createElement(Ee,{...e,ref:n}):o.createElement(Oe,{...e,ref:n}));re.displayName=O;var Ee=o.forwardRef((e,n)=>{let t=R(O),i=o.useRef(null),r=o.useRef(""),m=(0,H.useComposedRefs)(n,i),{onOpenChange:s,onVirtualRefChange:f}=t;return o.useEffect(()=>{if(!t.disabled){let l=()=>{if(r.current!=="mouse")return;let a=document.getSelection();if(!a)return;if(a.isCollapsed)return s(!1);let d=i.current;if(!(d==null?void 0:d.contains(a.anchorNode)))return;if(a.toString().trim()!==""){let p=a.getRangeAt(0);s(!0),f({getBoundingClientRect:()=>p.getBoundingClientRect()})}};return document.addEventListener("selectionchange",l),()=>document.removeEventListener("selectionchange",l)}},[t.disabled,s,f]),o.createElement(E.Primitive.div,{...e,ref:m,onPointerDown:l=>{r.current=l.pointerType}})}),Oe=o.forwardRef((e,n)=>{let t=R(O),i=o.useRef(null),{onOpenChange:r,onVirtualRefChange:m}=t,s=(0,H.useComposedRefs)(n,i);return o.useEffect(()=>{if(!t.disabled){let f=i.current;if(!f)return;let l=a=>{a.pointerType==="mouse"&&setTimeout(()=>{let d=document.getSelection();if(!d)return;if(d.isCollapsed)return r(!1);let u=i.current;if(!(u==null?void 0:u.contains(d.anchorNode)))return;let p=d==null?void 0:d.getRangeAt(0);p&&(r(!0),m({getBoundingClientRect:()=>p.getBoundingClientRect()}))})};return f.addEventListener("pointerup",l),()=>f.removeEventListener("pointerup",l)}},[r,m,t.disabled]),o.createElement(E.Primitive.div,{...e,ref:s})}),V="SelectionPortal",[Ne,Ie]=(0,b.createContext)(V,{forceMount:void 0}),ie=e=>{let{forceMount:n,container:t,children:i}=e,r=R(V);return o.createElement(Ne,{forceMount:n},o.createElement(L.Presence,{present:n||r.open},o.createElement(te.Portal,{asChild:!0,container:t},i)))};ie.displayName=V;var y="SelectionContent",le=o.forwardRef((e,n)=>{let t=Ie(y),{forceMount:i=t.forceMount,...r}=e,m=R(y);return o.createElement(L.Presence,{present:i||m.open},o.createElement(De,{...r,ref:n}))}),[Me,We]=(0,b.createContext)(y),De=o.forwardRef((e,n)=>{var Y,X,G,k,F,U,j,z,q;let{side:t="top",sideOffset:i=0,align:r="center",alignOffset:m=0,arrowPadding:s=0,sticky:f="partial",collisionBoundary:l=[],collisionPadding:a=0,hideWhenDetached:d=!1,avoidCollisions:u=!0,...P}=e,p=R(y),{onOpenChange:h}=p,[g,v]=o.useState(null),S=(0,ee.useSize)(g),x=(Y=S==null?void 0:S.width)!=null?Y:0,C=(X=S==null?void 0:S.height)!=null?X:0,A=t+(r!=="center"?"-"+r:""),de=typeof a=="number"?a:{top:0,right:0,bottom:0,left:0,...a},B=Array.isArray(l)?l:[l],pe=B.length>0,N={padding:de,boundary:B.filter(Le),altBoundary:pe},{x:I,y:M,strategy:fe,placement:ue,refs:W,middlewareData:w,isPositioned:$}=(0,c.useFloating)({strategy:"fixed",placement:A,whileElementsMounted:c.autoUpdate,middleware:[Ve(),(0,c.offset)({mainAxis:i+C,alignmentAxis:m}),u?(0,c.shift)({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?(0,c.limitShift)():void 0,...N}):void 0,g?(0,c.arrow)({element:g,padding:s}):void 0,u?(0,c.flip)(N):void 0,(0,c.size)(N),Be({arrowWidth:x,arrowHeight:C}),d?(0,c.hide)({strategy:"referenceHidden"}):void 0]});(0,ne.useLayoutEffect)(()=>{W.setReference(p.virtualRef)},[p.virtualRef,W]),o.useEffect(()=>{if(!p.disabled){let J=he=>{he.pointerType==="mouse"&&setTimeout(()=>{let D=document.getSelection();D!=null&&D.isCollapsed&&h(!1)})};return document.addEventListener("pointerdown",J),()=>document.removeEventListener("pointerdown",J)}},[p.disabled,h]);let[_,me]=se(ue),ge=(G=w.arrow)==null?void 0:G.x,Se=(k=w.arrow)==null?void 0:k.y,Pe=((F=w.arrow)==null?void 0:F.centerOffset)!==0;return o.createElement("div",{ref:W.setFloating,style:{position:fe,top:0,left:0,transform:$?`translate3d(${Math.round(I!=null?I:0)}px, ${Math.round(M!=null?M:0)}px, 0)`:"translate3d(0, -200%, 0)",minWidth:"max-content",zIndex:(U=P.style)==null?void 0:U.zIndex}},o.createElement(Me,{placedSide:_,onArrowChange:v,arrowX:ge,arrowY:Se,shouldHideArrow:Pe},o.createElement(E.Primitive.div,{"data-side":_,"data-align":me,"data-state":p.open?"open":"closed",...P,ref:n,style:{userSelect:"none",...P.style,animation:$?void 0:"none",opacity:(j=w.hide)!=null&&j.referenceHidden?0:void 0,["--selection-popover-content-transform-origin"]:[(z=w.transformOrigin)==null?void 0:z.x,(q=w.transformOrigin)==null?void 0:q.y].join(" ")}})))});le.displayName=y;var ae="SelectionArrow",He={top:"bottom",right:"left",bottom:"top",left:"right"},ce=o.forwardRef((e,n)=>{let t=We(ae),i=He[t.placedSide];return o.createElement("span",{ref:t.onArrowChange,style:{position:"absolute",left:t.arrowX,top:t.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[t.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[t.placedSide],visibility:t.shouldHideArrow?"hidden":void 0}},o.createElement(oe.Root,{...e,ref:n,style:{...e.style,display:"block"}}))});ce.displayName=ae;function Le(e){return e!==null}function se(e){let[n,t="center"]=e.split("-");return[n,t]}var Ve=()=>({name:"anchorCssProperties",fn(e){let{rects:n,elements:t}=e,{width:i,height:r}=n.reference;return t.floating.style.setProperty("--selection-popover-select-width",`${i}px`),t.floating.style.setProperty("--selection-popover-select-height",`${r}px`),{}}}),Be=e=>({name:"transformOrigin",options:e,fn(n){var v,S,x,C,A;let{placement:t,rects:i,middlewareData:r}=n,s=((v=r.arrow)==null?void 0:v.centerOffset)!==0,f=s?0:e.arrowWidth,l=s?0:e.arrowHeight,[a,d]=se(t),u={start:"0%",center:"50%",end:"100%"}[d],P=((x=(S=r.arrow)==null?void 0:S.x)!=null?x:0)+f/2,p=((A=(C=r.arrow)==null?void 0:C.y)!=null?A:0)+l/2,h="",g="";return a==="bottom"?(h=s?u:`${P}px`,g=`${-l}px`):a==="top"?(h=s?u:`${P}px`,g=`${i.floating.height+l}px`):a==="right"?(h=`${-l}px`,g=s?u:`${p}px`):a==="left"&&(h=`${i.floating.width+l}px`,g=s?u:`${p}px`),{data:{x:h,y:g}}}});0&&(module.exports={Arrow,Content,Portal,Root,Trigger});
var ye=Object.create;var O=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var Ee=(e,o)=>{for(var t in o)O(e,t,{get:o[t],enumerable:!0})},ee=(e,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of ve(o))!xe.call(e,r)&&r!==t&&O(e,r,{get:()=>o[r],enumerable:!(i=Ce(o,r))||i.enumerable});return e};var te=(e,o,t)=>(t=e!=null?ye(Te(e)):{},ee(o||!e||!e.__esModule?O(t,"default",{value:e,enumerable:!0}):t,e)),be=e=>ee(O({},"__esModule",{value:!0}),e);var Ye={};Ee(Ye,{Arrow:()=>fe,Content:()=>ce,Portal:()=>se,Root:()=>Oe,Trigger:()=>ae});module.exports=be(Ye);var n=te(require("react")),M=require("@radix-ui/react-context"),N=require("@radix-ui/react-compose-refs"),_=require("@radix-ui/react-presence"),ne=require("@radix-ui/react-use-controllable-state"),I=require("@radix-ui/react-primitive"),oe=require("@radix-ui/react-use-size"),re=require("@radix-ui/react-portal"),ie=require("@radix-ui/react-use-layout-effect"),le=te(require("@radix-ui/react-arrow")),c=require("@floating-ui/react-dom");var[Ae,v]=(0,M.createContext)("Selection"),Oe=e=>{let{children:o,open:t,defaultOpen:i,onOpenChange:r,whileSelect:g=!1,disabled:d=!1}=e,[u,a]=n.useState({getBoundingClientRect:()=>DOMRect.fromRect()}),[l,f]=n.useState(null),[p=!1,m]=(0,ne.useControllableState)({prop:t,defaultProp:i,onChange:r});return n.createElement(Ae,{open:p,onOpenChange:m,whileSelect:g,virtualRef:u,onVirtualRefChange:a,trigger:l,onTriggerChange:f,disabled:d},o)},W="SelectionTrigger",ae=n.forwardRef((e,o)=>{let t=v(W),i=(0,N.useComposedRefs)(o,r=>t.onTriggerChange(r));return t.whileSelect?n.createElement(Me,{...e,ref:i}):n.createElement(Ne,{...e,ref:i})});ae.displayName=W;var Me=n.forwardRef((e,o)=>{let t=v(W),i=n.useRef(null),r=n.useRef(""),g=(0,N.useComposedRefs)(o,i),{onOpenChange:d,onVirtualRefChange:u}=t;return n.useEffect(()=>{if(!t.disabled){let a=()=>{if(r.current!=="mouse")return;let l=document.getSelection();if(!l)return;if(l.isCollapsed)return d(!1);let f=i.current;if(!(f==null?void 0:f.contains(l.anchorNode)))return;if(l.toString().trim()!==""){let s=l.getRangeAt(0);d(!0),u({getBoundingClientRect:()=>s.getBoundingClientRect()})}};return document.addEventListener("selectionchange",a),()=>document.removeEventListener("selectionchange",a)}},[t.disabled,d,u]),n.createElement(I.Primitive.div,{...e,ref:g,onPointerDown:a=>{var l;(l=e.onPointerDown)==null||l.call(e,a),r.current=a.pointerType}})}),Ne=n.forwardRef((e,o)=>{let t=v(W),i=n.useRef(null),{onOpenChange:r,onVirtualRefChange:g}=t,d=(0,N.useComposedRefs)(o,i);return n.useEffect(()=>{if(!t.disabled){let u=i.current;if(!u)return;let a=l=>{l.pointerType==="mouse"&&setTimeout(()=>{let f=document.getSelection();if(!f)return;if(f.isCollapsed)return r(!1);let p=i.current;if(!(p==null?void 0:p.contains(f.anchorNode)))return;let s=f==null?void 0:f.getRangeAt(0);s&&(r(!0),g({getBoundingClientRect:()=>s.getBoundingClientRect()}))})};return u.addEventListener("pointerup",a),()=>u.removeEventListener("pointerup",a)}},[r,g,t.disabled]),n.createElement(I.Primitive.div,{...e,ref:d})}),Y="SelectionPortal",[Ie,We]=(0,M.createContext)(Y,{forceMount:void 0}),se=e=>{let{forceMount:o,container:t,children:i}=e,r=v(Y);return n.createElement(Ie,{forceMount:o},n.createElement(_.Presence,{present:o||r.open},n.createElement(re.Portal,{asChild:!0,container:t},i)))};se.displayName=Y;var x="SelectionContent",ce=n.forwardRef((e,o)=>{let t=We(x),{forceMount:i=t.forceMount,...r}=e,g=v(x);return n.createElement(_.Presence,{present:i||g.open},n.createElement(He,{...r,ref:o}))}),[De,Le]=(0,M.createContext)(x),V,$,He=n.forwardRef((e,o)=>{var k,F,j,z,q,J,K,Q,Z;let{side:t="top",sideOffset:i=0,align:r="center",alignOffset:g=0,arrowPadding:d=0,sticky:u="partial",collisionBoundary:a=[],collisionPadding:l=0,hideWhenDetached:f=!1,avoidCollisions:p=!0,...m}=e,s=v(x),{onOpenChange:h}=s,[S,E]=n.useState(null),P=(0,oe.useSize)(S),b=(k=P==null?void 0:P.width)!=null?k:0,T=(F=P==null?void 0:P.height)!=null?F:0,A=t+(r!=="center"?"-"+r:""),ue=typeof l=="number"?l:{top:0,right:0,bottom:0,left:0,...l},X=Array.isArray(a)?a:[a],ge=X.length>0,D={padding:ue,boundary:X.filter(Ve),altBoundary:ge},{x:L,y:H,strategy:me,placement:Se,refs:B,middlewareData:R,isPositioned:U}=(0,c.useFloating)({strategy:"fixed",placement:A,whileElementsMounted:c.autoUpdate,middleware:[$e(),(0,c.offset)({mainAxis:i+T,alignmentAxis:g}),p?(0,c.shift)({mainAxis:!0,crossAxis:!1,limiter:u==="partial"?(0,c.limitShift)():void 0,...D}):void 0,S?(0,c.arrow)({element:S,padding:d}):void 0,p?(0,c.flip)(D):void 0,(0,c.size)(D),_e({arrowWidth:b,arrowHeight:T}),f?(0,c.hide)({strategy:"referenceHidden"}):void 0]});(0,ie.useLayoutEffect)(()=>{B.setReference(s.virtualRef)},[s.virtualRef,B]),n.useEffect(()=>{if(!s.disabled){let w=y=>{y.pointerType==="mouse"&&setTimeout(()=>{let C=document.getSelection();C!=null&&C.isCollapsed&&h(!1)})};return document.addEventListener("pointerdown",w),()=>document.removeEventListener("pointerdown",w)}},[s.disabled,h]),n.useEffect(()=>{if(s.whileSelect&&s.trigger){let w=document.body,y=s.trigger;V=w.style.userSelect,$=y.style.userSelect,w.style.userSelect="none",y.style.userSelect="text";let C=()=>{w.style.userSelect=V,y.style.userSelect=$};return document.addEventListener("pointerup",C),()=>{w.style.userSelect=V,y.style.userSelect=$,document.removeEventListener("pointerup",C)}}},[s.whileSelect,s.trigger]);let[G,Pe]=pe(Se),he=(j=R.arrow)==null?void 0:j.x,we=(z=R.arrow)==null?void 0:z.y,Re=((q=R.arrow)==null?void 0:q.centerOffset)!==0;return n.createElement("div",{ref:B.setFloating,style:{position:me,top:0,left:0,transform:U?`translate3d(${Math.round(L!=null?L:0)}px, ${Math.round(H!=null?H:0)}px, 0)`:"translate3d(0, -200%, 0)",minWidth:"max-content",zIndex:(J=m.style)==null?void 0:J.zIndex}},n.createElement(De,{placedSide:G,onArrowChange:E,arrowX:he,arrowY:we,shouldHideArrow:Re},n.createElement(I.Primitive.div,{"data-side":G,"data-align":Pe,"data-state":s.open?"open":"closed",...m,ref:o,style:{userSelect:"none",...m.style,animation:U?void 0:"none",opacity:(K=R.hide)!=null&&K.referenceHidden?0:void 0,["--selection-popover-content-transform-origin"]:[(Q=R.transformOrigin)==null?void 0:Q.x,(Z=R.transformOrigin)==null?void 0:Z.y].join(" ")}})))});ce.displayName=x;var de="SelectionArrow",Be={top:"bottom",right:"left",bottom:"top",left:"right"},fe=n.forwardRef((e,o)=>{let t=Le(de),i=Be[t.placedSide];return n.createElement("span",{ref:t.onArrowChange,style:{position:"absolute",left:t.arrowX,top:t.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[t.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[t.placedSide],visibility:t.shouldHideArrow?"hidden":void 0}},n.createElement(le.Root,{...e,ref:o,style:{...e.style,display:"block"}}))});fe.displayName=de;function Ve(e){return e!==null}function pe(e){let[o,t="center"]=e.split("-");return[o,t]}var $e=()=>({name:"anchorCssProperties",fn(e){let{rects:o,elements:t}=e,{width:i,height:r}=o.reference;return t.floating.style.setProperty("--selection-popover-select-width",`${i}px`),t.floating.style.setProperty("--selection-popover-select-height",`${r}px`),{}}}),_e=e=>({name:"transformOrigin",options:e,fn(o){var E,P,b,T,A;let{placement:t,rects:i,middlewareData:r}=o,d=((E=r.arrow)==null?void 0:E.centerOffset)!==0,u=d?0:e.arrowWidth,a=d?0:e.arrowHeight,[l,f]=pe(t),p={start:"0%",center:"50%",end:"100%"}[f],m=((b=(P=r.arrow)==null?void 0:P.x)!=null?b:0)+u/2,s=((A=(T=r.arrow)==null?void 0:T.y)!=null?A:0)+a/2,h="",S="";return l==="bottom"?(h=d?p:`${m}px`,S=`${-a}px`):l==="top"?(h=d?p:`${m}px`,S=`${i.floating.height+a}px`):l==="right"?(h=`${-a}px`,S=d?p:`${s}px`):l==="left"&&(h=`${i.floating.width+a}px`,S=d?p:`${s}px`),{data:{x:h,y:S}}}});0&&(module.exports={Arrow,Content,Portal,Root,Trigger});
{
"name": "selection-popover",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",

@@ -17,2 +17,8 @@ "main": "./dist/index.js",

},
"keywords": [
"react",
"selection",
"popover"
],
"author": "João Pedro Magalhães <joaopsilvamagalhaes@gmail.com>",
"peerDependencies": {

@@ -23,3 +29,3 @@ "react": "^16.8 || ^17.0 || ^18.0",

"dependencies": {
"@floating-ui/react": "0.19.2",
"@floating-ui/react-dom": "^1.3.0",
"@radix-ui/react-arrow": "1.0.1",

@@ -37,3 +43,11 @@ "@radix-ui/react-compose-refs": "1.0.0",

"@types/react": "18.0.28"
},
"homepage": "https://selection-popover.vercel.app",
"repository": {
"type": "git",
"url": "git+https://github.com/joaom00/selection-popover.git"
},
"bugs": {
"url": "https://github.com/joaom00/selection-popover/issues"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc