@kelet-ai/feedback-ui 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -279,7 +279,7 @@ function pe() {
279
279
  return ce || (ce = 1, process.env.NODE_ENV === "production" ? U.exports = me() : U.exports = ve()), U.exports;
280
280
  }
281
281
  var E = pe();
282
- const L = ue(null), Ee = "https://api-v0.kelet.ai/", Pe = () => {
282
+ const L = ue(null), Ee = "https://api.kelet.ai/", Pe = () => {
283
283
  const s = W(L);
284
284
  if (!s)
285
285
  throw new Error("useKelet must be used within a KeletProvider");
@@ -19,4 +19,4 @@
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,v,p,j,p),se[p+v]=!0)}if(p=null,b!==void 0&&(c(b),p=""+b),f(r)&&(c(r.key),p=""+r.key),"key"in r){b={};for(var Z in r)Z!=="key"&&(b[Z]=r[Z])}else b=r;return p&&i(b,typeof e=="function"?e.displayName||e.name||"Unknown":e),k(e,p,x,S,n(),b,G,X)}function g(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var R=a,P=Symbol.for("react.transitional.element"),h=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),B=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),M=Symbol.for("react.context"),W=Symbol.for("react.forward_ref"),J=Symbol.for("react.suspense"),D=Symbol.for("react.suspense_list"),z=Symbol.for("react.memo"),K=Symbol.for("react.lazy"),u=Symbol.for("react.activity"),y=Symbol.for("react.client.reference"),C=R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,V=Object.prototype.hasOwnProperty,U=Array.isArray,H=console.createTask?console.createTask:function(){return null};R={"react-stack-bottom-frame":function(e){return e()}};var ne,oe={},re=R["react-stack-bottom-frame"].bind(R,s)(),ae=H(t(s)),se={};O.Fragment=_,O.jsx=function(e,r,b,v,S){var x=1e4>C.recentlyCreatedOwnerStacks++;return d(e,r,b,!1,v,S,x?Error("react-stack-top-frame"):re,x?H(t(e)):ae)},O.jsxs=function(e,r,b,v,S){var x=1e4>C.recentlyCreatedOwnerStacks++;return d(e,r,b,!0,v,S,x?Error("react-stack-top-frame"):re,x?H(t(e)):ae)}}()),O}var $;function ie(){return $||($=1,process.env.NODE_ENV==="production"?Y.exports=le():Y.exports=ce()),Y.exports}var E=ie();const N=a.createContext(null),ue="https://api-v0.kelet.ai/",de=()=>{const l=a.useContext(N);if(!l)throw new Error("useKelet must be used within a KeletProvider");return l},ee=()=>{const l=a.useContext(N);return l?l.feedback:async()=>{}},fe=({api_key:l,project:o,children:c})=>{const t=a.useContext(N),n=l||t?.api_key;if(!n)throw new Error("api_key is required either directly or from a parent KeletProvider");const f={api_key:n,project:o,feedback:async i=>{const m=`${ue}/projects/${o}/feedback`,k={tx_id:i.identifier,source:"EXPLICIT",vote:i.vote,explanation:i.explanation},d=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(k)});if(!d.ok)throw new Error(`Failed to submit feedback: ${d.statusText}`)}};return E.jsx(N.Provider,{value:f,children:c})},F=(l,o)=>{const c={...o};for(const t in o){const n=l[t],s=o[t];/^on[A-Z]/.test(t)?n&&s?c[t]=(...i)=>{s(...i),n(...i)}:n&&(c[t]=n):t==="style"?c[t]={...n,...s}:t==="className"?c[t]=[n,s].filter(Boolean).join(" "):c[t]=s!==void 0?s:n}return{...l,...c}},te=a.createContext(null),I=()=>{const l=a.useContext(te);if(!l)throw new Error("VoteFeedback components must be used within VoteFeedback.Root");return l},be={Root:({children:l,onFeedback:o,defaultText:c="",identifier:t,extra_metadata:n})=>{const[s,f]=a.useState(!1),[i,m]=a.useState(c),[k,d]=a.useState(!1),[g,R]=a.useState(null),P=a.useRef(null),h=a.useRef(null),_=a.useId(),B=a.useId(),L=ee(),T=o||L,M=a.useCallback(async()=>{R("upvote");const u={identifier:t,vote:"upvote",...n&&{extra_metadata:n}};try{d(!0),await T(u)}finally{d(!1)}},[T,t,n]),W=a.useCallback(async()=>{if(R("downvote"),T){const u={identifier:t,vote:"downvote",...n&&{extra_metadata:n}};try{d(!0),await T(u)}finally{d(!1)}}f(!0),setTimeout(()=>{P.current?.focus();const u=document.createElement("div");u.setAttribute("aria-live","polite"),u.setAttribute("aria-atomic","true"),u.className="sr-only",u.textContent="Feedback dialog opened. You can provide additional details about your downvote.",document.body.appendChild(u),setTimeout(()=>document.body.removeChild(u),1e3)},0)},[T,t,n]),J=a.useCallback(u=>{m(u.target.value)},[]),D=a.useCallback(async()=>{const u=i.trim().length>0;if(u){const y={identifier:t,vote:"downvote",explanation:i,...n&&{extra_metadata:n}};try{d(!0),await T(y)}finally{d(!1)}}if(f(!1),m(c),h.current?.focus(),u){const y=document.createElement("div");y.setAttribute("aria-live","polite"),y.className="sr-only",y.textContent="Feedback submitted successfully.",document.body.appendChild(y),setTimeout(()=>document.body.removeChild(y),1e3)}},[T,i,c,t,n]),z=a.useCallback(u=>{if(u.key==="Escape")f(!1),m(c),h.current?.focus();else if((u.metaKey||u.ctrlKey)&&u.key==="Enter")u.preventDefault(),D().then(y=>{});else if(u.key==="Tab"&&s){const y=document.getElementById(_);if(y){const C=y.querySelectorAll('button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'),V=C[0],U=C[C.length-1];u.shiftKey&&document.activeElement===V?(u.preventDefault(),U?.focus()):!u.shiftKey&&document.activeElement===U&&(u.preventDefault(),V?.focus())}}},[D,s,_,c]),K={onFeedback:T,showPopover:s,setShowPopover:f,feedbackText:i,setFeedbackText:m,isSubmitting:k,setIsSubmitting:d,vote:g,handleUpvote:M,handleDownvote:W,handleTextareaChange:J,handleSubmit:D,handleKeyDown:z,textareaRef:P,triggerRef:h,popoverId:_,triggerId:B,identifier:t,extra_metadata:n};return E.jsx(te.Provider,{value:K,children:l})},UpvoteButton:({asChild:l,children:o,onClick:c,...t})=>{const{handleUpvote:n,isSubmitting:s,vote:f}=I(),i=a.useCallback(d=>{n(),c?.(d)},[n,c]),m={...t,onClick:i,disabled:s||t.disabled,"aria-label":t["aria-label"]||"Upvote feedback",type:"button"},k=f==="upvote";if(l){const d=typeof o=="function"?o({isSelected:k}):o;if(a.isValidElement(d))return a.cloneElement(d,F(m,d.props))}return E.jsx("button",{...m,children:typeof o=="function"?o({isSelected:k}):o})},DownvoteButton:({asChild:l,children:o,onClick:c,...t})=>{const{handleDownvote:n,showPopover:s,isSubmitting:f,popoverId:i,triggerId:m,triggerRef:k,vote:d}=I(),g=a.useCallback(h=>{n(),c?.(h)},[n,c]),R={...t,ref:k,onClick:g,disabled:f||t.disabled,"aria-label":t["aria-label"]||"Downvote feedback","aria-expanded":s,"aria-controls":i,id:m,type:"button"},P=d==="downvote";if(l){const h=typeof o=="function"?o({isSelected:P}):o;if(a.isValidElement(h))return a.cloneElement(h,F(R,h.props));if(h)return h}return E.jsx("button",{...R,children:typeof o=="function"?o({isSelected:P}):o})},Popover:({asChild:l,children:o,...c})=>{const{showPopover:t,handleKeyDown:n,popoverId:s,triggerId:f}=I();if(!t)return null;const i={...c,role:"dialog","aria-labelledby":f,"aria-modal":!0,"aria-describedby":`${s}-description`,id:s,onKeyDown:n,tabIndex:-1};return l&&a.isValidElement(o)?E.jsxs(E.Fragment,{children:[a.cloneElement(o,F(i,o.props)),E.jsx("div",{id:`${s}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"})]}):E.jsxs("div",{...i,children:[E.jsx("div",{id:`${s}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"}),o]})},Textarea:({asChild:l,value:o,onChange:c,...t})=>{const{feedbackText:n,handleTextareaChange:s,textareaRef:f,handleKeyDown:i,popoverId:m}=I(),k={...t,ref:f,value:o!==void 0?o:n,onChange:c||s,onKeyDown:i,placeholder:t.placeholder||"What did we miss?","aria-label":t["aria-label"]||"Additional feedback","aria-describedby":`${m}-help`,rows:t.rows||3};return l&&a.isValidElement(t.children)?a.cloneElement(t.children,F(k,t.children.props)):E.jsx("textarea",{...k})},SubmitButton:({asChild:l,children:o,onClick:c,...t})=>{const{handleSubmit:n,isSubmitting:s,feedbackText:f}=I(),i=a.useCallback(g=>{n(),c?.(g)},[n,c]),m=f.trim().length>0,k=m?"Submit feedback":"Close without feedback",d={...t,onClick:i,disabled:s||t.disabled,type:"button","aria-label":t["aria-label"]||k,"aria-describedby":m?void 0:"submit-help"};return l&&a.isValidElement(o)?E.jsxs(E.Fragment,{children:[a.cloneElement(o,F(d,o.props)),!m&&E.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]}):E.jsxs("button",{...d,children:[o,!m&&E.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]})}};w.KeletContext=N,w.KeletProvider=fe,w.VoteFeedback=be,w.useDefaultFeedbackHandler=ee,w.useKelet=de,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
22
+ <%s key={someKey} {...props} />`,v,p,j,p),se[p+v]=!0)}if(p=null,b!==void 0&&(c(b),p=""+b),f(r)&&(c(r.key),p=""+r.key),"key"in r){b={};for(var Z in r)Z!=="key"&&(b[Z]=r[Z])}else b=r;return p&&i(b,typeof e=="function"?e.displayName||e.name||"Unknown":e),k(e,p,x,S,n(),b,G,X)}function g(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var R=a,P=Symbol.for("react.transitional.element"),h=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),B=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),M=Symbol.for("react.context"),W=Symbol.for("react.forward_ref"),J=Symbol.for("react.suspense"),D=Symbol.for("react.suspense_list"),z=Symbol.for("react.memo"),K=Symbol.for("react.lazy"),u=Symbol.for("react.activity"),y=Symbol.for("react.client.reference"),C=R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,V=Object.prototype.hasOwnProperty,U=Array.isArray,H=console.createTask?console.createTask:function(){return null};R={"react-stack-bottom-frame":function(e){return e()}};var ne,oe={},re=R["react-stack-bottom-frame"].bind(R,s)(),ae=H(t(s)),se={};O.Fragment=_,O.jsx=function(e,r,b,v,S){var x=1e4>C.recentlyCreatedOwnerStacks++;return d(e,r,b,!1,v,S,x?Error("react-stack-top-frame"):re,x?H(t(e)):ae)},O.jsxs=function(e,r,b,v,S){var x=1e4>C.recentlyCreatedOwnerStacks++;return d(e,r,b,!0,v,S,x?Error("react-stack-top-frame"):re,x?H(t(e)):ae)}}()),O}var $;function ie(){return $||($=1,process.env.NODE_ENV==="production"?Y.exports=le():Y.exports=ce()),Y.exports}var E=ie();const N=a.createContext(null),ue="https://api.kelet.ai/",de=()=>{const l=a.useContext(N);if(!l)throw new Error("useKelet must be used within a KeletProvider");return l},ee=()=>{const l=a.useContext(N);return l?l.feedback:async()=>{}},fe=({api_key:l,project:o,children:c})=>{const t=a.useContext(N),n=l||t?.api_key;if(!n)throw new Error("api_key is required either directly or from a parent KeletProvider");const f={api_key:n,project:o,feedback:async i=>{const m=`${ue}/projects/${o}/feedback`,k={tx_id:i.identifier,source:"EXPLICIT",vote:i.vote,explanation:i.explanation},d=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(k)});if(!d.ok)throw new Error(`Failed to submit feedback: ${d.statusText}`)}};return E.jsx(N.Provider,{value:f,children:c})},F=(l,o)=>{const c={...o};for(const t in o){const n=l[t],s=o[t];/^on[A-Z]/.test(t)?n&&s?c[t]=(...i)=>{s(...i),n(...i)}:n&&(c[t]=n):t==="style"?c[t]={...n,...s}:t==="className"?c[t]=[n,s].filter(Boolean).join(" "):c[t]=s!==void 0?s:n}return{...l,...c}},te=a.createContext(null),I=()=>{const l=a.useContext(te);if(!l)throw new Error("VoteFeedback components must be used within VoteFeedback.Root");return l},be={Root:({children:l,onFeedback:o,defaultText:c="",identifier:t,extra_metadata:n})=>{const[s,f]=a.useState(!1),[i,m]=a.useState(c),[k,d]=a.useState(!1),[g,R]=a.useState(null),P=a.useRef(null),h=a.useRef(null),_=a.useId(),B=a.useId(),L=ee(),T=o||L,M=a.useCallback(async()=>{R("upvote");const u={identifier:t,vote:"upvote",...n&&{extra_metadata:n}};try{d(!0),await T(u)}finally{d(!1)}},[T,t,n]),W=a.useCallback(async()=>{if(R("downvote"),T){const u={identifier:t,vote:"downvote",...n&&{extra_metadata:n}};try{d(!0),await T(u)}finally{d(!1)}}f(!0),setTimeout(()=>{P.current?.focus();const u=document.createElement("div");u.setAttribute("aria-live","polite"),u.setAttribute("aria-atomic","true"),u.className="sr-only",u.textContent="Feedback dialog opened. You can provide additional details about your downvote.",document.body.appendChild(u),setTimeout(()=>document.body.removeChild(u),1e3)},0)},[T,t,n]),J=a.useCallback(u=>{m(u.target.value)},[]),D=a.useCallback(async()=>{const u=i.trim().length>0;if(u){const y={identifier:t,vote:"downvote",explanation:i,...n&&{extra_metadata:n}};try{d(!0),await T(y)}finally{d(!1)}}if(f(!1),m(c),h.current?.focus(),u){const y=document.createElement("div");y.setAttribute("aria-live","polite"),y.className="sr-only",y.textContent="Feedback submitted successfully.",document.body.appendChild(y),setTimeout(()=>document.body.removeChild(y),1e3)}},[T,i,c,t,n]),z=a.useCallback(u=>{if(u.key==="Escape")f(!1),m(c),h.current?.focus();else if((u.metaKey||u.ctrlKey)&&u.key==="Enter")u.preventDefault(),D().then(y=>{});else if(u.key==="Tab"&&s){const y=document.getElementById(_);if(y){const C=y.querySelectorAll('button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'),V=C[0],U=C[C.length-1];u.shiftKey&&document.activeElement===V?(u.preventDefault(),U?.focus()):!u.shiftKey&&document.activeElement===U&&(u.preventDefault(),V?.focus())}}},[D,s,_,c]),K={onFeedback:T,showPopover:s,setShowPopover:f,feedbackText:i,setFeedbackText:m,isSubmitting:k,setIsSubmitting:d,vote:g,handleUpvote:M,handleDownvote:W,handleTextareaChange:J,handleSubmit:D,handleKeyDown:z,textareaRef:P,triggerRef:h,popoverId:_,triggerId:B,identifier:t,extra_metadata:n};return E.jsx(te.Provider,{value:K,children:l})},UpvoteButton:({asChild:l,children:o,onClick:c,...t})=>{const{handleUpvote:n,isSubmitting:s,vote:f}=I(),i=a.useCallback(d=>{n(),c?.(d)},[n,c]),m={...t,onClick:i,disabled:s||t.disabled,"aria-label":t["aria-label"]||"Upvote feedback",type:"button"},k=f==="upvote";if(l){const d=typeof o=="function"?o({isSelected:k}):o;if(a.isValidElement(d))return a.cloneElement(d,F(m,d.props))}return E.jsx("button",{...m,children:typeof o=="function"?o({isSelected:k}):o})},DownvoteButton:({asChild:l,children:o,onClick:c,...t})=>{const{handleDownvote:n,showPopover:s,isSubmitting:f,popoverId:i,triggerId:m,triggerRef:k,vote:d}=I(),g=a.useCallback(h=>{n(),c?.(h)},[n,c]),R={...t,ref:k,onClick:g,disabled:f||t.disabled,"aria-label":t["aria-label"]||"Downvote feedback","aria-expanded":s,"aria-controls":i,id:m,type:"button"},P=d==="downvote";if(l){const h=typeof o=="function"?o({isSelected:P}):o;if(a.isValidElement(h))return a.cloneElement(h,F(R,h.props));if(h)return h}return E.jsx("button",{...R,children:typeof o=="function"?o({isSelected:P}):o})},Popover:({asChild:l,children:o,...c})=>{const{showPopover:t,handleKeyDown:n,popoverId:s,triggerId:f}=I();if(!t)return null;const i={...c,role:"dialog","aria-labelledby":f,"aria-modal":!0,"aria-describedby":`${s}-description`,id:s,onKeyDown:n,tabIndex:-1};return l&&a.isValidElement(o)?E.jsxs(E.Fragment,{children:[a.cloneElement(o,F(i,o.props)),E.jsx("div",{id:`${s}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"})]}):E.jsxs("div",{...i,children:[E.jsx("div",{id:`${s}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"}),o]})},Textarea:({asChild:l,value:o,onChange:c,...t})=>{const{feedbackText:n,handleTextareaChange:s,textareaRef:f,handleKeyDown:i,popoverId:m}=I(),k={...t,ref:f,value:o!==void 0?o:n,onChange:c||s,onKeyDown:i,placeholder:t.placeholder||"What did we miss?","aria-label":t["aria-label"]||"Additional feedback","aria-describedby":`${m}-help`,rows:t.rows||3};return l&&a.isValidElement(t.children)?a.cloneElement(t.children,F(k,t.children.props)):E.jsx("textarea",{...k})},SubmitButton:({asChild:l,children:o,onClick:c,...t})=>{const{handleSubmit:n,isSubmitting:s,feedbackText:f}=I(),i=a.useCallback(g=>{n(),c?.(g)},[n,c]),m=f.trim().length>0,k=m?"Submit feedback":"Close without feedback",d={...t,onClick:i,disabled:s||t.disabled,type:"button","aria-label":t["aria-label"]||k,"aria-describedby":m?void 0:"submit-help"};return l&&a.isValidElement(o)?E.jsxs(E.Fragment,{children:[a.cloneElement(o,F(d,o.props)),!m&&E.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]}):E.jsxs("button",{...d,children:[o,!m&&E.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]})}};w.KeletContext=N,w.KeletProvider=fe,w.VoteFeedback=be,w.useDefaultFeedbackHandler=ee,w.useKelet=de,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kelet-ai/feedback-ui",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/kelet-ai/feedback-ui.git"