@bitux/review-layer-react 0.1.8 → 0.1.9
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.
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var We;function br(){if(We)return ce;We=1;var r=s,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,l=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c
|
|
9
|
+
*/var We;function br(){if(We)return ce;We=1;var r=s,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,l=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function f(c,v,h){var m,S={},w=null,L=null;h!==void 0&&(w=""+h),v.key!==void 0&&(w=""+v.key),v.ref!==void 0&&(L=v.ref);for(m in v)o.call(v,m)&&!i.hasOwnProperty(m)&&(S[m]=v[m]);if(c&&c.defaultProps)for(m in v=c.defaultProps,v)S[m]===void 0&&(S[m]=v[m]);return{$$typeof:n,type:c,key:w,ref:L,props:S,_owner:l.current}}return ce.Fragment=t,ce.jsx=f,ce.jsxs=f,ce}var de={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Be;function yr(){return Be||(Be=1,process.env.NODE_ENV!=="production"&&function(){var r=s,n=Symbol.for("react.element"),t=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),
|
|
17
|
+
*/var Be;function yr(){return Be||(Be=1,process.env.NODE_ENV!=="production"&&function(){var r=s,n=Symbol.for("react.element"),t=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),f=Symbol.for("react.provider"),c=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),L=Symbol.for("react.offscreen"),A=Symbol.iterator,M="@@iterator";function V(e){if(e===null||typeof e!="object")return null;var a=A&&e[A]||e[M];return typeof a=="function"?a:null}var N=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function p(e){{for(var a=arguments.length,u=new Array(a>1?a-1:0),g=1;g<a;g++)u[g-1]=arguments[g];T("error",e,u)}}function T(e,a,u){{var g=N.ReactDebugCurrentFrame,k=g.getStackAddendum();k!==""&&(a+="%s",u=u.concat([k]));var P=u.map(function(_){return String(_)});P.unshift("Warning: "+a),Function.prototype.apply.call(console[e],console,P)}}var Y=!1,R=!1,C=!1,I=!1,X=!1,H;H=Symbol.for("react.module.reference");function K(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===i||X||e===l||e===h||e===m||I||e===L||Y||R||C||typeof e=="object"&&e!==null&&(e.$$typeof===w||e.$$typeof===S||e.$$typeof===f||e.$$typeof===c||e.$$typeof===v||e.$$typeof===H||e.getModuleId!==void 0))}function ie(e,a,u){var g=e.displayName;if(g)return g;var k=a.displayName||a.name||"";return k!==""?u+"("+k+")":u}function b(e){return e.displayName||"Context"}function y(e){if(e==null)return null;if(typeof e.tag=="number"&&p("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case t:return"Portal";case i:return"Profiler";case l:return"StrictMode";case h:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case c:var a=e;return b(a)+".Consumer";case f:var u=e;return b(u._context)+".Provider";case v:return ie(e,e.render,"ForwardRef");case S:var g=e.displayName||null;return g!==null?g:y(e.type)||"Memo";case w:{var k=e,P=k._payload,_=k._init;try{return y(_(P))}catch{return null}}}return null}var D=Object.assign,O=0,ee,ae,se,ve,pe,E,$;function re(){}re.__reactDisabledLog=!0;function q(){{if(O===0){ee=console.log,ae=console.info,se=console.warn,ve=console.error,pe=console.group,E=console.groupCollapsed,$=console.groupEnd;var e={configurable:!0,enumerable:!0,value:re,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}O++}}function we(){{if(O--,O===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:ee}),info:D({},e,{value:ae}),warn:D({},e,{value:se}),error:D({},e,{value:ve}),group:D({},e,{value:pe}),groupCollapsed:D({},e,{value:E}),groupEnd:D({},e,{value:$})})}O<0&&p("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ie=N.ReactCurrentDispatcher,Oe;function Ee(e,a,u){{if(Oe===void 0)try{throw Error()}catch(k){var g=k.stack.trim().match(/\n( *(at )?)/);Oe=g&&g[1]||""}return`
|
|
18
18
|
`+Oe+e}}var De=!1,_e;{var Et=typeof WeakMap=="function"?WeakMap:Map;_e=new Et}function tr(e,a){if(!e||De)return"";{var u=_e.get(e);if(u!==void 0)return u}var g;De=!0;var k=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var P;P=Ie.current,Ie.current=null,q();try{if(a){var _=function(){throw Error()};if(Object.defineProperty(_.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(_,[])}catch(G){g=G}Reflect.construct(e,[],_)}else{try{_.call()}catch(G){g=G}e.call(_.prototype)}}else{try{throw Error()}catch(G){g=G}e()}}catch(G){if(G&&g&&typeof G.stack=="string"){for(var x=G.stack.split(`
|
|
19
19
|
`),B=g.stack.split(`
|
|
20
20
|
`),z=x.length-1,F=B.length-1;z>=1&&F>=0&&x[z]!==B[F];)F--;for(;z>=1&&F>=0;z--,F--)if(x[z]!==B[F]){if(z!==1||F!==1)do if(z--,F--,F<0||x[z]!==B[F]){var J=`
|
|
@@ -27,7 +27,7 @@ Check the top-level render call using <`+u+">.")}return a}}function vr(e,a){{if(
|
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Ne,te,Ht,te),gr[te+Ne]=!0}}return e===o?Mt(F):Nt(F),F}}function Wt(e,a,u){return hr(e,a,u,!0)}function Bt(e,a,u){return hr(e,a,u,!1)}var Ut=Bt,Yt=Wt;de.Fragment=o,de.jsx=Ut,de.jsxs=Yt}()),de}process.env.NODE_ENV==="production"?Se.exports=br():Se.exports=yr();var d=Se.exports;function xr(r){if(r.id&&/^[a-zA-Z][\w-]*$/.test(r.id))return`#${r.id}`;const n=[];let t=r;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let o=t.nodeName.toLowerCase();if(t.id&&/^[a-zA-Z][\w-]*$/.test(t.id)){n.unshift(`#${t.id}`);break}if(t.className&&typeof t.className=="string"){const l=t.className.trim().split(/\s+/).filter(Boolean);if(l.length>0){const i=l.filter(c=>/^[a-zA-Z][\w-]*$/.test(c)).slice(0,2).map(c=>`.${c}`).join("");i&&(o+=i)}}if(n.length>0){const l=t.parentElement;if(l){const i=Array.from(l.children).filter(c=>c.nodeName===t.nodeName);if(i.length>1){const c=i.indexOf(t)+1;o+=`:nth-child(${c})`}}}n.unshift(o),t=t.parentElement}return n.join(" > ")}const mr="[data-review-layer-root]",wr=16;function ke(r,n,t=wr){if(typeof window>"u")return{x:r,y:n};const o=t,l=t,i=window.innerWidth-t,c=window.innerHeight-t;return{x:Math.max(o,Math.min(i,r)),y:Math.max(l,Math.min(c,n))}}function Ue(r){if(typeof document>"u"||!r)return[];const n=[];let t=r.parentElement;for(;t&&t!==document.body;){const o=getComputedStyle(t),l=o.overflowX,i=o.overflowY;(l==="scroll"||l==="auto"||l==="overlay"||i==="scroll"||i==="auto"||i==="overlay")&&(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&n.push(t),t=t.parentElement}return n}function Ye(r){var n;if(typeof document>"u"||!(r!=null&&r.trim()))return null;try{const t=document.querySelector(r);return!t||(n=t.closest)!=null&&n.call(t,mr)?null:t.getBoundingClientRect()}catch{return null}}function Er(r){if(typeof window>"u")return{relativeX:0,relativeY:0};const n=window.innerWidth,t=window.innerHeight;return{relativeX:n>0?r.left/n:0,relativeY:t>0?r.top/t:0}}function He(r){if(typeof window>"u")return{x:r.x??0,y:r.y??0};const n=r.relativeX??r.relative_x??null,t=r.relativeY??r.relative_y??null;return n!=null&&t!=null?{x:n*window.innerWidth,y:t*window.innerHeight}:{x:r.x??0,y:r.y??0}}function _r(r){const{x:n,y:t}=He(r),o=r.width??100,l=r.height??40;return new DOMRect(n,t,o,l)}function he(r){if(r.selector){const n=Ye(r.selector);if(n!=null)return{x:n.left,y:n.top}}return He(r)}const Rr=["path"];function Cr(r){return r.trim().startsWith("/")?r.trim():`/${r.trim()}`}function Ge(){if(typeof window>"u")return"/";try{const r=new URLSearchParams(window.location.search);for(const[,t]of r){const o=t==null?void 0:t.trim();if(o!==""&&o.startsWith("/"))return o}for(const t of Rr){const o=r.get(t);if(o!=null&&o.trim()!=="")return Cr(o)}const n=window.location.pathname||"/";if(n==="/iframe.html"||n.endsWith("/iframe.html")){const t=r.get("id");if(t!=null&&t.trim()!=="")return`/story/${t.trim()}`}}catch{}return window.location.pathname||"/"}const j={PENDING:"pending",DEV_FIXED:"dev_fixed",VALIDATED:"validated"},Xe="[review-layer API]";function Q(r,n,t){if("status"in t){const{status:f,statusText:v,body:h=""}=t;let m;f===401?m="No autorizado (401). Revisa que apiKey sea correcta y esté aceptada por la API.":f===403?m="Acceso denegado (403). Revisa apiKey o permisos del proyecto.":f===404?m="Recurso no encontrado (404). Revisa apiUrl y que la ruta exista en el backend.":f>=500?m="Error del servidor (5xx). El backend puede estar caído o sobrecargado.":m=`Respuesta HTTP ${f} ${v}. Revisa la API.`,console.error(Xe,r,{motivo:m,url:n,status:f,statusText:v,body:h.slice(0,300)});return}const o=t.networkError,l=o instanceof Error?o.message:String(o),c=o instanceof TypeError||/failed to fetch|networkerror|load failed|network request failed/i.test(l)?"Posible CORS o error de red (servidor inalcanzable, bloqueo CORS o certificado). Revisa que apiUrl sea accesible desde este origen y que el backend permita CORS.":`Error inesperado: ${l}`;console.error(Xe,r,{motivo:c,url:n,error:o})}function fe(r){return{"Content-Type":"application/json","x-review-key":r}}async function Sr(r,n,t){const o=`${r}/reviewers`;let l;try{l=await fetch(o,{headers:fe(n),signal:t==null?void 0:t.signal})}catch(c){throw Q("fetchReviewers (red/CORS)",o,{networkError:c}),c}if(!l.ok){const c=await l.text();throw Q("fetchReviewers",o,{status:l.status,statusText:l.statusText,body:c}),new Error("Failed to fetch reviewers")}return(await l.json()).data??[]}async function kr(r,n,t){const o=`${r}/comments`;let l;try{l=await fetch(o,{method:"POST",headers:fe(n),body:JSON.stringify(t)})}catch(c){throw Q("createComment (red/CORS)",o,{networkError:c}),c}if(!l.ok){const c=await l.text();let f="Failed to create comment";try{f=JSON.parse(c).message??f}catch{}throw Q("createComment",o,{status:l.status,statusText:l.statusText,body:c}),new Error(f)}return(await l.json()).data}async function Tr(r,n,t,o){const l=new URLSearchParams({url:t}),i=`${r}/comments?${l}`;let c;try{c=await fetch(i,{headers:fe(n),signal:o==null?void 0:o.signal})}catch(v){throw Q("fetchComments (red/CORS)",i,{networkError:v}),v}if(!c.ok){const v=await c.text();throw Q("fetchComments",i,{status:c.status,statusText:c.statusText,body:v}),new Error("Failed to fetch comments")}return(await c.json()).data??[]}async function Pr(r,n,t,o){const l=`${r}/comments/${t}/status`;let i;try{i=await fetch(l,{method:"PATCH",headers:fe(n),body:JSON.stringify({status:o})})}catch(f){throw Q("updateCommentStatus (red/CORS)",l,{networkError:f}),f}if(!i.ok){const f=await i.text();Q("updateCommentStatus",l,{status:i.status,statusText:i.statusText,body:f});let v="Failed to update comment status";try{v=JSON.parse(f).message??v}catch{}throw new Error(v)}return(await i.json()).data}async function jr(r,n,t){const o=`${r}/comments/${t}`;let l;try{l=await fetch(o,{method:"DELETE",headers:fe(n)})}catch(i){throw Q("deleteComment (red/CORS)",o,{networkError:i}),i}if(!l.ok){const i=await l.text();Q("deleteComment",o,{status:l.status,statusText:l.statusText,body:i});let c="Failed to delete comment";try{c=JSON.parse(i).message??c}catch{}throw new Error(c)}}const Vr={position:"fixed",inset:0,zIndex:999997,backgroundColor:"transparent"},Ir={position:"fixed",minWidth:320,maxWidth:400,padding:"var(--ui-positive-Value_400, 16px)",backgroundColor:"var(--ui-color-bg-surface-default, #fff)",border:"1px solid var(--ui-color-border-subtle, #e8e8e8)",borderRadius:"var(--ui-radius_8, 8px)",boxShadow:"0 8px 24px var(--ui-color-black-alpha-20, rgba(0,0,0,0.15))",zIndex:999998},Or={width:"100%",minHeight:80,padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_300, 12px)",marginBottom:"var(--ui-positive-Value_200, 12px)",border:"1px solid var(--ui-color-border-default, #d9d9d9)",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-sm, 14px)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",resize:"vertical",boxSizing:"border-box"},Dr={width:"100%",padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_300, 12px)",marginBottom:"var(--ui-positive-Value_300, 12px)",border:"1px solid var(--ui-color-border-default, #d9d9d9)",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-sm, 14px)"},Je={padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_400, 16px)",backgroundColor:"var(--ui-color-bg-fill-danger-default, #ff4d4f)",color:"var(--ui-color-text-on-color, #fff)",border:"none",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-sm, 14px)",cursor:"pointer",fontWeight:"var(--ui-font-weight-medium, 500)"};function Lr({apiUrl:r,apiKey:n,reviewers:t,position:o,payload:l,onClose:i,onSuccess:c}){var N;const[f,v]=s.useState(""),[h,m]=s.useState(((N=t[0])==null?void 0:N.id)??0),[S,w]=s.useState(!1),[L,A]=s.useState(null);s.useEffect(()=>{t.length>0&&!h&&m(t[0].id)},[t,h]);const M=s.useCallback(async p=>{if(p.preventDefault(),!(!f.trim()||!h)){w(!0),A(null);try{await kr(r,n,{...l,message:f.trim(),reviewerId:h}),c(),i()}catch(T){A(T instanceof Error?T.message:"Failed to send comment")}finally{w(!1)}}},[r,n,l,f,h,c,i]),V=s.useRef(null);return s.useEffect(()=>{const p=T=>{T.key==="Escape"&&(T.preventDefault(),i())};return document.addEventListener("keydown",p,!0),()=>document.removeEventListener("keydown",p,!0)},[i]),s.useEffect(()=>{const p=T=>{const Y=T.target;V.current&&!V.current.contains(Y)&&(T.preventDefault(),T.stopPropagation(),i())};return document.addEventListener("mousedown",p,!0),()=>document.removeEventListener("mousedown",p,!0)},[i]),s.useEffect(()=>{var p;(p=V.current)==null||p.focus()},[]),d.jsxs("div",{ref:V,role:"dialog","aria-modal":"true",tabIndex:-1,style:{position:"fixed",inset:0,zIndex:999997,outline:"none"},children:[d.jsx("div",{role:"presentation",style:Vr,onClick:i}),d.jsx("div",{style:{...Ir,left:Math.min(o.x,typeof window<"u"?window.innerWidth-420:o.x),top:o.y+12},onClick:p=>p.stopPropagation(),children:d.jsxs("form",{onSubmit:M,children:[d.jsx("textarea",{placeholder:"Escribe tu comentario...",value:f,onChange:p=>v(p.target.value),style:Or,required:!0,autoFocus:!0}),d.jsxs("select",{value:h,onChange:p=>m(Number(p.target.value)),style:Dr,required:!0,disabled:t.length===0,children:[d.jsx("option",{value:"",children:t.length===0?"No hay revisores (ejecuta php artisan db:seed en la API)":"Selecciona revisor"}),t.map(p=>d.jsx("option",{value:p.id,children:p.name},p.id))]}),L&&d.jsx("div",{style:{color:"var(--ui-color-text-danger-default, #ff4d4f)",fontSize:"var(--ui-font-size-xs, 12px)",marginBottom:"var(--ui-positive-Value_200, 8px)"},children:L}),d.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--ui-positive-Value_200, 8px)"},children:[d.jsx("button",{type:"button",onClick:i,style:{...Je,backgroundColor:"var(--ui-color-bg-fill-secondary-default, #f0f0f0)",color:"var(--ui-color-text-primary, #333)"},children:"Cancelar"}),d.jsx("button",{type:"submit",style:Je,disabled:S||t.length===0,children:S?"Enviando...":"Enviar comentario"})]})]})})]})}const Ar=s.memo(Lr),zr="var(--ui-color-red-500, #ef4444)";function Fr(r){return{position:"fixed",outline:`2px solid ${r}`,outlineOffset:"var(--ui-positive-Value_200, 2px)",pointerEvents:"none",zIndex:999997,boxSizing:"border-box"}}const Nr=s.memo(function({selector:n,active:t,fallbackComment:o,outlineColor:l=zr}){const[i,c]=s.useState(null),f=s.useCallback(()=>{if(!t){c(null);return}const v=n!=null&&n.trim()?Ye(n):null;if(v){c(v);return}if(o){c(_r(o));return}c(null)},[n,t,o]);return s.useEffect(()=>{f()},[f]),s.useEffect(()=>{if(t)return window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[t,f]),!t||i==null?null:d.jsx("div",{"aria-hidden":!0,style:{...Fr(l),left:i.left,top:i.top,width:i.width,height:i.height}})}),be=32,Ze=150,Te=250,U={cardBg:"var(--ui-color-bg-surface-default, #ffffff)",cardFooterBg:"var(--ui-color-bg-surface-secondary-default, #f8fafc)",textDark:"var(--ui-color-text-primary, #333333)",textMuted:"var(--ui-color-text-secondary, #888888)",border:"var(--ui-color-border-default, #cccccc)",shadow:"var(--ui-shadow-card, 0 4px 16px rgba(0, 0, 0, 0.12))"},Mr={[j.PENDING]:"Pendiente",[j.DEV_FIXED]:"Corregido",[j.VALIDATED]:"Validado"},Wr={[j.PENDING]:"PENDIENTE",[j.DEV_FIXED]:"CORREGIDO",[j.VALIDATED]:"VALIDADO"},oe={[j.PENDING]:"var(--ui-color-red-500, rgb(240, 69, 69))",[j.DEV_FIXED]:"var(--ui-color-yellow-500, rgb(235, 179, 8))",[j.VALIDATED]:"var(--ui-color-green-500, rgb(33, 196, 94))"},Qe={[j.PENDING]:"var(--ui-color-bg-surface-danger-default, #fef2f2)",[j.DEV_FIXED]:"var(--ui-color-bg-surface-warning-default, #fffbeb)",[j.VALIDATED]:"var(--ui-color-bg-surface-success-default, #f0fdf4)"},ye={[j.PENDING]:"var(--ui-color-red-500, #ef4444)",[j.DEV_FIXED]:"var(--ui-color-orange-500, #f59e0b)",[j.VALIDATED]:"var(--ui-color-green-500, #22c55e)"};function Br(r){const n=r.trim().split(/\s+/);return n.length>=2?(n[0][0]+n[n.length-1][0]).toUpperCase():r.slice(0,2).toUpperCase()||"?"}const Ur=()=>d.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{marginRight:4,flexShrink:0},children:d.jsx("path",{d:"M10 3L4.5 8.5L2 6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),Yr=({color:r})=>d.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[d.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),d.jsx("path",{d:"M8 10h.01M12 10h.01M16 10h.01",stroke:"var(--ui-color-white, #fff)",strokeWidth:"1.5",strokeLinecap:"round"})]}),Hr=r=>({position:"fixed",width:be,height:be,borderRadius:"50%",backgroundColor:oe[r]??oe[j.PENDING],color:"var(--ui-color-text-on-color, #fff)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",boxShadow:"0 2px 8px var(--ui-color-black-alpha-20, rgba(0,0,0,0.2))",zIndex:999998,border:"2px solid var(--ui-color-white, #fff)"}),Gr={position:"fixed",width:Te,minWidth:Te,maxWidth:Te,boxSizing:"border-box",backgroundColor:U.cardBg,borderRadius:"var(--ui-radius_12, 12px)",boxShadow:U.shadow,fontSize:"var(--ui-font-size-sm, 14px)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",zIndex:999999,pointerEvents:"auto"},Xr={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--ui-positive-Value_250, 10px)",borderBottom:`1px solid ${U.border}`,padding:"var(--ui-positive-Value_300, 12px)"},Jr=r=>({width:40,height:40,borderRadius:"50%",backgroundColor:oe[r]??oe[j.PENDING],color:"var(--ui-color-text-on-color, #fff)",border:"2px solid var(--ui-color-white, #fff)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"var(--ui-font-size-sm, 14px)",fontWeight:"var(--ui-font-weight-bold, 700)",flexShrink:0,overflow:"hidden"}),Zr=s.memo(function({reviewer:n,status:t}){const o=n==null?void 0:n.image_url,l=(n==null?void 0:n.name)??"Revisor",i=Jr(t);if(o&&o.trim()){const c=oe[t]??oe[j.PENDING];return d.jsx("div",{style:{...i,border:`2px solid ${c}`},children:d.jsx("img",{src:o,alt:l,style:{width:"100%",height:"100%",objectFit:"cover"},loading:"lazy"})})}return d.jsx("div",{style:i,children:Br(l)})}),Qr={flexShrink:0,width:"var(--ui-positive-Value_600, 24px)",height:"var(--ui-positive-Value_600, 24px)",padding:0,border:"none",borderRadius:"var(--ui-radius_6, 6px)",backgroundColor:"transparent",color:U.textDark,cursor:"pointer",fontSize:"var(--ui-positive-Value_450, 18px)",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},Kr=r=>{const n=ye[r]??ye[j.PENDING];return{display:"inline-flex",alignItems:"center",padding:"var(--ui-positive-Value_50, 4px) var(--ui-positive-Value_100, 10px)",borderRadius:"var(--ui-radius_full, 9999px)",fontSize:"8px",fontWeight:"var(--ui-font-weight-bold, 700)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",textTransform:"uppercase",letterSpacing:"0.02em",backgroundColor:Qe[r]??Qe[j.PENDING],color:n,border:`1px solid ${n}`}},qr={display:"block",fontSize:"var(--ui-font-size-2xs, 10px)",fontWeight:"var(--ui-font-weight-semibold, 600)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",color:U.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},$r={width:"100%",padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_300, 12px)",paddingRight:"var(--ui-positive-Value_800, 32px)",fontSize:"var(--ui-font-size-xs, 13px)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",borderRadius:"var(--ui-radius_8, 8px)",border:`1px solid ${U.border}`,backgroundColor:U.cardBg,color:U.textDark,cursor:"pointer",appearance:"none",backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L2 4h8z'/%3E%3C/svg%3E")`,backgroundRepeat:"no-repeat",backgroundPosition:"right var(--ui-positive-Value_250, 10px) center"},et={display:"flex",alignItems:"center",justifyContent:"flex-end",gap:"var(--ui-positive-Value_200, 8px)",padding:"var(--ui-positive-Value_300, 12px)",borderTop:`1px solid ${U.border}`,backgroundColor:U.cardFooterBg},Ke={minWidth:100,padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_350, 14px)",fontSize:"var(--ui-font-size-xs, 13px)",fontWeight:"var(--ui-font-weight-semibold, 600)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",borderRadius:"var(--ui-radius_8, 8px)",cursor:"pointer",border:"none"},rt={...Ke,backgroundColor:"transparent",color:U.textDark},xe="review-layer-resolve-btn",tt=["pending","dev_fixed","validated"],ot={...Ke,backgroundColor:"var(--ui-color-bg-fill-success-default, #22c55e)",color:"var(--ui-color-text-on-color, #fff)"};function nt({comment:r,offset:n={dx:0,dy:0},apiUrl:t,apiKey:o,onStatusChange:l,reviewMode:i=!1}){var ve,pe;const[c,f]=s.useState(!1),[v,h]=s.useState(!1),[m,S]=s.useState(()=>he(r)),[w,L]=s.useState(!1),[A,M]=s.useState(null),V=s.useRef(null),N=s.useRef(null),p=s.useRef(null),T=s.useCallback(()=>{S(he(r))},[r]);s.useEffect(()=>{T()},[T]),s.useEffect(()=>{if(!(typeof window>"u"))return window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[T]),s.useEffect(()=>{if(!r.selector||typeof document>"u")return;const E=document.querySelector(r.selector);if(!E)return;const re=Ue(E).map(q=>(q.addEventListener("scroll",T,!0),()=>q.removeEventListener("scroll",T,!0)));return()=>re.forEach(q=>q())},[r.selector,T]);const Y=s.useCallback(()=>{V.current!==null&&(clearTimeout(V.current),V.current=null)},[]),R=s.useCallback(()=>{i||(Y(),f(!0))},[i,Y]),C=s.useCallback(()=>{v||(V.current=setTimeout(()=>{V.current=null,f(!1)},Ze))},[v]),I=s.useCallback(()=>{Y(),f(!0)},[Y]),X=s.useCallback(()=>{v||(V.current=setTimeout(()=>{V.current=null,f(!1)},Ze))},[v]),H=s.useCallback(()=>{if(i){v&&(h(!1),f(!1));return}v?(h(!1),f(!1)):(h(!0),f(!0))},[i,v]);s.useEffect(()=>{if(!v)return;const E=$=>{var q,we;const re=$.target;(q=N.current)!=null&&q.contains(re)||(we=p.current)!=null&&we.contains(re)||(h(!1),f(!1))};return document.addEventListener("mousedown",E,!0),()=>document.removeEventListener("mousedown",E,!0)},[v]),s.useEffect(()=>()=>Y(),[Y]),s.useEffect(()=>{i&&(h(!1),f(!1))},[i]);const K=m.x+n.dx,ie=m.y+n.dy,{x:b,y}=ke(K,ie,be/2),D=c&&!v,O=s.useCallback(()=>{h(!1),f(!1)},[]),ee=s.useCallback(async E=>{if(E!==r.status){M(null),L(!0);try{await Pr(t,o,r.id,E),l()}catch($){M($ instanceof Error?$.message:"Error al actualizar")}finally{L(!1)}}},[t,o,r.id,r.status,l]),ae=s.useCallback(async()=>{M(null),L(!0);try{await jr(t,o,r.id),l(),O()}catch(E){M(E instanceof Error?E.message:"Error al eliminar")}finally{L(!1)}},[t,o,r.id,l,O]),se=s.useMemo(()=>({...Hr(r.status),left:b,top:y,transform:"translate(-50%, -50%)"}),[r.status,b,y]);return d.jsxs(d.Fragment,{children:[d.jsx(Nr,{selector:r.selector,active:D,fallbackComment:r,outlineColor:ye[r.status]??ye[j.PENDING]}),d.jsx("div",{ref:N,role:"button",tabIndex:0,"aria-label":`Comentario: ${r.message.slice(0,30)}...`,"aria-expanded":c,style:se,onMouseEnter:R,onMouseLeave:C,onClick:H,children:d.jsx(Yr,{color:"var(--ui-color-white, #fff)"})}),c&&d.jsxs("div",{ref:p,role:"dialog","aria-label":"Detalle del comentario",style:{...Gr,left:b+be/2+6,top:y},onMouseEnter:I,onMouseLeave:X,children:[d.jsxs("div",{style:Xr,children:[d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flex:1,minWidth:0},children:[d.jsx(Zr,{reviewer:r.reviewer,status:r.status}),d.jsxs("div",{children:[d.jsx("div",{style:{fontWeight:700,fontSize:14,color:U.textDark},children:((ve=r.reviewer)==null?void 0:ve.name)??"Revisor"}),d.jsx("div",{style:{fontSize:12,color:U.textMuted},children:((pe=r.reviewer)==null?void 0:pe.job_title)??"Revisor"})]})]}),d.jsx("button",{type:"button","aria-label":r.status===j.VALIDATED?"Eliminar comentario":"Cerrar",style:Qr,disabled:w,onClick:E=>{E.stopPropagation(),r.status===j.VALIDATED?ae():O()},onMouseDown:E=>E.stopPropagation(),children:"✕"})]}),d.jsxs("div",{style:{padding:12,display:"flex",alignItems:"flex-start",flexDirection:"column",gap:4},children:[d.jsxs("div",{style:Kr(r.status),children:[r.status===j.VALIDATED&&d.jsx(Ur,{}),Wr[r.status]??r.status]}),d.jsx("div",{style:{color:U.textDark,lineHeight:1.5,marginBottom:12,marginTop:12},children:r.message}),d.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,width:"100%"},children:[d.jsx("label",{style:qr,htmlFor:`comment-status-${r.id}`,children:"Cambiar estado"}),d.jsx("select",{id:`comment-status-${r.id}`,style:$r,value:r.status,disabled:w,onChange:E=>ee(E.target.value),onMouseDown:E=>E.stopPropagation(),"aria-label":"Cambiar estado del comentario",children:tt.map(E=>d.jsx("option",{value:E,children:Mr[E]},E))}),A&&d.jsx("div",{style:{marginTop:8,fontSize:11,color:"var(--ui-color-text-danger-default, rgb(240, 69, 69))"},children:A})]})]}),d.jsxs("div",{style:et,children:[d.jsx("button",{type:"button",style:rt,onMouseDown:E=>E.stopPropagation(),onClick:E=>{E.stopPropagation(),O()},children:"Cerrar"}),r.status!==j.VALIDATED&&d.jsxs(d.Fragment,{children:[d.jsx("style",{children:`
|
|
30
|
+
<%s key={someKey} {...props} />`,Ne,te,Ht,te),gr[te+Ne]=!0}}return e===o?Mt(F):Nt(F),F}}function Wt(e,a,u){return hr(e,a,u,!0)}function Bt(e,a,u){return hr(e,a,u,!1)}var Ut=Bt,Yt=Wt;de.Fragment=o,de.jsx=Ut,de.jsxs=Yt}()),de}process.env.NODE_ENV==="production"?Se.exports=br():Se.exports=yr();var d=Se.exports;function xr(r){if(r.id&&/^[a-zA-Z][\w-]*$/.test(r.id))return`#${r.id}`;const n=[];let t=r;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let o=t.nodeName.toLowerCase();if(t.id&&/^[a-zA-Z][\w-]*$/.test(t.id)){n.unshift(`#${t.id}`);break}if(t.className&&typeof t.className=="string"){const i=t.className.trim().split(/\s+/).filter(Boolean);if(i.length>0){const f=i.filter(c=>/^[a-zA-Z][\w-]*$/.test(c)).slice(0,2).map(c=>`.${c}`).join("");f&&(o+=f)}}const l=t.parentElement;if(l){const i=Array.from(l.children);if(i.length>1){const f=i.indexOf(t)+1;o+=`:nth-child(${f})`}}n.unshift(o),t=t.parentElement}return n.join(" > ")}const mr="[data-review-layer-root]",wr=16;function ke(r,n,t=wr){if(typeof window>"u")return{x:r,y:n};const o=t,l=t,i=window.innerWidth-t,f=window.innerHeight-t;return{x:Math.max(o,Math.min(i,r)),y:Math.max(l,Math.min(f,n))}}function Ue(r){if(typeof document>"u"||!r)return[];const n=[];let t=r.parentElement;for(;t&&t!==document.body;){const o=getComputedStyle(t),l=o.overflowX,i=o.overflowY;(l==="scroll"||l==="auto"||l==="overlay"||i==="scroll"||i==="auto"||i==="overlay")&&(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&n.push(t),t=t.parentElement}return n}function Ye(r){var n;if(typeof document>"u"||!(r!=null&&r.trim()))return null;try{const t=document.querySelector(r);return!t||(n=t.closest)!=null&&n.call(t,mr)?null:t.getBoundingClientRect()}catch{return null}}function Er(r){if(typeof window>"u")return{relativeX:0,relativeY:0};const n=window.innerWidth,t=window.innerHeight;return{relativeX:n>0?r.left/n:0,relativeY:t>0?r.top/t:0}}function He(r){if(typeof window>"u")return{x:r.x??0,y:r.y??0};const n=r.relativeX??r.relative_x??null,t=r.relativeY??r.relative_y??null;return n!=null&&t!=null?{x:n*window.innerWidth,y:t*window.innerHeight}:{x:r.x??0,y:r.y??0}}function _r(r){const{x:n,y:t}=He(r),o=r.width??100,l=r.height??40;return new DOMRect(n,t,o,l)}function he(r){if(r.selector){const n=Ye(r.selector);if(n!=null)return{x:n.left,y:n.top}}return He(r)}const Rr=["path"];function Cr(r){return r.trim().startsWith("/")?r.trim():`/${r.trim()}`}function Ge(){if(typeof window>"u")return"/";try{const r=new URLSearchParams(window.location.search);for(const[,t]of r){const o=t==null?void 0:t.trim();if(o!==""&&o.startsWith("/"))return o}for(const t of Rr){const o=r.get(t);if(o!=null&&o.trim()!=="")return Cr(o)}const n=window.location.pathname||"/";if(n==="/iframe.html"||n.endsWith("/iframe.html")){const t=r.get("id");if(t!=null&&t.trim()!=="")return`/story/${t.trim()}`}}catch{}return window.location.pathname||"/"}const j={PENDING:"pending",DEV_FIXED:"dev_fixed",VALIDATED:"validated"},Xe="[review-layer API]";function Q(r,n,t){if("status"in t){const{status:c,statusText:v,body:h=""}=t;let m;c===401?m="No autorizado (401). Revisa que apiKey sea correcta y esté aceptada por la API.":c===403?m="Acceso denegado (403). Revisa apiKey o permisos del proyecto.":c===404?m="Recurso no encontrado (404). Revisa apiUrl y que la ruta exista en el backend.":c>=500?m="Error del servidor (5xx). El backend puede estar caído o sobrecargado.":m=`Respuesta HTTP ${c} ${v}. Revisa la API.`,console.error(Xe,r,{motivo:m,url:n,status:c,statusText:v,body:h.slice(0,300)});return}const o=t.networkError,l=o instanceof Error?o.message:String(o),f=o instanceof TypeError||/failed to fetch|networkerror|load failed|network request failed/i.test(l)?"Posible CORS o error de red (servidor inalcanzable, bloqueo CORS o certificado). Revisa que apiUrl sea accesible desde este origen y que el backend permita CORS.":`Error inesperado: ${l}`;console.error(Xe,r,{motivo:f,url:n,error:o})}function fe(r){return{"Content-Type":"application/json","x-review-key":r}}async function Sr(r,n,t){const o=`${r}/reviewers`;let l;try{l=await fetch(o,{headers:fe(n),signal:t==null?void 0:t.signal})}catch(f){throw Q("fetchReviewers (red/CORS)",o,{networkError:f}),f}if(!l.ok){const f=await l.text();throw Q("fetchReviewers",o,{status:l.status,statusText:l.statusText,body:f}),new Error("Failed to fetch reviewers")}return(await l.json()).data??[]}async function kr(r,n,t){const o=`${r}/comments`;let l;try{l=await fetch(o,{method:"POST",headers:fe(n),body:JSON.stringify(t)})}catch(f){throw Q("createComment (red/CORS)",o,{networkError:f}),f}if(!l.ok){const f=await l.text();let c="Failed to create comment";try{c=JSON.parse(f).message??c}catch{}throw Q("createComment",o,{status:l.status,statusText:l.statusText,body:f}),new Error(c)}return(await l.json()).data}async function Tr(r,n,t,o){const l=new URLSearchParams({url:t}),i=`${r}/comments?${l}`;let f;try{f=await fetch(i,{headers:fe(n),signal:o==null?void 0:o.signal})}catch(v){throw Q("fetchComments (red/CORS)",i,{networkError:v}),v}if(!f.ok){const v=await f.text();throw Q("fetchComments",i,{status:f.status,statusText:f.statusText,body:v}),new Error("Failed to fetch comments")}return(await f.json()).data??[]}async function Pr(r,n,t,o){const l=`${r}/comments/${t}/status`;let i;try{i=await fetch(l,{method:"PATCH",headers:fe(n),body:JSON.stringify({status:o})})}catch(c){throw Q("updateCommentStatus (red/CORS)",l,{networkError:c}),c}if(!i.ok){const c=await i.text();Q("updateCommentStatus",l,{status:i.status,statusText:i.statusText,body:c});let v="Failed to update comment status";try{v=JSON.parse(c).message??v}catch{}throw new Error(v)}return(await i.json()).data}async function jr(r,n,t){const o=`${r}/comments/${t}`;let l;try{l=await fetch(o,{method:"DELETE",headers:fe(n)})}catch(i){throw Q("deleteComment (red/CORS)",o,{networkError:i}),i}if(!l.ok){const i=await l.text();Q("deleteComment",o,{status:l.status,statusText:l.statusText,body:i});let f="Failed to delete comment";try{f=JSON.parse(i).message??f}catch{}throw new Error(f)}}const Vr={position:"fixed",inset:0,zIndex:999997,backgroundColor:"transparent"},Ir={position:"fixed",minWidth:320,maxWidth:400,padding:"var(--ui-positive-Value_400, 16px)",backgroundColor:"var(--ui-color-bg-surface-default, #fff)",border:"1px solid var(--ui-color-border-subtle, #e8e8e8)",borderRadius:"var(--ui-radius_8, 8px)",boxShadow:"0 8px 24px var(--ui-color-black-alpha-20, rgba(0,0,0,0.15))",zIndex:999998},Or={width:"100%",minHeight:80,padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_300, 12px)",marginBottom:"var(--ui-positive-Value_200, 12px)",border:"1px solid var(--ui-color-border-default, #d9d9d9)",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-sm, 14px)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",resize:"vertical",boxSizing:"border-box"},Dr={width:"100%",padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_300, 12px)",marginBottom:"var(--ui-positive-Value_300, 12px)",border:"1px solid var(--ui-color-border-default, #d9d9d9)",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-sm, 14px)"},Je={padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_400, 16px)",backgroundColor:"var(--ui-color-bg-fill-danger-default, #ff4d4f)",color:"var(--ui-color-text-on-color, #fff)",border:"none",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-sm, 14px)",cursor:"pointer",fontWeight:"var(--ui-font-weight-medium, 500)"};function Lr({apiUrl:r,apiKey:n,reviewers:t,position:o,payload:l,onClose:i,onSuccess:f}){var N;const[c,v]=s.useState(""),[h,m]=s.useState(((N=t[0])==null?void 0:N.id)??0),[S,w]=s.useState(!1),[L,A]=s.useState(null);s.useEffect(()=>{t.length>0&&!h&&m(t[0].id)},[t,h]);const M=s.useCallback(async p=>{if(p.preventDefault(),!(!c.trim()||!h)){w(!0),A(null);try{await kr(r,n,{...l,message:c.trim(),reviewerId:h}),f(),i()}catch(T){A(T instanceof Error?T.message:"Failed to send comment")}finally{w(!1)}}},[r,n,l,c,h,f,i]),V=s.useRef(null);return s.useEffect(()=>{const p=T=>{T.key==="Escape"&&(T.preventDefault(),i())};return document.addEventListener("keydown",p,!0),()=>document.removeEventListener("keydown",p,!0)},[i]),s.useEffect(()=>{const p=T=>{const Y=T.target;V.current&&!V.current.contains(Y)&&(T.preventDefault(),T.stopPropagation(),i())};return document.addEventListener("mousedown",p,!0),()=>document.removeEventListener("mousedown",p,!0)},[i]),s.useEffect(()=>{var p;(p=V.current)==null||p.focus()},[]),d.jsxs("div",{ref:V,role:"dialog","aria-modal":"true",tabIndex:-1,style:{position:"fixed",inset:0,zIndex:999997,outline:"none"},children:[d.jsx("div",{role:"presentation",style:Vr,onClick:i}),d.jsx("div",{style:{...Ir,left:Math.min(o.x,typeof window<"u"?window.innerWidth-420:o.x),top:o.y+12},onClick:p=>p.stopPropagation(),children:d.jsxs("form",{onSubmit:M,children:[d.jsx("textarea",{placeholder:"Escribe tu comentario...",value:c,onChange:p=>v(p.target.value),style:Or,required:!0,autoFocus:!0}),d.jsxs("select",{value:h,onChange:p=>m(Number(p.target.value)),style:Dr,required:!0,disabled:t.length===0,children:[d.jsx("option",{value:"",children:t.length===0?"No hay revisores (ejecuta php artisan db:seed en la API)":"Selecciona revisor"}),t.map(p=>d.jsx("option",{value:p.id,children:p.name},p.id))]}),L&&d.jsx("div",{style:{color:"var(--ui-color-text-danger-default, #ff4d4f)",fontSize:"var(--ui-font-size-xs, 12px)",marginBottom:"var(--ui-positive-Value_200, 8px)"},children:L}),d.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--ui-positive-Value_200, 8px)"},children:[d.jsx("button",{type:"button",onClick:i,style:{...Je,backgroundColor:"var(--ui-color-bg-fill-secondary-default, #f0f0f0)",color:"var(--ui-color-text-primary, #333)"},children:"Cancelar"}),d.jsx("button",{type:"submit",style:Je,disabled:S||t.length===0,children:S?"Enviando...":"Enviar comentario"})]})]})})]})}const Ar=s.memo(Lr),zr="var(--ui-color-red-500, #ef4444)";function Fr(r){return{position:"fixed",outline:`2px solid ${r}`,outlineOffset:"var(--ui-positive-Value_200, 2px)",pointerEvents:"none",zIndex:999997,boxSizing:"border-box"}}const Nr=s.memo(function({selector:n,active:t,fallbackComment:o,outlineColor:l=zr}){const[i,f]=s.useState(null),c=s.useCallback(()=>{if(!t){f(null);return}const v=n!=null&&n.trim()?Ye(n):null;if(v){f(v);return}if(o){f(_r(o));return}f(null)},[n,t,o]);return s.useEffect(()=>{c()},[c]),s.useEffect(()=>{if(t)return window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[t,c]),!t||i==null?null:d.jsx("div",{"aria-hidden":!0,style:{...Fr(l),left:i.left,top:i.top,width:i.width,height:i.height}})}),be=32,Ze=150,Te=250,U={cardBg:"var(--ui-color-bg-surface-default, #ffffff)",cardFooterBg:"var(--ui-color-bg-surface-secondary-default, #f8fafc)",textDark:"var(--ui-color-text-primary, #333333)",textMuted:"var(--ui-color-text-secondary, #888888)",border:"var(--ui-color-border-default, #cccccc)",shadow:"var(--ui-shadow-card, 0 4px 16px rgba(0, 0, 0, 0.12))"},Mr={[j.PENDING]:"Pendiente",[j.DEV_FIXED]:"Corregido",[j.VALIDATED]:"Validado"},Wr={[j.PENDING]:"PENDIENTE",[j.DEV_FIXED]:"CORREGIDO",[j.VALIDATED]:"VALIDADO"},oe={[j.PENDING]:"var(--ui-color-red-500, rgb(240, 69, 69))",[j.DEV_FIXED]:"var(--ui-color-yellow-500, rgb(235, 179, 8))",[j.VALIDATED]:"var(--ui-color-green-500, rgb(33, 196, 94))"},Qe={[j.PENDING]:"var(--ui-color-bg-surface-danger-default, #fef2f2)",[j.DEV_FIXED]:"var(--ui-color-bg-surface-warning-default, #fffbeb)",[j.VALIDATED]:"var(--ui-color-bg-surface-success-default, #f0fdf4)"},ye={[j.PENDING]:"var(--ui-color-red-500, #ef4444)",[j.DEV_FIXED]:"var(--ui-color-orange-500, #f59e0b)",[j.VALIDATED]:"var(--ui-color-green-500, #22c55e)"};function Br(r){const n=r.trim().split(/\s+/);return n.length>=2?(n[0][0]+n[n.length-1][0]).toUpperCase():r.slice(0,2).toUpperCase()||"?"}const Ur=()=>d.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{marginRight:4,flexShrink:0},children:d.jsx("path",{d:"M10 3L4.5 8.5L2 6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),Yr=({color:r})=>d.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[d.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),d.jsx("path",{d:"M8 10h.01M12 10h.01M16 10h.01",stroke:"var(--ui-color-white, #fff)",strokeWidth:"1.5",strokeLinecap:"round"})]}),Hr=r=>({position:"fixed",width:be,height:be,borderRadius:"50%",backgroundColor:oe[r]??oe[j.PENDING],color:"var(--ui-color-text-on-color, #fff)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",boxShadow:"0 2px 8px var(--ui-color-black-alpha-20, rgba(0,0,0,0.2))",zIndex:999998,border:"2px solid var(--ui-color-white, #fff)"}),Gr={position:"fixed",width:Te,minWidth:Te,maxWidth:Te,boxSizing:"border-box",backgroundColor:U.cardBg,borderRadius:"var(--ui-radius_12, 12px)",boxShadow:U.shadow,fontSize:"var(--ui-font-size-sm, 14px)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",zIndex:999999,pointerEvents:"auto"},Xr={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--ui-positive-Value_250, 10px)",borderBottom:`1px solid ${U.border}`,padding:"var(--ui-positive-Value_300, 12px)"},Jr=r=>({width:40,height:40,borderRadius:"50%",backgroundColor:oe[r]??oe[j.PENDING],color:"var(--ui-color-text-on-color, #fff)",border:"2px solid var(--ui-color-white, #fff)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"var(--ui-font-size-sm, 14px)",fontWeight:"var(--ui-font-weight-bold, 700)",flexShrink:0,overflow:"hidden"}),Zr=s.memo(function({reviewer:n,status:t}){const o=n==null?void 0:n.image_url,l=(n==null?void 0:n.name)??"Revisor",i=Jr(t);if(o&&o.trim()){const f=oe[t]??oe[j.PENDING];return d.jsx("div",{style:{...i,border:`2px solid ${f}`},children:d.jsx("img",{src:o,alt:l,style:{width:"100%",height:"100%",objectFit:"cover"},loading:"lazy"})})}return d.jsx("div",{style:i,children:Br(l)})}),Qr={flexShrink:0,width:"var(--ui-positive-Value_600, 24px)",height:"var(--ui-positive-Value_600, 24px)",padding:0,border:"none",borderRadius:"var(--ui-radius_6, 6px)",backgroundColor:"transparent",color:U.textDark,cursor:"pointer",fontSize:"var(--ui-positive-Value_450, 18px)",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},Kr=r=>{const n=ye[r]??ye[j.PENDING];return{display:"inline-flex",alignItems:"center",padding:"var(--ui-positive-Value_50, 4px) var(--ui-positive-Value_100, 10px)",borderRadius:"var(--ui-radius_full, 9999px)",fontSize:"8px",fontWeight:"var(--ui-font-weight-bold, 700)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",textTransform:"uppercase",letterSpacing:"0.02em",backgroundColor:Qe[r]??Qe[j.PENDING],color:n,border:`1px solid ${n}`}},qr={display:"block",fontSize:"var(--ui-font-size-2xs, 10px)",fontWeight:"var(--ui-font-weight-semibold, 600)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",color:U.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},$r={width:"100%",padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_300, 12px)",paddingRight:"var(--ui-positive-Value_800, 32px)",fontSize:"var(--ui-font-size-xs, 13px)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",borderRadius:"var(--ui-radius_8, 8px)",border:`1px solid ${U.border}`,backgroundColor:U.cardBg,color:U.textDark,cursor:"pointer",appearance:"none",backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L2 4h8z'/%3E%3C/svg%3E")`,backgroundRepeat:"no-repeat",backgroundPosition:"right var(--ui-positive-Value_250, 10px) center"},et={display:"flex",alignItems:"center",justifyContent:"flex-end",gap:"var(--ui-positive-Value_200, 8px)",padding:"var(--ui-positive-Value_300, 12px)",borderTop:`1px solid ${U.border}`,backgroundColor:U.cardFooterBg},Ke={minWidth:100,padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_350, 14px)",fontSize:"var(--ui-font-size-xs, 13px)",fontWeight:"var(--ui-font-weight-semibold, 600)",fontFamily:"var(--ui-font-family-ui, 'Inter', sans-serif)",borderRadius:"var(--ui-radius_8, 8px)",cursor:"pointer",border:"none"},rt={...Ke,backgroundColor:"transparent",color:U.textDark},xe="review-layer-resolve-btn",tt=["pending","dev_fixed","validated"],ot={...Ke,backgroundColor:"var(--ui-color-bg-fill-success-default, #22c55e)",color:"var(--ui-color-text-on-color, #fff)"};function nt({comment:r,offset:n={dx:0,dy:0},apiUrl:t,apiKey:o,onStatusChange:l,reviewMode:i=!1}){var ve,pe;const[f,c]=s.useState(!1),[v,h]=s.useState(!1),[m,S]=s.useState(()=>he(r)),[w,L]=s.useState(!1),[A,M]=s.useState(null),V=s.useRef(null),N=s.useRef(null),p=s.useRef(null),T=s.useCallback(()=>{S(he(r))},[r]);s.useEffect(()=>{T()},[T]),s.useEffect(()=>{if(!(typeof window>"u"))return window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[T]),s.useEffect(()=>{if(!r.selector||typeof document>"u")return;const E=document.querySelector(r.selector);if(!E)return;const re=Ue(E).map(q=>(q.addEventListener("scroll",T,!0),()=>q.removeEventListener("scroll",T,!0)));return()=>re.forEach(q=>q())},[r.selector,T]);const Y=s.useCallback(()=>{V.current!==null&&(clearTimeout(V.current),V.current=null)},[]),R=s.useCallback(()=>{i||(Y(),c(!0))},[i,Y]),C=s.useCallback(()=>{v||(V.current=setTimeout(()=>{V.current=null,c(!1)},Ze))},[v]),I=s.useCallback(()=>{Y(),c(!0)},[Y]),X=s.useCallback(()=>{v||(V.current=setTimeout(()=>{V.current=null,c(!1)},Ze))},[v]),H=s.useCallback(()=>{if(i){v&&(h(!1),c(!1));return}v?(h(!1),c(!1)):(h(!0),c(!0))},[i,v]);s.useEffect(()=>{if(!v)return;const E=$=>{var q,we;const re=$.target;(q=N.current)!=null&&q.contains(re)||(we=p.current)!=null&&we.contains(re)||(h(!1),c(!1))};return document.addEventListener("mousedown",E,!0),()=>document.removeEventListener("mousedown",E,!0)},[v]),s.useEffect(()=>()=>Y(),[Y]),s.useEffect(()=>{i&&(h(!1),c(!1))},[i]);const K=m.x+n.dx,ie=m.y+n.dy,{x:b,y}=ke(K,ie,be/2),D=f&&!v,O=s.useCallback(()=>{h(!1),c(!1)},[]),ee=s.useCallback(async E=>{if(E!==r.status){M(null),L(!0);try{await Pr(t,o,r.id,E),l()}catch($){M($ instanceof Error?$.message:"Error al actualizar")}finally{L(!1)}}},[t,o,r.id,r.status,l]),ae=s.useCallback(async()=>{M(null),L(!0);try{await jr(t,o,r.id),l(),O()}catch(E){M(E instanceof Error?E.message:"Error al eliminar")}finally{L(!1)}},[t,o,r.id,l,O]),se=s.useMemo(()=>({...Hr(r.status),left:b,top:y,transform:"translate(-50%, -50%)"}),[r.status,b,y]);return d.jsxs(d.Fragment,{children:[d.jsx(Nr,{selector:r.selector,active:D,fallbackComment:r,outlineColor:ye[r.status]??ye[j.PENDING]}),d.jsx("div",{ref:N,role:"button",tabIndex:0,"aria-label":`Comentario: ${r.message.slice(0,30)}...`,"aria-expanded":f,style:se,onMouseEnter:R,onMouseLeave:C,onClick:H,children:d.jsx(Yr,{color:"var(--ui-color-white, #fff)"})}),f&&d.jsxs("div",{ref:p,role:"dialog","aria-label":"Detalle del comentario",style:{...Gr,left:b+be/2+6,top:y},onMouseEnter:I,onMouseLeave:X,children:[d.jsxs("div",{style:Xr,children:[d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flex:1,minWidth:0},children:[d.jsx(Zr,{reviewer:r.reviewer,status:r.status}),d.jsxs("div",{children:[d.jsx("div",{style:{fontWeight:700,fontSize:14,color:U.textDark},children:((ve=r.reviewer)==null?void 0:ve.name)??"Revisor"}),d.jsx("div",{style:{fontSize:12,color:U.textMuted},children:((pe=r.reviewer)==null?void 0:pe.job_title)??"Revisor"})]})]}),d.jsx("button",{type:"button","aria-label":r.status===j.VALIDATED?"Eliminar comentario":"Cerrar",style:Qr,disabled:w,onClick:E=>{E.stopPropagation(),r.status===j.VALIDATED?ae():O()},onMouseDown:E=>E.stopPropagation(),children:"✕"})]}),d.jsxs("div",{style:{padding:12,display:"flex",alignItems:"flex-start",flexDirection:"column",gap:4},children:[d.jsxs("div",{style:Kr(r.status),children:[r.status===j.VALIDATED&&d.jsx(Ur,{}),Wr[r.status]??r.status]}),d.jsx("div",{style:{color:U.textDark,lineHeight:1.5,marginBottom:12,marginTop:12},children:r.message}),d.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,width:"100%"},children:[d.jsx("label",{style:qr,htmlFor:`comment-status-${r.id}`,children:"Cambiar estado"}),d.jsx("select",{id:`comment-status-${r.id}`,style:$r,value:r.status,disabled:w,onChange:E=>ee(E.target.value),onMouseDown:E=>E.stopPropagation(),"aria-label":"Cambiar estado del comentario",children:tt.map(E=>d.jsx("option",{value:E,children:Mr[E]},E))}),A&&d.jsx("div",{style:{marginTop:8,fontSize:11,color:"var(--ui-color-text-danger-default, rgb(240, 69, 69))"},children:A})]})]}),d.jsxs("div",{style:et,children:[d.jsx("button",{type:"button",style:rt,onMouseDown:E=>E.stopPropagation(),onClick:E=>{E.stopPropagation(),O()},children:"Cerrar"}),r.status!==j.VALIDATED&&d.jsxs(d.Fragment,{children:[d.jsx("style",{children:`
|
|
31
31
|
.${xe}:hover:not(:disabled) {
|
|
32
32
|
background-color: var(--ui-color-bg-fill-success-hover, #16a34a) !important;
|
|
33
33
|
}
|
|
@@ -39,7 +39,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
39
39
|
opacity: 0.7;
|
|
40
40
|
cursor: not-allowed;
|
|
41
41
|
}
|
|
42
|
-
`}),d.jsx("button",{type:"button",className:xe,style:ot,disabled:w,onMouseDown:E=>E.stopPropagation(),onClick:E=>{E.stopPropagation(),ee("validated")},children:"Validar"})]})]})]})]})}const it=s.memo(nt),at=25,st=36;function lt(r){const n=new Map;for(let t=0;t<r.length;t++){const o=r[t],{x:l,y:i}=he(o),{x:
|
|
42
|
+
`}),d.jsx("button",{type:"button",className:xe,style:ot,disabled:w,onMouseDown:E=>E.stopPropagation(),onClick:E=>{E.stopPropagation(),ee("validated")},children:"Validar"})]})]})]})]})}const it=s.memo(nt),at=25,st=36;function lt(r){const n=new Map;for(let t=0;t<r.length;t++){const o=r[t],{x:l,y:i}=he(o),{x:f,y:c}=ke(l,i);let v=0;for(let h=0;h<t;h++){const{x:m,y:S}=he(r[h]),{x:w,y:L}=ke(m,S);Math.hypot(f-w,c-L)<at&&v++}n.set(o.id,{dx:v*st,dy:0})}return n}function ut(){return typeof window>"u"?"":`${window.innerWidth}x${window.innerHeight}`}function ct({apiUrl:r,apiKey:n,getPageUrl:t,reviewMode:o,setReviewMode:l,reviewers:i,comments:f,loadComments:c,commentsLoadFailed:v=!1}){const[h,m]=s.useState(null),S=s.useRef(null),[w,L]=s.useState(null),A=s.useCallback(()=>{h&&(h.style.outline="",h.style.outlineOffset="",m(null))},[h]),M=s.useCallback(()=>{S.current&&(S.current.style.outline="",S.current.style.outlineOffset="",S.current=null)},[]);s.useEffect(()=>{o||(A(),M())},[o,A,M]),s.useEffect(()=>{if(typeof document>"u")return;const b=document.body.style.cursor;return w?document.body.style.cursor="default":o&&(document.body.style.cursor="crosshair"),()=>{document.body.style.cursor=b}},[o,w]);const V=s.useCallback(b=>{var D;if(!b||typeof document>"u"||b===document.body||b===document.documentElement)return!0;const y=(D=b.tagName)==null?void 0:D.toUpperCase();return y==="BODY"||y==="HTML"?!0:b.parentElement!==document.body?!1:b.id==="root"||b.getAttribute("data-review-layer-host")!=null||document.body.children.length===1},[]),N=s.useCallback(b=>{if(!o||w)return;const y=b.target.nodeType===Node.ELEMENT_NODE?b.target:b.target.parentElement;!y||V(y)||(A(),m(y),y.style.outline="2px solid var(--ui-color-bg-fill-danger-default, #ff4d4f)",y.style.outlineOffset="2px")},[o,w,A,V]),p=s.useCallback(b=>{var D;if(w)return;const y=b.relatedTarget;h&&(!y||!h.contains(y))&&!(y&&((D=h.contains)!=null&&D.call(h,y)))&&A()},[h,w,A]),T=s.useCallback(b=>{if(!o||w)return;const y=b.target;if(!y||V(y)||y.closest("[data-review-layer-root]"))return;b.preventDefault(),b.stopPropagation(),A();const D=y;S.current=D,D.style.outline="2px solid var(--ui-color-bg-fill-danger-default, #ff4d4f)",D.style.outlineOffset="2px";const O=D.getBoundingClientRect(),ee=xr(y),{relativeX:ae,relativeY:se}=Er(O);L({position:{x:O.left+O.width/2,y:O.bottom},payload:{selector:ee,x:Math.round(O.left),y:Math.round(O.top),relativeX:ae,relativeY:se,width:Math.round(O.width),height:Math.round(O.height),url:typeof window<"u"?(t==null?void 0:t())??Ge():"/",viewport:ut(),userAgent:typeof navigator<"u"?navigator.userAgent:"",pageTitle:typeof document<"u"?document.title:""}})},[o,w,A,V]);s.useEffect(()=>{if(o)return document.addEventListener("mouseover",N,!0),document.addEventListener("mouseout",p,!0),document.addEventListener("click",T,!0),()=>{document.removeEventListener("mouseover",N,!0),document.removeEventListener("mouseout",p,!0),document.removeEventListener("click",T,!0)}},[o,N,p,T]);const[Y,R]=s.useState(0),C=s.useCallback(()=>{if(R(b=>b+1),S.current){const b=S.current.getBoundingClientRect();L(y=>y?{...y,position:{x:b.left+b.width/2,y:b.bottom}}:null)}},[]);s.useEffect(()=>{if(!(typeof window>"u"))return window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[C]),s.useEffect(()=>{if(!w||!S.current)return;const b=S.current,D=Ue(b).map(O=>(O.addEventListener("scroll",C,!0),()=>O.removeEventListener("scroll",C,!0)));return()=>D.forEach(O=>O())},[w,C]);const I=s.useMemo(()=>lt(f),[f,Y]),X=s.useCallback(()=>{M(),L(null)},[M]),H={position:"fixed",inset:0,zIndex:999999,pointerEvents:"none",cursor:o?"crosshair":void 0},K=d.jsxs(d.Fragment,{children:[d.jsx("div",{style:H,"aria-hidden":!0,"data-review-layer-root":!0}),o&&d.jsxs("div",{"data-review-layer-root":!0,style:{position:"fixed",top:"var(--ui-positive-Value_250, 10px)",left:"var(--ui-positive-Value_250, 10px)",zIndex:1e6,display:"flex",alignItems:"center",gap:"var(--ui-positive-Value_250, 10px)",padding:"var(--ui-positive-Value_150, 6px) var(--ui-positive-Value_300, 12px)",backgroundColor:"var(--ui-color-bg-fill-danger-default, #ff4d4f)",color:"var(--ui-color-text-on-color, #fff)",borderRadius:"var(--ui-radius_6, 6px)",fontSize:"var(--ui-font-size-xs, 12px)",fontWeight:"var(--ui-font-weight-medium, 500)",pointerEvents:"auto"},children:[d.jsx("span",{children:"Modo revisión (Shift+R para salir)"}),d.jsx("button",{type:"button",onClick:()=>l(!1),"aria-label":"Salir del modo revisión",style:{padding:0,margin:0,width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",border:"none",borderRadius:"var(--ui-radius_6, 6px)",backgroundColor:"rgba(255,255,255,0.2)",color:"inherit",fontSize:14,lineHeight:1,cursor:"pointer"},children:"×"})]}),v&&d.jsxs("div",{style:{position:"fixed",bottom:"var(--ui-positive-Value_400, 16px)",left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:"var(--ui-positive-Value_250, 10px)",padding:"var(--ui-positive-Value_200, 8px) var(--ui-positive-Value_350, 14px)",backgroundColor:"var(--ui-color-bg-surface-default, #fff)",border:"1px solid var(--ui-color-border-subtle, #e8e8e8)",borderRadius:"var(--ui-radius_8, 8px)",boxShadow:"0 2px 12px var(--ui-color-black-alpha-10, rgba(0,0,0,0.1))",fontSize:"var(--ui-font-size-xs, 12px)",color:"var(--ui-color-text-primary, #333)",zIndex:999997,pointerEvents:"auto"},children:[d.jsx("span",{children:"No se pudo conectar. Mostrando últimos datos guardados. Reintentar no garantiza respuesta hasta que el servicio esté activo."}),d.jsx("button",{type:"button",onClick:()=>c(),style:{padding:"var(--ui-positive-Value_100, 4px) var(--ui-positive-Value_250, 10px)",fontSize:"var(--ui-font-size-xs, 12px)",fontWeight:"var(--ui-font-weight-semibold, 600)",backgroundColor:"var(--ui-color-bg-fill-success-default, rgb(33, 196, 94))",color:"var(--ui-color-text-on-color, #fff)",border:"none",borderRadius:"var(--ui-radius_6, 6px)",cursor:"pointer"},children:"Reintentar"})]}),f.map(b=>d.jsx("div",{"data-review-layer-pin":!0,style:{pointerEvents:"auto"},children:d.jsx(it,{comment:b,offset:I.get(b.id),apiUrl:r,apiKey:n,onStatusChange:c,reviewMode:o})},b.id)),w&&d.jsx("div",{"data-review-layer-modal":!0,style:{pointerEvents:"auto"},children:d.jsx(Ar,{apiUrl:r,apiKey:n,reviewers:i,position:w.position,payload:w.payload,onClose:X,onSuccess:c})})]}),ie=typeof document<"u"?document.body:null;return ie?Me.createPortal(K,ie):null}const dt=`/**
|
|
43
43
|
* Tokens de diseño UI para review-layer-react.
|
|
44
44
|
* Las variables se inyectan en :root al montar ReviewProvider.
|
|
45
45
|
* Puedes sobrescribirlas en tu app para adaptar el tema.
|
|
@@ -364,5 +364,5 @@ React keys must be passed directly to JSX without using spread:
|
|
|
364
364
|
--ui-shadow-popover: 0 var(--ui-shadow-02-y) var(--ui-shadow-02-blur) var(--ui-shadow-02-Color);
|
|
365
365
|
--ui-shadow-modal: 0 var(--ui-shadow-04-y) var(--ui-shadow-04-blur) var(--ui-shadow-04-Color);
|
|
366
366
|
}
|
|
367
|
-
`;function ft(r,n,t){const o=s.useCallback(()=>{r&&t(l=>!l)},[r,t]);s.useEffect(()=>{if(!r)return;const l=i=>{(i.key==="r"||i.key==="R"||i.code==="KeyR")&&i.shiftKey&&!i.ctrlKey&&!i.metaKey&&(i.preventDefault(),o())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r,o])}const vt="review_layer:v1:";function pt(r,n){if(r==null)return n;try{return JSON.parse(r)??n}catch{return n}}function ne(r,n,t,o){const l=`${vt}${gt(r)}:${t}`;return o!=null?`${l}:${o}`:l}function gt(r){return r.replace(/\/+$/,"")||"/"}function me(r){if(typeof localStorage>"u")return null;const n=localStorage.getItem(r);return pt(n,null)}function qe(r,n){if(!(typeof localStorage>"u"))try{localStorage.setItem(r,JSON.stringify({data:n,at:Date.now()}))}catch{}}function Pe(r,n,t){const o=me(ne(r,n,"comments",t));return(o==null?void 0:o.data)??null}function ht(r,n,t,o){qe(ne(r,n,"comments",t),o)}function je(r,n){const t=me(ne(r,n,"reviewers"));return(t==null?void 0:t.data)??null}function bt(r,n,t){qe(ne(r,n,"reviewers"),t)}function yt(r,n,t){const o=me(ne(r,n,"comments",t));return(o==null?void 0:o.at)??null}function xt(r,n){const t=me(ne(r,n,"reviewers"));return(t==null?void 0:t.at)??null}const $e="https://review-layer-api.onrender.com/api",er=s.createContext(null);let Ve=null;function mt(){const r=s.useContext(er);if(!r)throw new Error("useReview must be used within ReviewProvider");return r}const W="[review-layer]",rr=2500;function wt({children:r,enabled:n=!0,apiUrl:t,apiKey:o,getPageUrl:l}){const i=(t==null?void 0:t.trim())||$e,[c
|
|
367
|
+
`;function ft(r,n,t){const o=s.useCallback(()=>{r&&t(l=>!l)},[r,t]);s.useEffect(()=>{if(!r)return;const l=i=>{(i.key==="r"||i.key==="R"||i.code==="KeyR")&&i.shiftKey&&!i.ctrlKey&&!i.metaKey&&(i.preventDefault(),o())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r,o])}const vt="review_layer:v1:";function pt(r,n){if(r==null)return n;try{return JSON.parse(r)??n}catch{return n}}function ne(r,n,t,o){const l=`${vt}${gt(r)}:${t}`;return o!=null?`${l}:${o}`:l}function gt(r){return r.replace(/\/+$/,"")||"/"}function me(r){if(typeof localStorage>"u")return null;const n=localStorage.getItem(r);return pt(n,null)}function qe(r,n){if(!(typeof localStorage>"u"))try{localStorage.setItem(r,JSON.stringify({data:n,at:Date.now()}))}catch{}}function Pe(r,n,t){const o=me(ne(r,n,"comments",t));return(o==null?void 0:o.data)??null}function ht(r,n,t,o){qe(ne(r,n,"comments",t),o)}function je(r,n){const t=me(ne(r,n,"reviewers"));return(t==null?void 0:t.data)??null}function bt(r,n,t){qe(ne(r,n,"reviewers"),t)}function yt(r,n,t){const o=me(ne(r,n,"comments",t));return(o==null?void 0:o.at)??null}function xt(r,n){const t=me(ne(r,n,"reviewers"));return(t==null?void 0:t.at)??null}const $e="https://review-layer-api.onrender.com/api",er=s.createContext(null);let Ve=null;function mt(){const r=s.useContext(er);if(!r)throw new Error("useReview must be used within ReviewProvider");return r}const W="[review-layer]",rr=2500;function wt({children:r,enabled:n=!0,apiUrl:t,apiKey:o,getPageUrl:l}){const i=(t==null?void 0:t.trim())||$e,[f,c]=s.useState(!1),[v,h]=s.useState([]),[m,S]=s.useState([]),[w,L]=s.useState(!1),A=s.useRef(!1),M=s.useRef(null),V=s.useCallback(()=>(l==null?void 0:l())??Ge(),[l]);ft(n,f,c);const N=s.useCallback(async R=>{if(!n||!i||!o){console.warn(W,"loadReviewers omitido: faltan enabled, apiUrl o apiKey",{enabled:n,apiUrl:i,hasApiKey:!!o});return}const C=xt(i,o);if(C!=null&&Date.now()-C<rr){const I=je(i,o);if(I!=null){h(I);return}}if(!A.current){A.current=!0,console.log(W,"Cargando revisores...",{apiUrl:i});try{const I=await Sr(i,o,{signal:R});R!=null&&R.aborted||(h(I),bt(i,o,I),console.log(W,"Revisores cargados:",I.length))}catch(I){if(I instanceof Error&&I.name==="AbortError")return;if(!(R!=null&&R.aborted)){console.error(W,"Error al cargar revisores:",I);const X=je(i,o);X!=null&&(h(X),console.log(W,"Usando revisores en caché:",X.length))}}finally{A.current=!1}}},[n,i,o]),p=s.useCallback(async R=>{if(!n||!i||!o){console.warn(W,"loadComments omitido: faltan enabled, apiUrl o apiKey",{enabled:n,apiUrl:i,hasApiKey:!!o});return}const C=V(),I=Pe(i,o,C);I!=null&&S(I);const X=yt(i,o,C);if(!(X!=null&&Date.now()-X<rr&&I!=null)&&M.current!==C){M.current=C,console.log(W,"Cargando comentarios...",{apiUrl:i,url:C});try{L(!1);const H=await Tr(i,o,C,{signal:R});R!=null&&R.aborted||(S(H),ht(i,o,C,H),console.log(W,"Comentarios cargados:",H.length))}catch(H){if(H instanceof Error&&H.name==="AbortError")return;if(!(R!=null&&R.aborted)){L(!0),console.error(W,"Error al cargar comentarios:",H);const K=Pe(i,o,C);K!=null?(S(K),console.log(W,"Usando comentarios en caché:",K.length)):console.warn(W,"Sin caché de comentarios; la lista quedará vacía hasta que la API responda.")}}finally{M.current=null}}},[n,i,o,V]);s.useEffect(()=>{if(!n||!i||!o){console.warn(W,"Provider activo pero sin carga: enabled, apiUrl y apiKey son requeridos.",{enabled:n,apiUrl:i,hasApiKey:!!o});return}const R=V(),C=je(i,o),I=Pe(i,o,R);C!=null&&(h(C),console.log(W,"Revisores desde caché (inicial):",C.length)),I!=null&&(S(I),console.log(W,"Comentarios desde caché (inicial):",I.length,{url:R}))},[n,i,o,V]),s.useEffect(()=>{if(typeof document>"u")return;const R="review-layer-ui-variables";if(!document.getElementById(R)){const C=document.createElement("style");C.id=R,C.textContent=dt,document.head.appendChild(C)}},[]),s.useEffect(()=>{if(!n||!i||!o)return;const R=`${i}:${o}`;if(Ve!==R)return Ve=R,console.log(W,"Inicio de carga (revisores + comentarios)",{apiUrl:i,apiKey:o?"***":"(vacío)"}),N(),p(),()=>{setTimeout(()=>{Ve=null},0)}},[n,i,o,N,p]),s.useEffect(()=>{if(!n)return;const R=()=>p();return window.addEventListener("popstate",R),()=>window.removeEventListener("popstate",R)},[n,p]);const T=s.useMemo(()=>({apiUrl:i,apiKey:o,reviewMode:f,setReviewMode:c,reviewers:v,comments:m,loadComments:p,commentsLoadFailed:w}),[i,o,f,c,v,m,p,w]),Y=n&&typeof document<"u"?Me.createPortal(d.jsx(ct,{apiUrl:i,apiKey:o,getPageUrl:V,reviewMode:f,setReviewMode:c,reviewers:v,comments:m,loadComments:p,commentsLoadFailed:w}),document.body):null;return d.jsxs(er.Provider,{value:T,children:[r,Y]})}Z.DEFAULT_API_URL=$e,Z.ReviewProvider=wt,Z.useReview=mt,Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"})});
|
|
368
368
|
//# sourceMappingURL=review-layer-react.umd.cjs.map
|