use-chisel 0.1.10 → 0.1.12

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,6 +1,6 @@
1
- "use client";import{forwardRef as Ze,createElement as Je}from"react";var xe=e=>e?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Ce(e,a,o=[]){if(a==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:xe(e),size:24,node:a,...o.length>0?{aliases:o}:{}}}var he=e=>{let a="",o=!1;for(let t of e){if(t==="-"||t==="_"||t<=" "){o=a.length>0;continue}a.length===0?a+=t.toLowerCase():a+=o?t.toUpperCase():t,o=!1}return a};var ge=e=>{let a=he(e);return a.charAt(0).toUpperCase()+a.slice(1)};import{forwardRef as Ke,createElement as ye}from"react";var G=(...e)=>e.filter((a,o,t)=>!!a&&a.trim()!==""&&t.indexOf(a)===o).join(" ").trim();var v={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function de(e){return e!=null}function Se(e,a={}){let o=a.attributeNames??{},t=d=>o[d]??d,l=e.size??e.width??v.width,u=e.size??e.height??v.height,r=e.aliases?.filter(d=>typeof d=="string"&&d.trim()!=="").map(d=>`lucide-${d}`)??[],c=[...e.name?[`lucide-${e.name}`]:[],...r],i=a.className?.split(" ").filter(Boolean)??[],L=a.includeDefaultClasses===!1?G(...i):G("lucide",...c,...i),s=a.absoluteStrokeWidth?Number(a.strokeWidth??v["stroke-width"])*Number(e.size??e.width??v.width)/Number(a.size??a.width??v.width):a.strokeWidth??v["stroke-width"];return["svg",{...Object.entries(v).reduce((d,[f,n])=>(d[t(f)]=n,d),{}),..."color"in a&&a.color&&{[t("stroke")]:a.color},..."size"in a&&de(a.size)&&{[t("width")]:a.size,[t("height")]:a.size},..."width"in a&&de(a.width)&&{[t("width")]:a.width},..."height"in a&&de(a.height)&&{[t("height")]:a.height},[t("stroke-width")]:s,...L&&{[t("class")]:L},[t("viewBox")]:`0 0 ${l} ${u}`,...a.hasA11yProp===!1?{[t("aria-hidden")]:"true"}:{},..."attributes"in a&&a.attributes},e.node.map(d=>{let[f,n,x]=d,h=a.nonScalingStroke?{[t("vector-effect")]:"non-scaling-stroke",...n}:n;return x?[f,h,x]:[f,h]})]}function ke(e,a={}){return Se(e,{...a,attributeNames:{...a.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var we=e=>{for(let a in e)if(a.startsWith("aria-")||a==="role"||a==="title")return!0;return!1};import{createContext as ze,useContext as Ne,useMemo as Va,createElement as za}from"react";var Xe=ze({});var Pe=()=>Ne(Xe);var Ae=Ke(({color:e,size:a,width:o,height:t,strokeWidth:l,absoluteStrokeWidth:u,nonScalingStroke:r,className:c="",children:i,iconNode:L=[],icon:s={node:L,aliases:[],size:24},...m},d)=>{let{size:f=24,strokeWidth:n=2,absoluteStrokeWidth:x=!1,nonScalingStroke:h=!1,color:R="currentColor",className:S=""}=Pe()??{},F=!!i||we(m),[ae,te,I=[]]=ke(s,{color:e??R,width:o??a??f,height:t??a??f,strokeWidth:l??n,absoluteStrokeWidth:u??x,nonScalingStroke:r??h,className:G(S,c),hasA11yProp:F,attributes:m});return ye(ae,{ref:d,...te},[...I.map(([g,b])=>ye(g,b)),...Array.isArray(i)?i:[i]])});function k(e,a=[],o=[]){let t=typeof e=="string"?Ce(e,a,o):e,l=Ze(({className:u,...r},c)=>Je(Ae,{ref:c,icon:t,className:u,...r}));return t.name&&(l.displayName=ge(t.name)),l}var Qe={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]},W=k(Qe);var $e={name:"download",size:24,node:[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]},V=k($e);var _e={name:"paperclip",size:24,node:[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]},z=k(_e);var je={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]},N=k(je);var Ye={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]},X=k(Ye);var ea={name:"rotate-cw",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]},K=k(ea);var aa={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]},q=k(aa);import{useEffect as U,useRef as y,useState as Q}from"react";function D(e){return{version:1,content:e.split(`
2
- `).map(a=>({type:"paragraph",children:[{text:a}]}))}}function $(e){return e.content.map(a=>a.children.map(o=>"type"in o?o.text||o.url:o.text).join("")).join(`
3
- `)}function _(e){let a=e.content.slice();for(;a.length;){let o=a[a.length-1],t=o.children.slice();for(;t.length;){let l=t[t.length-1],u="type"in l?l.text||l.url:l.text,r=u.trimEnd();if(r)return t[t.length-1]=r===u?l:{...l,text:r},a[a.length-1]={...o,children:t},{...e,content:a};t.pop()}a.pop()}return D("")}function le(e){try{let a=JSON.parse(localStorage.getItem(e)??"null");return a?.version===1&&Date.now()-a.time<7*864e5?a.value:null}catch{return null}}function H(e,a){try{return a===null?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify({version:1,time:Date.now(),value:a})),!0}catch{return!1}}function re(e,a,o){let t=e;for(let l of[...a].sort((u,r)=>u-r))if(!(l<=t)){if(!o.has(l))break;t=l}return t}var j=["image/jpeg","image/png","image/gif","image/webp","image/avif","image/bmp"],Be=["video/mp4","video/webm","video/quicktime"],De=[...j,...Be].join(",");function Me(e){let a=j.includes(e.type);return!a&&!Be.includes(e.type)?"Choose a JPG, PNG, GIF, WebP, AVIF, BMP, MP4, WebM, or MOV file.":!Number.isSafeInteger(e.size)||e.size<=0?"This file is empty or invalid.":e.size>(a?5242880:20971520)?`${a?"Images must be 5 MB":"Videos must be 20 MB"} or smaller.`:null}import{useEffect as ta,useRef as Re,useState as be}from"react";import{createEditor as oa,Editor as C,Element as E,Node as ua,Path as da,Range as se,Transforms as M}from"slate";import{withHistory as la}from"slate-history";import{Editable as ra,Slate as sa,withReact as fa,ReactEditor as Fe}from"slate-react";import{Fragment as qe,jsx as w,jsxs as Ue}from"react/jsx-runtime";function fe(e){return e.content.length?e.content.map(a=>({type:"paragraph",children:a.children.length?a.children.map(o=>"type"in o&&o.type==="link"?{type:"link",url:o.url,children:[{text:o.text||o.url}]}:{...o}):[{text:""}]})):[{type:"paragraph",children:[{text:""}]}]}function ve(e){return{version:1,content:e.map(a=>({type:"paragraph",children:E.isElement(a)?a.children.map(o=>E.isElement(o)?{type:"link",url:o.url,text:ua.string(o)}:{...o}):[{text:a.text}]}))}}function ie(e){return/^(https?:\/\/|mailto:)[^\s]+$/i.test(e)}function ia(e,a){if(!e.selection){let o=window.getSelection(),t=o&&Fe.toSlateRange(e,o,{exactMatch:!1,suppressThrow:!0});M.select(e,t??C.end(e,[]))}C.marks(e)?.[a]?C.removeMark(e,a):C.addMark(e,a,!0)}function Te(){let e=fa(la(oa()),"application/x-chisel-review-fragment"),{isInline:a,insertText:o,insertData:t,insertBreak:l}=e;e.isInline=c=>c.type==="link"||a(c);function u(c,i){C.above(e,{at:c,match:L=>E.isElement(L)&&L.type==="link"})||(M.wrapNodes(e,{type:"link",url:i,children:[]},{at:c,split:!0}),M.collapse(e,{edge:"end"}))}function r(){if(!e.selection||!se.isCollapsed(e.selection))return;let c=C.above(e,{match:d=>E.isElement(d)&&d.type==="paragraph"});if(!c)return;let i=e.selection.anchor,s=C.string(e,{anchor:C.start(e,c[1]),focus:i}).match(/\S+$/)?.[0];if(!s||!ie(s))return;let m=C.before(e,i,{distance:s.length,unit:"offset"});if(m){u({anchor:m,focus:i},s);let d=C.above(e,{match:f=>E.isElement(f)&&f.type==="link"});d&&e.selection&&C.isEnd(e,e.selection.anchor,d[1])&&M.select(e,C.start(e,da.next(d[1])))}}return e.insertText=c=>{if(Fe.isComposing(e)){o(c);return}c===" "&&r();let i={"*":"bold",_:"italic","~":"strikethrough","`":"code"}[c];if(i&&e.selection&&se.isCollapsed(e.selection)){let L=C.above(e,{match:s=>E.isElement(s)&&s.type==="paragraph"});if(L){let s=e.selection.anchor,m=C.string(e,{anchor:C.start(e,L[1]),focus:s}),d=m.lastIndexOf(c),f=m.slice(d+1);if(d>=0&&(!d||/[\s*_~`]/.test(m[d-1]))&&f&&f.trim()===f){let n=C.before(e,s,{distance:f.length,unit:"offset"}),x=n&&C.before(e,n,{unit:"offset"});if(n&&x){M.select(e,{anchor:n,focus:s}),C.addMark(e,i,!0),M.collapse(e,{edge:"end"}),M.delete(e,{at:{anchor:x,focus:n}}),C.removeMark(e,i);return}}}}o(c)},e.insertBreak=()=>{r(),l()},e.insertData=c=>{let i=c.getData("text/plain");ie(i)?e.selection&&!se.isCollapsed(e.selection)?u(e.selection,i):M.insertNodes(e,[{type:"link",url:i,children:[{text:i}]},{text:""}]):t(c)},e}function ca({attributes:e,children:a,element:o}){return o.type==="link"?w("a",{...e,href:ie(o.url)?o.url:void 0,onClick:t=>t.preventDefault(),children:a}):w("p",{...e,children:a})}function na({attributes:e,children:a,leaf:o}){let t=w(qe,{children:a});return o.bold&&(t=w("strong",{children:t})),o.italic&&(t=w("em",{children:t})),o.strikethrough&&(t=w("s",{children:t})),o.code&&(t=w("code",{children:t})),w("span",{...e,children:t})}function Z({onFiles:e,disabled:a}){let o=Re(null);return Ue(qe,{children:[w("input",{ref:o,type:"file",accept:De,multiple:!0,hidden:!0,onChange:t=>{e(t.target.files),t.target.value=""}}),w("button",{type:"button",className:"review-retry-upload","aria-label":"Attach image or video",title:"Images up to 5 MB \xB7 Videos up to 20 MB",disabled:a,onClick:()=>o.current?.click(),children:w(z,{size:16,strokeWidth:1.75})})]})}function J({text:e,defaultBody:a,disabled:o,label:t,placeholder:l,autoFocus:u,onChange:r,onSubmit:c,onFiles:i,uploading:L}){let[s]=be(Te),[m]=be(()=>fe(a??D(e))),d=Re(e);return ta(()=>{if(e===d.current)return;let f=d.current;d.current=e,f&&e.startsWith(f)?M.insertText(s,e.slice(f.length),{at:C.end(s,[])}):(C.withoutNormalizing(s,()=>{M.removeNodes(s,{at:[],match:(n,x)=>x.length===1}),M.insertNodes(s,fe(D(e)),{at:[0]}),M.deselect(s)}),e||(s.history={undos:[],redos:[]}))},[s,e]),Ue(sa,{editor:s,initialValue:m,onChange:f=>{if(!s.operations.some(x=>x.type!=="set_selection"))return;let n=ve(f);d.current=$(n),r(d.current,n)},children:[w(ra,{className:"review-composer-editor",role:"textbox","aria-multiline":"true","aria-label":t,placeholder:l,readOnly:o,autoFocus:u,renderElement:ca,renderLeaf:na,onKeyDown:f=>{if(f.nativeEvent.isComposing)return;let n=f.metaKey||f.ctrlKey;if(f.key==="Enter"){f.preventDefault(),n?s.insertBreak():c();return}let x=n?{b:"bold",i:"italic",e:"code",...f.shiftKey?{s:"strikethrough"}:{}}[f.key.toLowerCase()]:void 0;x&&(f.preventDefault(),ia(s,x))}}),i&&w("div",{className:"chisel-attachment-controls",children:w(Z,{onFiles:i,disabled:o||L})})]})}import{useEffect as pa,useRef as ma,useState as La}from"react";import{Fragment as Oe,jsx as P,jsxs as Y}from"react/jsx-runtime";function Ia({src:e,name:a,mimeType:o,onError:t,close:l}){let u=ma(null);return pa(()=>{u.current?.showModal()},[]),P("dialog",{ref:u,className:"review-media-lightbox","aria-label":`Preview ${a}`,onCancel:r=>{r.preventDefault(),l()},onClick:r=>{r.target===r.currentTarget&&l()},children:Y("div",{className:"review-media-lightbox-content",children:[Y("header",{children:[P("span",{children:a}),P("a",{href:e,download:a,"aria-label":`Download ${a}`,title:"Download",children:P(V,{size:20,"aria-hidden":"true"})}),P("button",{type:"button","aria-label":"Close preview",onClick:l,children:P(q,{size:20})})]}),o.startsWith("image/")?P("img",{src:e,alt:a,onError:t}):P("video",{src:e,controls:!0,autoPlay:!0,playsInline:!0,"aria-label":a,onError:t})]})})}function ee({src:e,name:a,mimeType:o,onError:t}){let[l,u]=La(!1);return Y(Oe,{children:[P("button",{type:"button",className:"review-media-thumbnail","aria-label":`Preview ${a}`,onClick:()=>u(!0),children:o.startsWith("image/")?P("img",{src:e,alt:a,loading:"lazy",onError:t}):Y(Oe,{children:[P("video",{src:e,muted:!0,playsInline:!0,preload:"metadata","aria-hidden":"true",onError:t}),P("span",{className:"review-media-play","aria-hidden":"true",children:P(X,{size:20,fill:"currentColor"})})]})}),l&&P(Ia,{src:e,name:a,mimeType:o,onError:t,close:()=>u(!1)})]})}import{Fragment as ka,jsx as p,jsxs as A}from"react/jsx-runtime";function ce(e,a,o){if(e)try{let t=le(e);if(t?.text===a&&$(t.body)===a)return t.body}catch{}return o??D(a)}function ne(e,a,o,t=!1){e&&H(e,t||a.trim()?{text:a,body:o}:null)}function He({body:e}){return p("div",{className:"review-comment-body",children:e.content.map((a,o)=>p("p",{children:a.children.map((t,l)=>{if("type"in t&&t.type==="link")return p("a",{href:/^(https?:|mailto:)/i.test(t.url)?t.url:void 0,target:"_blank",rel:"noopener noreferrer",children:t.text||t.url},l);if(!("text"in t))return null;let u=p(ka,{children:t.text});return"bold"in t&&t.bold&&(u=p("strong",{children:u})),"italic"in t&&t.italic&&(u=p("em",{children:u})),"strikethrough"in t&&t.strikethrough&&(u=p("s",{children:u})),"code"in t&&t.code&&(u=p("code",{children:u})),p("span",{children:u},l)})},o))})}function xa({attachment:e,loadMedia:a}){let[o,t]=Q(e.previewUrl??""),[l,u]=Q(!1),[r,c]=Q(0),i=y(0);U(()=>{if(e.previewUrl){t(e.previewUrl);return}t("");let s=!0,m=!1,d=new AbortController;async function f(){if(!(m||document.visibilityState==="hidden")){m=!0;try{let h=await a(e.id,d.signal);s&&(t(h),u(!1),i.current=Date.now()+240*1e3)}catch{s&&u(!0)}finally{m=!1}}}function n(){Date.now()>=i.current&&f()}f();let x=window.setInterval(n,60*1e3);return window.addEventListener("focus",n),document.addEventListener("visibilitychange",n),()=>{s=!1,d.abort(),window.clearInterval(x),window.removeEventListener("focus",n),document.removeEventListener("visibilitychange",n)}},[e.id,e.previewUrl,r,a]);function L(){u(!0),Date.now()>=i.current&&c(s=>s+1)}return A("figure",{className:"review-attachment",children:[o&&!l?p(ee,{src:o,name:e.name,mimeType:e.mimeType,onError:L}):p("div",{className:"review-attachment-placeholder",role:"status",children:l?p("button",{type:"button",className:"review-retry-upload",onClick:()=>c(s=>s+1),children:"Retry attachment"}):"Loading attachment\u2026"}),p("figcaption",{children:e.name})]})}function Ee(e){let a=Math.max(0,Math.floor((Date.now()-Date.parse(e))/6e4));return a<1?"Just now":a<60?`${a}m`:a<1440?`${Math.floor(a/60)}h`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Ca({comment:e,activity:a,loadMedia:o,editable:t,editing:l,saving:u,onStartEdit:r,onCancelEdit:c,onSaveEdit:i,onDraftChange:L,onEditStyles:s,draftKey:m}){let[d,f]=Q(e.text),n=y(e.body??D(e.text)),x=y(!1),h=y(!1);U(()=>{l?L(d!==e.text||JSON.stringify(n.current)!==JSON.stringify(e.body??D(e.text))):h.current&&m&&H(m,null),h.current=l},[l]),U(()=>{l||(f(e.text),n.current=e.body??D(e.text))},[l,e.text,e.body]);async function R(){if(!(u||x.current||!d.trim()&&!e.attachments?.length)){x.current=!0;try{await i(d.trimEnd(),_(n.current))&&(m&&H(m,null),L(!1))}finally{x.current=!1}}}return A("article",{className:"review-comment","data-activity":a,children:[p("span",{className:"review-comment-avatar",children:e.authorImage?p("img",{src:e.authorImage,alt:""}):e.author.slice(0,1).toUpperCase()}),A("div",{className:"review-comment-content",children:[A("header",{className:"review-comment-header",children:[p("span",{className:"review-comment-author",children:e.author}),e.pending?p("span",{className:"review-comment-time",role:"status",children:"Sending\u2026"}):p("time",{className:"review-comment-time",dateTime:e.date,title:new Date(e.date).toLocaleString(),children:Ee(e.date)}),t&&!l&&p("button",{type:"button",className:"review-comment-edit","aria-label":"Edit comment",title:"Edit comment",disabled:u,onClick:()=>{let S=m?le(m):null;S&&typeof S.text=="string"&&(f(S.text),n.current=ce(m,S.text)),r()},children:p(N,{size:16})})]}),l?A("form",{className:"review-inline-edit",onSubmit:S=>{S.preventDefault(),R()},children:[p(J,{text:d,defaultBody:n.current,disabled:u,label:"Edit comment",placeholder:"Edit comment\u2026",autoFocus:!0,onSubmit:()=>{R()},onChange:(S,F)=>{f(S),n.current=F,ne(m,S,F,!0),L(S!==e.text||JSON.stringify(F)!==JSON.stringify(e.body??D(e.text)))}}),A("div",{className:"review-inline-edit-actions",children:[s&&p("button",{type:"button",disabled:u,onClick:s,children:"Edit styles"}),p("button",{type:"button",disabled:u,onClick:c,children:"Cancel"}),p("button",{type:"submit",disabled:u||!d.trim()&&!e.attachments?.length,children:"Save"})]})]}):p(He,{body:e.body??D(e.text)}),e.attachments?.length>0&&p("div",{className:"review-attachments",children:e.attachments.map(S=>p(xa,{attachment:S,loadMedia:o},S.id))})]})]})}function ha(e){let a=e.useAttachments(e.disabled,e.existingAttachments?.length??0),o=y(ce(e.draftKey,e.text,e.defaultBody)),t=y(!1);U(()=>(e.onAttachmentDraftChange?.(a.uploading||a.attachments.length>0),()=>e.onAttachmentDraftChange?.(!1)),[a.uploading,a.attachments.length,e.onAttachmentDraftChange]);async function l(){if(!(e.disabled||a.blocked||t.current||!e.text.trim()&&!a.attachments.length&&!e.existingAttachments?.length)){t.current=!0;try{await e.onSubmit(e.text.trimEnd(),_(o.current),a.tokens,a.previews)&&(e.draftKey&&H(e.draftKey,null),a.clear())}finally{t.current=!1}}}return p("form",{className:"review-composer chisel-review-composer","aria-label":e.commentId?"Edit comment":"New comment",onSubmit:u=>{u.preventDefault(),l()},onPasteCapture:u=>{u.clipboardData.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.clipboardData.files))},onDragOver:u=>{u.dataTransfer.types.includes("Files")&&u.preventDefault()},onDropCapture:u=>{u.dataTransfer.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.dataTransfer.files))},children:e.renderContent(A("div",{className:"chisel-composer-input",children:[p(J,{text:e.text,defaultBody:o.current,disabled:e.disabled,label:"Comment",placeholder:"Leave a comment\u2026",autoFocus:!0,onSubmit:()=>{l()},onChange:(u,r)=>{o.current=r,ne(e.draftKey,u,r),e.onText(u)}}),a.previewsUI,a.controls]}),a.attachments.length>0||!!e.existingAttachments?.length,a.blocked,p(Z,{onFiles:a.upload,disabled:e.disabled||a.uploading}))})}function ga(e){let a=e.useAttachments(e.saving),o=y(ce(e.draftKey,e.reply)),t=y(!1);U(()=>(e.onAttachmentDraftChange?.(a.uploading||a.attachments.length>0),()=>e.onAttachmentDraftChange?.(!1)),[a.uploading,a.attachments.length,e.onAttachmentDraftChange]);async function l(){if(!(e.saving||a.blocked||t.current||!e.reply.trim()&&!a.attachments.length)){t.current=!0;try{await e.onReply(e.reply.trimEnd(),_(o.current),a.tokens,a.previews)&&(e.draftKey&&H(e.draftKey,null),o.current=D(""),a.clear())}finally{t.current=!1}}}return A("form",{className:"review-composer chisel-review-reply","aria-label":"Reply to thread",hidden:e.submittingReply,onSubmit:u=>{u.preventDefault(),l()},onPasteCapture:u=>{u.clipboardData.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.clipboardData.files))},onDragOver:u=>{u.dataTransfer.types.includes("Files")&&u.preventDefault()},onDropCapture:u=>{u.dataTransfer.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.dataTransfer.files))},children:[p("span",{className:"feedback-avatar feedback-reply-avatar",children:e.replyAuthor?.image?p("img",{src:e.replyAuthor.image,alt:""}):(e.replyAuthor?.name||"You").slice(0,1).toUpperCase()}),A("div",{className:"chisel-reply-field",children:[p(J,{text:e.reply,defaultBody:o.current,disabled:e.saving,label:"Reply",placeholder:"Write a reply\u2026",onSubmit:()=>{l()},onChange:(u,r)=>{o.current=r,ne(e.draftKey,u,r),e.onReplyText(u)}}),a.previewsUI,a.controls,p("div",{className:"chisel-attachment-controls",children:p(Z,{onFiles:a.upload,disabled:e.saving||a.uploading})}),p("button",{type:"submit",className:"chisel-reply-submit","aria-label":"Reply",disabled:e.saving||a.blocked||!e.reply.trim()&&!a.attachments.length,children:p(W,{size:16,strokeWidth:1.75})})]})]})}function Sa(e){let a=e.comment,[o,t]=Q(null),l=y(!1),u=y(e.onEditDraftChange);u.current=e.onEditDraftChange,U(()=>()=>{u.current?.(!1)},[]);function r(d){l.current=d,e.onEditDraftChange?.(d)}async function c(d){d&&e.onBeginEdit&&!await e.onBeginEdit()||!d&&l.current&&e.onDiscardEdit&&!await e.onDiscardEdit()||(r(!1),t(d))}function i(d,f){return p(Ca,{draftKey:e.draftKey?`${e.draftKey}:edit:${d.id}`:void 0,comment:d,activity:f?a.rootActivity:d.activity,loadMedia:e.loadMedia,editable:!!(e.expanded&&e.onEdit&&e.userId&&d.authorId===e.userId&&!d.pending),editing:o===d.id,saving:e.saving,onEditStyles:f?e.onEditStyles:void 0,onStartEdit:()=>{c(d.id)},onCancelEdit:()=>{c(null)},onDraftChange:r,onSaveEdit:async(n,x)=>{let h=await e.onEdit?.(f?null:d.id,n,x);return h&&(r(!1),t(null)),!!h}},d.id)}let L=y(null),s=y(new Set),m=y(a.readActivity??0);return U(()=>{if(!e.expanded||!L.current||a.pending||a.readActivity===null)return;let d=[a.rootActivity,...a.replies.map(x=>x.activity)],f=new IntersectionObserver(x=>{if(document.visibilityState!=="visible")return;for(let R of x)R.isIntersecting&&R.intersectionRatio>0&&s.current.add(Number(R.target.dataset.activity));let h=re(Math.max(m.current,a.readActivity??0),d,s.current);h>m.current&&(m.current=h,e.onRead(a.id,h))},{threshold:0});function n(){if(f.disconnect(),document.visibilityState==="visible")for(let x of L.current?.querySelectorAll("[data-activity]")??[])f.observe(x)}return n(),document.addEventListener("visibilitychange",n),()=>{f.disconnect(),document.removeEventListener("visibilitychange",n)}},[a,e.expanded,e.onRead]),A("div",{className:"chisel-review-thread-content",children:[e.expanded&&a.context&&A("p",{className:"review-capture-context",children:[a.context.width," \xD7 ",a.context.height,"px \xB7 ",a.breakpoint??"desktop",a.context.deployment?` \xB7 ${a.context.deployment}`:"",A("time",{dateTime:a.context.capturedAt,title:new Date(a.context.capturedAt).toLocaleString(),children:[" \xB7 ",Ee(a.context.capturedAt)]})]}),A("div",{ref:L,className:"review-thread",children:[i(a,!0),e.expanded&&a.replies.map(d=>i(d,!1))]}),e.expanded?!o&&p(ga,{...e}):p("button",{type:"button",className:"chisel-expand-thread",onClick:e.onExpand,children:a.replies.length?`${a.replies.length} ${a.replies.length===1?"reply":"replies"}`:"Reply\u2026"})]})}import{useCallback as Ge,useRef as We}from"react";function wa(e,a){let o=We(new Map),t=We(!1),l=Ge(async()=>{if(!t.current){t.current=!0;try{for(;o.current.size;){let[r,c]=o.current.entries().next().value;try{await e(r,c)}catch(i){if([400,403,404].includes(i.status??0)){o.current.delete(r);continue}throw i}o.current.get(r)===c&&o.current.delete(r),a(r,c)}}catch{}finally{t.current=!1}}},[e,a]),u=Ge((r,c)=>{o.current.set(r,Math.max(c,o.current.get(r)??0)),l()},[l]);return{flush:l,markDisplayed:u}}import{useEffect as Pa,useRef as pe,useState as me}from"react";import{jsx as T,jsxs as Le}from"react/jsx-runtime";function ya(e=!1,a=0,o){let[t,l]=me([]),[u,r]=me(!1),[c,i]=me(""),L=pe(!0),s=pe(!1),m=pe(new Map),d=I=>o.discard(I);Pa(()=>(L.current=!0,()=>{L.current=!1;for(let I of m.current.values())URL.revokeObjectURL(I.preview),d(I).catch(()=>{})}),[]);function f(){L.current&&l([...m.current.values()].map(I=>({...I})))}function n(){for(let I of m.current.values())URL.revokeObjectURL(I.preview);m.current.clear(),L.current&&(l([]),i(""))}async function x(I){let g=m.current.get(I);if(!(!g||s.current||e)){s.current=!0,r(!0);try{await d(g),m.current.delete(I),URL.revokeObjectURL(g.preview),f(),i("")}catch(b){L.current&&i(b instanceof Error?b.message:"The attachment could not be removed.")}finally{s.current=!1,L.current&&r(!1)}}}async function h(I){for(let g of I){if(!L.current)return;let b=g.status==="failed";g.status="uploading",f();try{g.token=await o.send(g,b,()=>L.current),g.status="ready"}catch(B){g.status="failed",L.current&&i(B instanceof Error?B.message:"The upload failed. Your comment is still here.")}finally{L.current||await d(g).catch(()=>{})}f()}}async function R(I){if(!I?.length||s.current||e)return;let g=Array.from(I),b=g.map(B=>Me(B)).find(Boolean);if(b){i(b);return}if(a+m.current.size+g.length>20){i("Attach up to 20 files per comment.");return}s.current=!0,r(!0),i("");try{let B=await o.userId();if(!B)throw new Error("Sign in again to attach files.");if(!L.current)return;let oe=g.map(O=>{let ue=crypto.randomUUID(),Ie={id:ue,name:O.name,mimeType:O.type,size:O.size,file:O,bucket:j.includes(O.type)?"chisel-review-images":"chisel-review-videos",path:`${B}/${ue}`,preview:URL.createObjectURL(O),stored:!1,status:"uploading"};return m.current.set(ue,Ie),Ie});f(),await h(oe)}catch(B){L.current&&i(B instanceof Error?B.message:"The upload failed. Your comment is still here.")}finally{s.current=!1,L.current&&r(!1)}}async function S(){if(!(s.current||e)){s.current=!0,r(!0),i("");try{await h([...m.current.values()].filter(I=>I.status==="failed"))}finally{s.current=!1,L.current&&r(!1)}}}let F=t.some(I=>I.status==="failed"),ae=Le("div",{className:"chisel-attachment-controls",children:[u&&T("span",{role:"status",children:"Uploading\u2026"}),F&&Le("button",{type:"button",className:"review-retry-upload",disabled:u||e,onClick:()=>{S()},children:[T(K,{size:16,strokeWidth:1.75}),"Retry upload"]}),c&&T("span",{className:"chisel-attachment-error",role:"alert",children:c})]}),te=t.length>0&&T("div",{className:"chisel-attachment-previews",children:t.map(I=>Le("div",{className:"chisel-attachment-preview","data-state":I.status,children:[T(ee,{src:I.preview,name:I.name,mimeType:I.mimeType}),T("span",{title:I.name,children:I.name}),T("button",{type:"button","aria-label":`Remove ${I.name}`,disabled:u||e,onClick:()=>{x(I.id)},children:T(q,{size:16,strokeWidth:1.75})})]},I.id))});return{attachments:t,uploading:u,blocked:u||F,controls:ae,previewsUI:te,clear:n,upload:R,previews:t.map(({id:I,name:g,mimeType:b,size:B,preview:oe})=>({id:I,name:g,mimeType:b,size:B,previewUrl:oe})),tokens:t.flatMap(I=>I.token?[I.token]:[])}}var Ve=new WeakMap;async function Aa(e,a,o){let t=Ve.get(e);if(!t){let u=await a.userId();if(!u)throw new Error("Sign in again to save the snapshot.");let r=crypto.randomUUID();t={id:r,name:e.name,mimeType:e.type,size:e.size,file:e,bucket:"chisel-review-images",path:`${u}/${r}`,preview:"",stored:!1,status:"uploading"},Ve.set(e,t)}let l=t.token??await a.send(t,t.stored,()=>!0);if(!l)throw new Error("The snapshot upload was incomplete.");t.token=l,await o(l)}export{Z as ReviewAttachmentButton,He as ReviewBody,ha as ReviewComposer,J as ReviewEditor,Sa as ReviewThread,fe as bodyToEditor,Te as createReviewEditor,re as displayedActivity,ve as editorToBody,Aa as uploadSnapshot,wa as useReadQueue,ya as useReviewAttachments};
1
+ "use client";import{forwardRef as Je,createElement as Qe}from"react";var Ce=e=>e?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function he(e,a,o=[]){if(a==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Ce(e),size:24,node:a,...o.length>0?{aliases:o}:{}}}var ge=e=>{let a="",o=!1;for(let t of e){if(t==="-"||t==="_"||t<=" "){o=a.length>0;continue}a.length===0?a+=t.toLowerCase():a+=o?t.toUpperCase():t,o=!1}return a};var Se=e=>{let a=ge(e);return a.charAt(0).toUpperCase()+a.slice(1)};import{forwardRef as Ze,createElement as Ae}from"react";var W=(...e)=>e.filter((a,o,t)=>!!a&&a.trim()!==""&&t.indexOf(a)===o).join(" ").trim();var v={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function re(e){return e!=null}function ke(e,a={}){let o=a.attributeNames??{},t=d=>o[d]??d,l=e.size??e.width??v.width,u=e.size??e.height??v.height,r=e.aliases?.filter(d=>typeof d=="string"&&d.trim()!=="").map(d=>`lucide-${d}`)??[],n=[...e.name?[`lucide-${e.name}`]:[],...r],i=a.className?.split(" ").filter(Boolean)??[],I=a.includeDefaultClasses===!1?W(...i):W("lucide",...n,...i),s=a.absoluteStrokeWidth?Number(a.strokeWidth??v["stroke-width"])*Number(e.size??e.width??v.width)/Number(a.size??a.width??v.width):a.strokeWidth??v["stroke-width"];return["svg",{...Object.entries(v).reduce((d,[f,c])=>(d[t(f)]=c,d),{}),..."color"in a&&a.color&&{[t("stroke")]:a.color},..."size"in a&&re(a.size)&&{[t("width")]:a.size,[t("height")]:a.size},..."width"in a&&re(a.width)&&{[t("width")]:a.width},..."height"in a&&re(a.height)&&{[t("height")]:a.height},[t("stroke-width")]:s,...I&&{[t("class")]:I},[t("viewBox")]:`0 0 ${l} ${u}`,...a.hasA11yProp===!1?{[t("aria-hidden")]:"true"}:{},..."attributes"in a&&a.attributes},e.node.map(d=>{let[f,c,x]=d,g=a.nonScalingStroke?{[t("vector-effect")]:"non-scaling-stroke",...c}:c;return x?[f,g,x]:[f,g]})]}function we(e,a={}){return ke(e,{...a,attributeNames:{...a.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var Pe=e=>{for(let a in e)if(a.startsWith("aria-")||a==="role"||a==="title")return!0;return!1};import{createContext as Ne,useContext as Xe,useMemo as za,createElement as Na}from"react";var Ke=Ne({});var ye=()=>Xe(Ke);var Be=Ze(({color:e,size:a,width:o,height:t,strokeWidth:l,absoluteStrokeWidth:u,nonScalingStroke:r,className:n="",children:i,iconNode:I=[],icon:s={node:I,aliases:[],size:24},...L},d)=>{let{size:f=24,strokeWidth:c=2,absoluteStrokeWidth:x=!1,nonScalingStroke:g=!1,color:b="currentColor",className:O=""}=ye()??{},S=!!i||Pe(L),[F,oe,ue=[]]=we(s,{color:e??b,width:o??a??f,height:t??a??f,strokeWidth:l??c,absoluteStrokeWidth:u??x,nonScalingStroke:r??g,className:W(O,n),hasA11yProp:S,attributes:L});return Ae(F,{ref:d,...oe},[...ue.map(([p,h])=>Ae(p,h)),...Array.isArray(i)?i:[i]])});function k(e,a=[],o=[]){let t=typeof e=="string"?he(e,a,o):e,l=Je(({className:u,...r},n)=>Qe(Be,{ref:n,icon:t,className:u,...r}));return t.name&&(l.displayName=Se(t.name)),l}var $e={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]},V=k($e);var _e={name:"download",size:24,node:[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]},z=k(_e);var je={name:"paperclip",size:24,node:[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]},N=k(je);var Ye={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]},X=k(Ye);var ea={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]},K=k(ea);var aa={name:"rotate-cw",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]},Z=k(aa);var ta={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]},q=k(ta);import{useEffect as U,useRef as y,useState as $}from"react";function D(e){return{version:1,content:e.split(`
2
+ `).map(a=>({type:"paragraph",children:[{text:a}]}))}}function _(e){return e.content.map(a=>a.children.map(o=>"type"in o?o.text||o.url:o.text).join("")).join(`
3
+ `)}function j(e){let a=e.content.slice();for(;a.length;){let o=a[a.length-1],t=o.children.slice();for(;t.length;){let l=t[t.length-1],u="type"in l?l.text||l.url:l.text,r=u.trimEnd();if(r)return t[t.length-1]=r===u?l:{...l,text:r},a[a.length-1]={...o,children:t},{...e,content:a};t.pop()}a.pop()}return D("")}function se(e){try{let a=JSON.parse(localStorage.getItem(e)??"null");return a?.version===1&&Date.now()-a.time<7*864e5?a.value:null}catch{return null}}function E(e,a){try{return a===null?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify({version:1,time:Date.now(),value:a})),!0}catch{return!1}}function fe(e,a,o){let t=e;for(let l of[...a].sort((u,r)=>u-r))if(!(l<=t)){if(!o.has(l))break;t=l}return t}var Y=["image/jpeg","image/png","image/gif","image/webp","image/avif","image/bmp"],De=["video/mp4","video/webm","video/quicktime"],Me=[...Y,...De].join(",");function be(e){let a=Y.includes(e.type);return!a&&!De.includes(e.type)?"Choose a JPG, PNG, GIF, WebP, AVIF, BMP, MP4, WebM, or MOV file.":!Number.isSafeInteger(e.size)||e.size<=0?"This file is empty or invalid.":e.size>(a?5242880:20971520)?`${a?"Images must be 5 MB":"Videos must be 20 MB"} or smaller.`:null}import{useEffect as oa,useRef as Fe,useState as Re}from"react";import{createEditor as ua,Editor as C,Element as G,Node as da,Path as la,Range as ie,Transforms as M}from"slate";import{withHistory as ra}from"slate-history";import{Editable as sa,Slate as fa,withReact as ia,ReactEditor as ve}from"slate-react";import{Fragment as Ue,jsx as w,jsxs as Oe}from"react/jsx-runtime";function ce(e){return e.content.length?e.content.map(a=>({type:"paragraph",children:a.children.length?a.children.map(o=>"type"in o&&o.type==="link"?{type:"link",url:o.url,children:[{text:o.text||o.url}]}:{...o}):[{text:""}]})):[{type:"paragraph",children:[{text:""}]}]}function Te(e){return{version:1,content:e.map(a=>({type:"paragraph",children:G.isElement(a)?a.children.map(o=>G.isElement(o)?{type:"link",url:o.url,text:da.string(o)}:{...o}):[{text:a.text}]}))}}function ne(e){return/^(https?:\/\/|mailto:)[^\s]+$/i.test(e)}function ca(e,a){if(!e.selection){let o=window.getSelection(),t=o&&ve.toSlateRange(e,o,{exactMatch:!1,suppressThrow:!0});M.select(e,t??C.end(e,[]))}C.marks(e)?.[a]?C.removeMark(e,a):C.addMark(e,a,!0)}function qe(){let e=ia(ra(ua()),"application/x-chisel-review-fragment"),{isInline:a,insertText:o,insertData:t,insertBreak:l}=e;e.isInline=n=>n.type==="link"||a(n);function u(n,i){C.above(e,{at:n,match:I=>G.isElement(I)&&I.type==="link"})||(M.wrapNodes(e,{type:"link",url:i,children:[]},{at:n,split:!0}),M.collapse(e,{edge:"end"}))}function r(){if(!e.selection||!ie.isCollapsed(e.selection))return;let n=C.above(e,{match:d=>G.isElement(d)&&d.type==="paragraph"});if(!n)return;let i=e.selection.anchor,s=C.string(e,{anchor:C.start(e,n[1]),focus:i}).match(/\S+$/)?.[0];if(!s||!ne(s))return;let L=C.before(e,i,{distance:s.length,unit:"offset"});if(L){u({anchor:L,focus:i},s);let d=C.above(e,{match:f=>G.isElement(f)&&f.type==="link"});d&&e.selection&&C.isEnd(e,e.selection.anchor,d[1])&&M.select(e,C.start(e,la.next(d[1])))}}return e.insertText=n=>{if(ve.isComposing(e)){o(n);return}n===" "&&r();let i={"*":"bold",_:"italic","~":"strikethrough","`":"code"}[n];if(i&&e.selection&&ie.isCollapsed(e.selection)){let I=C.above(e,{match:s=>G.isElement(s)&&s.type==="paragraph"});if(I){let s=e.selection.anchor,L=C.string(e,{anchor:C.start(e,I[1]),focus:s}),d=L.lastIndexOf(n),f=L.slice(d+1);if(d>=0&&(!d||/[\s*_~`]/.test(L[d-1]))&&f&&f.trim()===f){let c=C.before(e,s,{distance:f.length,unit:"offset"}),x=c&&C.before(e,c,{unit:"offset"});if(c&&x){M.select(e,{anchor:c,focus:s}),C.addMark(e,i,!0),M.collapse(e,{edge:"end"}),M.delete(e,{at:{anchor:x,focus:c}}),C.removeMark(e,i);return}}}}o(n)},e.insertBreak=()=>{r(),l()},e.insertData=n=>{let i=n.getData("text/plain");ne(i)?e.selection&&!ie.isCollapsed(e.selection)?u(e.selection,i):M.insertNodes(e,[{type:"link",url:i,children:[{text:i}]},{text:""}]):t(n)},e}function na({attributes:e,children:a,element:o}){return o.type==="link"?w("a",{...e,href:ne(o.url)?o.url:void 0,onClick:t=>t.preventDefault(),children:a}):w("p",{...e,children:a})}function pa({attributes:e,children:a,leaf:o}){let t=w(Ue,{children:a});return o.bold&&(t=w("strong",{children:t})),o.italic&&(t=w("em",{children:t})),o.strikethrough&&(t=w("s",{children:t})),o.code&&(t=w("code",{children:t})),w("span",{...e,children:t})}function J({onFiles:e,disabled:a}){let o=Fe(null);return Oe(Ue,{children:[w("input",{ref:o,type:"file",accept:Me,multiple:!0,hidden:!0,onChange:t=>{e(t.target.files),t.target.value=""}}),w("button",{type:"button",className:"review-retry-upload","aria-label":"Attach image or video",title:"Images up to 5 MB \xB7 Videos up to 20 MB",disabled:a,onClick:()=>o.current?.click(),children:w(N,{size:16,strokeWidth:1.75})})]})}function Q({text:e,defaultBody:a,disabled:o,label:t,placeholder:l,autoFocus:u,onChange:r,onSubmit:n,onFiles:i,uploading:I}){let[s]=Re(qe),[L]=Re(()=>ce(a??D(e))),d=Fe(e);return oa(()=>{if(e===d.current)return;let f=d.current;d.current=e,f&&e.startsWith(f)?M.insertText(s,e.slice(f.length),{at:C.end(s,[])}):(C.withoutNormalizing(s,()=>{M.removeNodes(s,{at:[],match:(c,x)=>x.length===1}),M.insertNodes(s,ce(D(e)),{at:[0]}),M.deselect(s)}),e||(s.history={undos:[],redos:[]}))},[s,e]),Oe(fa,{editor:s,initialValue:L,onChange:f=>{if(!s.operations.some(x=>x.type!=="set_selection"))return;let c=Te(f);d.current=_(c),r(d.current,c)},children:[w(sa,{className:"review-composer-editor",role:"textbox","aria-multiline":"true","aria-label":t,placeholder:l,readOnly:o,autoFocus:u,renderElement:na,renderLeaf:pa,onKeyDown:f=>{if(f.nativeEvent.isComposing)return;let c=f.metaKey||f.ctrlKey;if(f.key==="Enter"){f.preventDefault(),c?s.insertBreak():n();return}let x=c?{b:"bold",i:"italic",e:"code",...f.shiftKey?{s:"strikethrough"}:{}}[f.key.toLowerCase()]:void 0;x&&(f.preventDefault(),ca(s,x))}}),i&&w("div",{className:"chisel-attachment-controls",children:w(J,{onFiles:i,disabled:o||I})})]})}import{useEffect as ma,useRef as La,useState as Ia}from"react";import{Fragment as He,jsx as P,jsxs as ee}from"react/jsx-runtime";function xa({src:e,name:a,mimeType:o,onError:t,close:l}){let u=La(null);return ma(()=>{u.current?.showModal()},[]),P("dialog",{ref:u,className:"review-media-lightbox","aria-label":`Preview ${a}`,onCancel:r=>{r.preventDefault(),l()},onClick:r=>{r.target===r.currentTarget&&l()},children:ee("div",{className:"review-media-lightbox-content",children:[ee("header",{children:[P("span",{children:a}),P("a",{href:e,download:a,"aria-label":`Download ${a}`,title:"Download",children:P(z,{size:20,"aria-hidden":"true"})}),P("button",{type:"button","aria-label":"Close preview",onClick:l,children:P(q,{size:20})})]}),o.startsWith("image/")?P("img",{src:e,alt:a,onError:t}):P("video",{src:e,controls:!0,autoPlay:!0,playsInline:!0,"aria-label":a,onError:t})]})})}function ae({src:e,name:a,mimeType:o,onError:t}){let[l,u]=Ia(!1);return ee(He,{children:[P("button",{type:"button",className:"review-media-thumbnail","aria-label":`Preview ${a}`,onClick:()=>u(!0),children:o.startsWith("image/")?P("img",{src:e,alt:a,loading:"lazy",onError:t}):ee(He,{children:[P("video",{src:e,muted:!0,playsInline:!0,preload:"metadata","aria-hidden":"true",onError:t}),P("span",{className:"review-media-play","aria-hidden":"true",children:P(K,{size:20,fill:"currentColor"})})]})}),l&&P(xa,{src:e,name:a,mimeType:o,onError:t,close:()=>u(!1)})]})}import{Fragment as wa,jsx as m,jsxs as A}from"react/jsx-runtime";function pe(e,a,o){if(e)try{let t=se(e);if(t?.text===a&&_(t.body)===a)return t.body}catch{}return o??D(a)}function me(e,a,o,t=!1){e&&E(e,t||a.trim()?{text:a,body:o}:null)}function Ee({body:e}){return m("div",{className:"review-comment-body",children:e.content.map((a,o)=>m("p",{children:a.children.map((t,l)=>{if("type"in t&&t.type==="link")return m("a",{href:/^(https?:|mailto:)/i.test(t.url)?t.url:void 0,target:"_blank",rel:"noopener noreferrer",children:t.text||t.url},l);if(!("text"in t))return null;let u=m(wa,{children:t.text});return"bold"in t&&t.bold&&(u=m("strong",{children:u})),"italic"in t&&t.italic&&(u=m("em",{children:u})),"strikethrough"in t&&t.strikethrough&&(u=m("s",{children:u})),"code"in t&&t.code&&(u=m("code",{children:u})),m("span",{children:u},l)})},o))})}function Ca({attachment:e,loadMedia:a}){let[o,t]=$(e.previewUrl??""),[l,u]=$(!1),[r,n]=$(0),i=y(0);U(()=>{if(e.previewUrl){t(e.previewUrl);return}t("");let s=!0,L=!1,d=new AbortController;async function f(){if(!(L||document.visibilityState==="hidden")){L=!0;try{let g=await a(e.id,d.signal);s&&(t(g),u(!1),i.current=Date.now()+240*1e3)}catch{s&&u(!0)}finally{L=!1}}}function c(){Date.now()>=i.current&&f()}f();let x=window.setInterval(c,60*1e3);return window.addEventListener("focus",c),document.addEventListener("visibilitychange",c),()=>{s=!1,d.abort(),window.clearInterval(x),window.removeEventListener("focus",c),document.removeEventListener("visibilitychange",c)}},[e.id,e.previewUrl,r,a]);function I(){u(!0),Date.now()>=i.current&&n(s=>s+1)}return A("figure",{className:"review-attachment",children:[o&&!l?m(ae,{src:o,name:e.name,mimeType:e.mimeType,onError:I}):m("div",{className:"review-attachment-placeholder",role:"status",children:l?m("button",{type:"button",className:"review-retry-upload",onClick:()=>n(s=>s+1),children:"Retry attachment"}):"Loading attachment\u2026"}),m("figcaption",{children:e.name})]})}function Ge(e){let a=Math.max(0,Math.floor((Date.now()-Date.parse(e))/6e4));return a<1?"Just now":a<60?`${a}m`:a<1440?`${Math.floor(a/60)}h`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function ha({comment:e,activity:a,loadMedia:o,editable:t,editing:l,saving:u,onStartEdit:r,onCancelEdit:n,onSaveEdit:i,onDraftChange:I,onEditStyles:s,draftKey:L}){let[d,f]=$(e.text),c=y(e.body??D(e.text)),x=y(!1),g=l&&!(u&&x.current),b=y(!1);U(()=>{l?I(d!==e.text||JSON.stringify(c.current)!==JSON.stringify(e.body??D(e.text))):b.current&&L&&E(L,null),b.current=l},[l]),U(()=>{l||(f(e.text),c.current=e.body??D(e.text))},[l,e.text,e.body]);async function O(){if(!(u||x.current||!d.trim()&&!e.attachments?.length)){x.current=!0;try{await i(d.trimEnd(),j(c.current))&&(L&&E(L,null),I(!1))}finally{x.current=!1}}}return A("article",{className:"review-comment","data-activity":a,children:[m("span",{className:"review-comment-avatar",children:e.authorImage?m("img",{src:e.authorImage,alt:""}):e.author.slice(0,1).toUpperCase()}),A("div",{className:"review-comment-content",children:[A("header",{className:"review-comment-header",children:[m("span",{className:"review-comment-author",children:e.author}),e.pending?m("span",{className:"review-comment-time",role:"status",children:"Sending\u2026"}):m("time",{className:"review-comment-time",dateTime:e.date,title:new Date(e.date).toLocaleString(),children:Ge(e.date)}),t&&!l&&m("button",{type:"button",className:"review-comment-edit","aria-label":"Edit comment",title:"Edit comment",disabled:u,onClick:()=>{let S=L?se(L):null;S&&typeof S.text=="string"&&(f(S.text),c.current=pe(L,S.text)),r()},children:m(X,{size:16})})]}),g?A("form",{className:"review-inline-edit",onSubmit:S=>{S.preventDefault(),O()},children:[m(Q,{text:d,defaultBody:c.current,disabled:u,label:"Edit comment",placeholder:"Edit comment\u2026",autoFocus:!0,onSubmit:()=>{O()},onChange:(S,F)=>{f(S),c.current=F,me(L,S,F,!0),I(S!==e.text||JSON.stringify(F)!==JSON.stringify(e.body??D(e.text)))}}),A("div",{className:"review-inline-edit-actions",children:[s&&m("button",{type:"button",disabled:u,onClick:s,children:"Edit styles"}),m("button",{type:"button",disabled:u,onClick:n,children:"Cancel"}),m("button",{type:"submit",disabled:u||!d.trim()&&!e.attachments?.length,children:"Save"})]})]}):m(Ee,{body:e.body??D(e.text)}),e.attachments?.length>0&&m("div",{className:"review-attachments",children:e.attachments.map(S=>m(Ca,{attachment:S,loadMedia:o},S.id))})]})]})}function ga(e){let a=e.useAttachments(e.disabled,e.existingAttachments?.length??0),o=y(pe(e.draftKey,e.text,e.defaultBody)),t=y(!1);U(()=>(e.onAttachmentDraftChange?.(a.uploading||a.attachments.length>0),()=>e.onAttachmentDraftChange?.(!1)),[a.uploading,a.attachments.length,e.onAttachmentDraftChange]);async function l(){if(!(e.disabled||a.blocked||t.current||!e.text.trim()&&!a.attachments.length&&!e.existingAttachments?.length)){t.current=!0;try{await e.onSubmit(e.text.trimEnd(),j(o.current),a.tokens,a.previews)&&(e.draftKey&&E(e.draftKey,null),a.clear())}finally{t.current=!1}}}return m("form",{className:"review-composer chisel-review-composer","aria-label":e.commentId?"Edit comment":"New comment",onSubmit:u=>{u.preventDefault(),l()},onPasteCapture:u=>{u.clipboardData.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.clipboardData.files))},onDragOver:u=>{u.dataTransfer.types.includes("Files")&&u.preventDefault()},onDropCapture:u=>{u.dataTransfer.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.dataTransfer.files))},children:e.renderContent(A("div",{className:"chisel-composer-input",children:[m(Q,{text:e.text,defaultBody:o.current,disabled:e.disabled,label:"Comment",placeholder:"Leave a comment\u2026",autoFocus:!0,onSubmit:()=>{l()},onChange:(u,r)=>{o.current=r,me(e.draftKey,u,r),e.onText(u)}}),a.previewsUI,a.controls]}),a.attachments.length>0||!!e.existingAttachments?.length,a.blocked,m(J,{onFiles:a.upload,disabled:e.disabled||a.uploading}))})}function Sa(e){let a=e.useAttachments(e.saving),o=y(pe(e.draftKey,e.reply)),t=y(!1);U(()=>(e.onAttachmentDraftChange?.(a.uploading||a.attachments.length>0),()=>e.onAttachmentDraftChange?.(!1)),[a.uploading,a.attachments.length,e.onAttachmentDraftChange]);async function l(){if(!(e.saving||a.blocked||t.current||!e.reply.trim()&&!a.attachments.length)){t.current=!0;try{await e.onReply(e.reply.trimEnd(),j(o.current),a.tokens,a.previews)&&(e.draftKey&&E(e.draftKey,null),o.current=D(""),a.clear())}finally{t.current=!1}}}return A("form",{className:"review-composer chisel-review-reply","aria-label":"Reply to thread",hidden:e.submittingReply,onSubmit:u=>{u.preventDefault(),l()},onPasteCapture:u=>{u.clipboardData.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.clipboardData.files))},onDragOver:u=>{u.dataTransfer.types.includes("Files")&&u.preventDefault()},onDropCapture:u=>{u.dataTransfer.files.length&&(u.preventDefault(),u.stopPropagation(),a.upload(u.dataTransfer.files))},children:[m("span",{className:"feedback-avatar feedback-reply-avatar",children:e.replyAuthor?.image?m("img",{src:e.replyAuthor.image,alt:""}):(e.replyAuthor?.name||"You").slice(0,1).toUpperCase()}),A("div",{className:"chisel-reply-field",children:[m(Q,{text:e.reply,defaultBody:o.current,disabled:e.saving,label:"Reply",placeholder:"Write a reply\u2026",onSubmit:()=>{l()},onChange:(u,r)=>{o.current=r,me(e.draftKey,u,r),e.onReplyText(u)}}),a.previewsUI,a.controls,m("div",{className:"chisel-attachment-controls",children:m(J,{onFiles:a.upload,disabled:e.saving||a.uploading})}),m("button",{type:"submit",className:"chisel-reply-submit","aria-label":"Reply",disabled:e.saving||a.blocked||!e.reply.trim()&&!a.attachments.length,children:m(V,{size:16,strokeWidth:1.75})})]})]})}function ka(e){let a=e.comment,[o,t]=$(null),l=y(!1),u=y(e.onEditDraftChange);u.current=e.onEditDraftChange,U(()=>()=>{u.current?.(!1)},[]);function r(d){l.current=d,e.onEditDraftChange?.(d)}async function n(d){d&&e.onBeginEdit&&!await e.onBeginEdit()||!d&&l.current&&e.onDiscardEdit&&!await e.onDiscardEdit()||(r(!1),t(d))}function i(d,f){return m(ha,{draftKey:e.draftKey?`${e.draftKey}:edit:${d.id}`:void 0,comment:d,activity:f?a.rootActivity:d.activity,loadMedia:e.loadMedia,editable:!!(e.expanded&&e.onEdit&&e.userId&&d.authorId===e.userId&&!d.pending),editing:o===d.id,saving:e.saving,onEditStyles:f?e.onEditStyles:void 0,onStartEdit:()=>{n(d.id)},onCancelEdit:()=>{n(null)},onDraftChange:r,onSaveEdit:async(c,x)=>{let g=await e.onEdit?.(f?null:d.id,c,x);return g&&(r(!1),t(null)),!!g}},d.id)}let I=y(null),s=y(new Set),L=y(a.readActivity??0);return U(()=>{if(!e.expanded||!I.current||a.pending||a.readActivity===null)return;let d=[a.rootActivity,...a.replies.map(x=>x.activity)],f=new IntersectionObserver(x=>{if(document.visibilityState!=="visible")return;for(let b of x)b.isIntersecting&&b.intersectionRatio>0&&s.current.add(Number(b.target.dataset.activity));let g=fe(Math.max(L.current,a.readActivity??0),d,s.current);g>L.current&&(L.current=g,e.onRead(a.id,g))},{threshold:0});function c(){if(f.disconnect(),document.visibilityState==="visible")for(let x of I.current?.querySelectorAll("[data-activity]")??[])f.observe(x)}return c(),document.addEventListener("visibilitychange",c),()=>{f.disconnect(),document.removeEventListener("visibilitychange",c)}},[a,e.expanded,e.onRead]),A("div",{className:"chisel-review-thread-content",children:[e.expanded&&a.context&&A("p",{className:"review-capture-context",children:[a.context.width," \xD7 ",a.context.height,"px \xB7 ",a.breakpoint??"desktop",a.context.deployment?` \xB7 ${a.context.deployment}`:"",A("time",{dateTime:a.context.capturedAt,title:new Date(a.context.capturedAt).toLocaleString(),children:[" \xB7 ",Ge(a.context.capturedAt)]})]}),A("div",{ref:I,className:"review-thread",children:[i(a,!0),e.expanded&&a.replies.map(d=>i(d,!1))]}),e.expanded?!o&&m(Sa,{...e}):m("button",{type:"button",className:"chisel-expand-thread",onClick:e.onExpand,children:a.replies.length?`${a.replies.length} ${a.replies.length===1?"reply":"replies"}`:"Reply\u2026"})]})}import{useCallback as We,useRef as Ve}from"react";function Pa(e,a){let o=Ve(new Map),t=Ve(!1),l=We(async()=>{if(!t.current){t.current=!0;try{for(;o.current.size;){let[r,n]=o.current.entries().next().value;try{await e(r,n)}catch(i){if([400,403,404].includes(i.status??0)){o.current.delete(r);continue}throw i}o.current.get(r)===n&&o.current.delete(r),a(r,n)}}catch{}finally{t.current=!1}}},[e,a]),u=We((r,n)=>{o.current.set(r,Math.max(n,o.current.get(r)??0)),l()},[l]);return{flush:l,markDisplayed:u}}import{useEffect as ya,useRef as te,useState as Le}from"react";import{jsx as T,jsxs as Ie}from"react/jsx-runtime";function Aa(e=!1,a=0,o){let[t,l]=Le([]),[u,r]=Le(!1),[n,i]=Le(""),I=te(!0),s=te(!1),L=te(new Map),d=te(null),f=p=>o.discard(p);ya(()=>(I.current=!0,()=>{I.current=!1;for(let p of L.current.values())URL.revokeObjectURL(p.preview),f(p).catch(()=>{})}),[]);function c(){I.current&&l([...L.current.values()].filter(p=>p.id!==d.current).map(p=>({...p})))}function x(){for(let p of L.current.values())URL.revokeObjectURL(p.preview);L.current.clear(),I.current&&(l([]),i(""))}async function g(p){let h=L.current.get(p);if(!(!h||s.current||e)){s.current=!0,r(!0),d.current=p,c();try{await f(h),L.current.delete(p),URL.revokeObjectURL(h.preview),c(),i("")}catch(R){I.current&&i(R instanceof Error?R.message:"The attachment could not be removed.")}finally{d.current=null,s.current=!1,c(),I.current&&r(!1)}}}async function b(p){for(let h of p){if(!I.current)return;let R=h.status==="failed";h.status="uploading",c();try{h.token=await o.send(h,R,()=>I.current),h.status="ready"}catch(B){h.status="failed",I.current&&i(B instanceof Error?B.message:"The upload failed. Your comment is still here.")}finally{I.current||await f(h).catch(()=>{})}c()}}async function O(p){if(!p?.length||s.current||e)return;let h=Array.from(p),R=h.map(B=>be(B)).find(Boolean);if(R){i(R);return}if(a+L.current.size+h.length>20){i("Attach up to 20 files per comment.");return}s.current=!0,r(!0),i("");try{let B=await o.userId();if(!B)throw new Error("Sign in again to attach files.");if(!I.current)return;let de=h.map(H=>{let le=crypto.randomUUID(),xe={id:le,name:H.name,mimeType:H.type,size:H.size,file:H,bucket:Y.includes(H.type)?"chisel-review-images":"chisel-review-videos",path:`${B}/${le}`,preview:URL.createObjectURL(H),stored:!1,status:"uploading"};return L.current.set(le,xe),xe});c(),await b(de)}catch(B){I.current&&i(B instanceof Error?B.message:"The upload failed. Your comment is still here.")}finally{s.current=!1,I.current&&r(!1)}}async function S(){if(!(s.current||e)){s.current=!0,r(!0),i("");try{await b([...L.current.values()].filter(p=>p.status==="failed"))}finally{s.current=!1,I.current&&r(!1)}}}let F=t.some(p=>p.status==="failed"),oe=Ie("div",{className:"chisel-attachment-controls",children:[u&&T("span",{role:"status",children:"Uploading\u2026"}),F&&Ie("button",{type:"button",className:"review-retry-upload",disabled:u||e,onClick:()=>{S()},children:[T(Z,{size:16,strokeWidth:1.75}),"Retry upload"]}),n&&T("span",{className:"chisel-attachment-error",role:"alert",children:n})]}),ue=t.length>0&&T("div",{className:"chisel-attachment-previews",children:t.map(p=>Ie("div",{className:"chisel-attachment-preview","data-state":p.status,children:[T(ae,{src:p.preview,name:p.name,mimeType:p.mimeType}),T("span",{title:p.name,children:p.name}),T("button",{type:"button","aria-label":`Remove ${p.name}`,disabled:u||e,onClick:()=>{g(p.id)},children:T(q,{size:16,strokeWidth:1.75})})]},p.id))});return{attachments:t,uploading:u,blocked:u||F,controls:oe,previewsUI:ue,clear:x,upload:O,previews:t.map(({id:p,name:h,mimeType:R,size:B,preview:de})=>({id:p,name:h,mimeType:R,size:B,previewUrl:de})),tokens:t.flatMap(p=>p.token?[p.token]:[])}}var ze=new WeakMap;async function Ba(e,a,o){let t=ze.get(e);if(!t){let u=await a.userId();if(!u)throw new Error("Sign in again to save the snapshot.");let r=crypto.randomUUID();t={id:r,name:e.name,mimeType:e.type,size:e.size,file:e,bucket:"chisel-review-images",path:`${u}/${r}`,preview:"",stored:!1,status:"uploading"},ze.set(e,t)}let l=t.token??await a.send(t,t.stored,()=>!0);if(!l)throw new Error("The snapshot upload was incomplete.");t.token=l,await o(l)}export{J as ReviewAttachmentButton,Ee as ReviewBody,ga as ReviewComposer,Q as ReviewEditor,ka as ReviewThread,ce as bodyToEditor,qe as createReviewEditor,fe as displayedActivity,Te as editorToBody,Ba as uploadSnapshot,Pa as useReadQueue,Aa as useReviewAttachments};
4
4
  /*! Bundled license information:
5
5
 
6
6
  lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs: