@kelet-ai/feedback-ui 0.2.1 → 0.2.2

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,4 +1,4 @@
1
- (function(w,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],a):(w=typeof globalThis<"u"?globalThis:w||self,a(w["@kelet-ai/feedback-ui"]={},w.React))})(this,function(w,a){"use strict";var Y={exports:{}},A={};/**
1
+ (function(Y,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],x):(Y=typeof globalThis<"u"?globalThis:Y||self,x(Y["@kelet-ai/feedback-ui"]={},Y.React))})(this,function(Y,x){"use strict";function Ee(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Pe(r){if(Object.prototype.hasOwnProperty.call(r,"__esModule"))return r;var e=r.default;if(typeof e=="function"){var n=function t(){var s=!1;try{s=this instanceof t}catch{}return s?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(r).forEach(function(t){var s=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(n,t,s.get?s:{enumerable:!0,get:function(){return r[t]}})}),n}var ee={exports:{}},X={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -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 Q;function le(){if(Q)return A;Q=1;var l=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function c(t,n,s){var f=null;if(s!==void 0&&(f=""+s),n.key!==void 0&&(f=""+n.key),"key"in n){s={};for(var i in n)i!=="key"&&(s[i]=n[i])}else s=n;return n=s.ref,{$$typeof:l,type:t,key:f,ref:n!==void 0?n:null,props:s}}return A.Fragment=o,A.jsx=c,A.jsxs=c,A}var O={};/**
9
+ */var ae;function xe(){if(ae)return X;ae=1;var r=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(t,s,u){var f=null;if(u!==void 0&&(f=""+u),s.key!==void 0&&(f=""+s.key),"key"in s){u={};for(var c in s)c!=="key"&&(u[c]=s[c])}else u=s;return s=u.ref,{$$typeof:r,type:t,key:f,ref:s!==void 0?s:null,props:u}}return X.Fragment=e,X.jsx=n,X.jsxs=n,X}var Z={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,9 +14,23 @@
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 q;function ce(){return q||(q=1,process.env.NODE_ENV!=="production"&&function(){function l(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===y?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case _:return"Fragment";case L:return"Profiler";case B:return"StrictMode";case J:return"Suspense";case D:return"SuspenseList";case u:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case h:return"Portal";case M:return(e.displayName||"Context")+".Provider";case T:return(e._context.displayName||"Context")+".Consumer";case W:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case z:return r=e.displayName||null,r!==null?r:l(e.type)||"Memo";case K:r=e._payload,e=e._init;try{return l(e(r))}catch{}}return null}function o(e){return""+e}function c(e){try{o(e);var r=!1}catch{r=!0}if(r){r=console;var b=r.error,v=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return b.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",v),o(e)}}function t(e){if(e===_)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===K)return"<...>";try{var r=l(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function n(){var e=C.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function f(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function i(e,r){function b(){ne||(ne=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}b.isReactWarning=!0,Object.defineProperty(e,"key",{get:b,configurable:!0})}function m(){var e=l(this.type);return oe[e]||(oe[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function k(e,r,b,v,S,x,G,X){return b=x.ref,e={$$typeof:P,type:e,key:r,props:x,_owner:S},(b!==void 0?b:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:m}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,r,b,v,S,x,G,X){var p=r.children;if(p!==void 0)if(v)if(U(p)){for(v=0;v<p.length;v++)g(p[v]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else g(p);if(V.call(r,"key")){p=l(e);var j=Object.keys(r).filter(function(me){return me!=="key"});v=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",se[p+v]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var le;function Te(){return le||(le=1,process.env.NODE_ENV!=="production"&&function(){function r(a){if(a==null)return null;if(typeof a=="function")return a.$$typeof===o?null:a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case k:return"Fragment";case D:return"Profiler";case A:return"StrictMode";case P:return"Suspense";case L:return"SuspenseList";case l:return"Activity"}if(typeof a=="object")switch(typeof a.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),a.$$typeof){case m:return"Portal";case w:return(a.displayName||"Context")+".Provider";case h:return(a._context.displayName||"Context")+".Consumer";case R:var C=a.render;return a=a.displayName,a||(a=C.displayName||C.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case N:return C=a.displayName||null,C!==null?C:r(a.type)||"Memo";case i:C=a._payload,a=a._init;try{return r(a(C))}catch{}}return null}function e(a){return""+a}function n(a){try{e(a);var C=!1}catch{C=!0}if(C){C=console;var _=C.error,j=typeof Symbol=="function"&&Symbol.toStringTag&&a[Symbol.toStringTag]||a.constructor.name||"Object";return _.call(C,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",j),e(a)}}function t(a){if(a===k)return"<>";if(typeof a=="object"&&a!==null&&a.$$typeof===i)return"<...>";try{var C=r(a);return C?"<"+C+">":"<...>"}catch{return"<...>"}}function s(){var a=p.A;return a===null?null:a.getOwner()}function u(){return Error("react-stack-top-frame")}function f(a){if(v.call(a,"key")){var C=Object.getOwnPropertyDescriptor(a,"key").get;if(C&&C.isReactWarning)return!1}return a.key!==void 0}function c(a,C){function _(){K||(K=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",C))}_.isReactWarning=!0,Object.defineProperty(a,"key",{get:_,configurable:!0})}function d(){var a=r(this.type);return F[a]||(F[a]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),a=this.props.ref,a!==void 0?a:null}function y(a,C,_,j,z,W,G,J){return _=W.ref,a={$$typeof:g,type:a,key:C,props:W,_owner:z},(_!==void 0?_:null)!==null?Object.defineProperty(a,"ref",{enumerable:!1,get:d}):Object.defineProperty(a,"ref",{enumerable:!1,value:null}),a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(a,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(a,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(a,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a}function b(a,C,_,j,z,W,G,J){var I=C.children;if(I!==void 0)if(j)if(S(I)){for(j=0;j<I.length;j++)E(I[j]);Object.freeze&&Object.freeze(I)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else E(I);if(v.call(C,"key")){I=r(a);var U=Object.keys(C).filter(function(Qe){return Qe!=="key"});j=0<U.length?"{key: someKey, "+U.join(": ..., ")+": ...}":"{key: someKey}",re[I+j]||(U=0<U.length?"{"+U.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
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.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} />`,j,I,U,I),re[I+j]=!0)}if(I=null,_!==void 0&&(n(_),I=""+_),f(C)&&(n(C.key),I=""+C.key),"key"in C){_={};for(var ie in C)ie!=="key"&&(_[ie]=C[ie])}else _=C;return I&&c(_,typeof a=="function"?a.displayName||a.name||"Unknown":a),y(a,I,W,z,s(),_,G,J)}function E(a){typeof a=="object"&&a!==null&&a.$$typeof===g&&a._store&&(a._store.validated=1)}var O=x,g=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),w=Symbol.for("react.context"),R=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),N=Symbol.for("react.memo"),i=Symbol.for("react.lazy"),l=Symbol.for("react.activity"),o=Symbol.for("react.client.reference"),p=O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,v=Object.prototype.hasOwnProperty,S=Array.isArray,T=console.createTask?console.createTask:function(){return null};O={react_stack_bottom_frame:function(a){return a()}};var K,F={},V=O.react_stack_bottom_frame.bind(O,u)(),B=T(t(u)),re={};Z.Fragment=k,Z.jsx=function(a,C,_,j,z){var W=1e4>p.recentlyCreatedOwnerStacks++;return b(a,C,_,!1,j,z,W?Error("react-stack-top-frame"):V,W?T(t(a)):B)},Z.jsxs=function(a,C,_,j,z){var W=1e4>p.recentlyCreatedOwnerStacks++;return b(a,C,_,!0,j,z,W?Error("react-stack-top-frame"):V,W?T(t(a)):B)}}()),Z}var ue;function Ce(){return ue||(ue=1,process.env.NODE_ENV==="production"?ee.exports=xe():ee.exports=Te()),ee.exports}var M=Ce();const Q=x.createContext(null),Re="https://api.kelet.ai/",Oe=()=>{const r=x.useContext(Q);if(!r)throw new Error("useKelet must be used within a KeletProvider");return r},oe=()=>{const r=x.useContext(Q);return r?r.feedback:async()=>{}},Se=({api_key:r,project:e,children:n})=>{const t=x.useContext(Q),s=r||t?.api_key;if(!s)throw new Error("api_key is required either directly or from a parent KeletProvider");const f={api_key:s,project:e,feedback:async c=>{const d=`${Re}/projects/${e}/feedback`,y={tx_id:c.identifier,source:c.source||"EXPLICIT",vote:c.vote,explanation:c.explanation,correction:c.correction,selection:c.selection},b=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify(y)});if(!b.ok)throw new Error(`Failed to submit feedback: ${b.statusText}`)}};return M.jsx(Q.Provider,{value:f,children:n})},q=(r,e)=>{const n={...e};for(const t in e){const s=r[t],u=e[t];/^on[A-Z]/.test(t)?s&&u?n[t]=(...c)=>{u(...c),s(...c)}:s&&(n[t]=s):t==="style"?n[t]={...s,...u}:t==="className"?n[t]=[s,u].filter(Boolean).join(" "):n[t]=u!==void 0?u:s}return{...r,...n}},ce=x.createContext(null),$=()=>{const r=x.useContext(ce);if(!r)throw new Error("VoteFeedback components must be used within VoteFeedback.Root");return r},Ae={Root:({children:r,onFeedback:e,defaultText:n="",identifier:t,extra_metadata:s,trigger_name:u})=>{const[f,c]=x.useState(!1),[d,y]=x.useState(n),[b,E]=x.useState(!1),[O,g]=x.useState(null),m=x.useRef(null),k=x.useRef(null),A=x.useId(),D=x.useId(),h=oe(),w=e||h,R=x.useCallback(async()=>{g("upvote");const o={identifier:t,vote:"upvote",...s&&{extra_metadata:s},...u&&{trigger_name:u}};try{E(!0),await w(o)}finally{E(!1)}},[w,t,s,u]),P=x.useCallback(async()=>{if(g("downvote"),w){const o={identifier:t,vote:"downvote",...s&&{extra_metadata:s},...u&&{trigger_name:u}};try{E(!0),await w(o)}finally{E(!1)}}c(!0),setTimeout(()=>{m.current?.focus();const o=document.createElement("div");o.setAttribute("aria-live","polite"),o.setAttribute("aria-atomic","true"),o.className="sr-only",o.textContent="Feedback dialog opened. You can provide additional details about your downvote.",document.body.appendChild(o),setTimeout(()=>document.body.removeChild(o),1e3)},0)},[w,t,s,u]),L=x.useCallback(o=>{y(o.target.value)},[]),N=x.useCallback(async()=>{const o=d.trim().length>0;if(o){const p={identifier:t,vote:"downvote",explanation:d,...s&&{extra_metadata:s},...u&&{trigger_name:u}};try{E(!0),await w(p)}finally{E(!1)}}if(c(!1),y(n),k.current?.focus(),o){const p=document.createElement("div");p.setAttribute("aria-live","polite"),p.className="sr-only",p.textContent="Feedback submitted successfully.",document.body.appendChild(p),setTimeout(()=>document.body.removeChild(p),1e3)}},[w,d,n,t,s,u]),i=x.useCallback(o=>{if(o.key==="Escape")c(!1),y(n),k.current?.focus();else if((o.metaKey||o.ctrlKey)&&o.key==="Enter")o.preventDefault(),N().then(p=>{});else if(o.key==="Tab"&&f){const p=document.getElementById(A);if(p){const v=p.querySelectorAll('button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'),S=v[0],T=v[v.length-1];o.shiftKey&&document.activeElement===S?(o.preventDefault(),T?.focus()):!o.shiftKey&&document.activeElement===T&&(o.preventDefault(),S?.focus())}}},[N,f,A,n]),l={onFeedback:w,showPopover:f,setShowPopover:c,feedbackText:d,setFeedbackText:y,isSubmitting:b,setIsSubmitting:E,vote:O,handleUpvote:R,handleDownvote:P,handleTextareaChange:L,handleSubmit:N,handleKeyDown:i,textareaRef:m,triggerRef:k,popoverId:A,triggerId:D,identifier:t,extra_metadata:s,trigger_name:u};return M.jsx(ce.Provider,{value:l,children:r})},UpvoteButton:({asChild:r,children:e,onClick:n,...t})=>{const{handleUpvote:s,isSubmitting:u,vote:f}=$(),c=x.useCallback(b=>{s(),n?.(b)},[s,n]),d={...t,onClick:c,disabled:u||t.disabled,"aria-label":t["aria-label"]||"Upvote feedback",type:"button"},y=f==="upvote";if(r){const b=typeof e=="function"?e({isSelected:y}):e;if(x.isValidElement(b))return x.cloneElement(b,q(d,b.props))}return M.jsx("button",{...d,children:typeof e=="function"?e({isSelected:y}):e})},DownvoteButton:({asChild:r,children:e,onClick:n,...t})=>{const{handleDownvote:s,showPopover:u,isSubmitting:f,popoverId:c,triggerId:d,triggerRef:y,vote:b}=$(),E=x.useCallback(m=>{s(),n?.(m)},[s,n]),O={...t,ref:y,onClick:E,disabled:f||t.disabled,"aria-label":t["aria-label"]||"Downvote feedback","aria-expanded":u,"aria-controls":c,id:d,type:"button"},g=b==="downvote";if(r){const m=typeof e=="function"?e({isSelected:g}):e;if(x.isValidElement(m))return x.cloneElement(m,q(O,m.props));if(m)return m}return M.jsx("button",{...O,children:typeof e=="function"?e({isSelected:g}):e})},Popover:({asChild:r,children:e,...n})=>{const{showPopover:t,handleKeyDown:s,popoverId:u,triggerId:f}=$();if(!t)return null;const c={...n,role:"dialog","aria-labelledby":f,"aria-modal":!0,"aria-describedby":`${u}-description`,id:u,onKeyDown:s,tabIndex:-1};return r&&x.isValidElement(e)?M.jsxs(M.Fragment,{children:[x.cloneElement(e,q(c,e.props)),M.jsx("div",{id:`${u}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"})]}):M.jsxs("div",{...c,children:[M.jsx("div",{id:`${u}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"}),e]})},Textarea:({asChild:r,value:e,onChange:n,...t})=>{const{feedbackText:s,handleTextareaChange:u,textareaRef:f,handleKeyDown:c,popoverId:d}=$(),y={...t,ref:f,value:e!==void 0?e:s,onChange:n||u,onKeyDown:c,placeholder:t.placeholder||"What did we miss?","aria-label":t["aria-label"]||"Additional feedback","aria-describedby":`${d}-help`,rows:t.rows||3};return r&&x.isValidElement(t.children)?x.cloneElement(t.children,q(y,t.children.props)):M.jsx("textarea",{...y})},SubmitButton:({asChild:r,children:e,onClick:n,...t})=>{const{handleSubmit:s,isSubmitting:u,feedbackText:f}=$(),c=x.useCallback(E=>{s(),n?.(E)},[s,n]),d=f.trim().length>0,y=d?"Submit feedback":"Close without feedback",b={...t,onClick:c,disabled:u||t.disabled,type:"button","aria-label":t["aria-label"]||y,"aria-describedby":d?void 0:"submit-help"};return r&&x.isValidElement(e)?M.jsxs(M.Fragment,{children:[x.cloneElement(e,q(b,e.props)),!d&&M.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]}):M.jsxs("button",{...b,children:[e,!d&&M.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]})}};var te={exports:{}},De=te.exports,fe;function _e(){return fe||(fe=1,function(r,e){(function(n,t){var s=t(n);r.exports=s})(De,function(n){var t=["N","E","A","D"];function s(i,l){i.super_=l,i.prototype=Object.create(l.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}})}function u(i,l){Object.defineProperty(this,"kind",{value:i,enumerable:!0}),l&&l.length&&Object.defineProperty(this,"path",{value:l,enumerable:!0})}function f(i,l,o){f.super_.call(this,"E",i),Object.defineProperty(this,"lhs",{value:l,enumerable:!0}),Object.defineProperty(this,"rhs",{value:o,enumerable:!0})}s(f,u);function c(i,l){c.super_.call(this,"N",i),Object.defineProperty(this,"rhs",{value:l,enumerable:!0})}s(c,u);function d(i,l){d.super_.call(this,"D",i),Object.defineProperty(this,"lhs",{value:l,enumerable:!0})}s(d,u);function y(i,l,o){y.super_.call(this,"A",i),Object.defineProperty(this,"index",{value:l,enumerable:!0}),Object.defineProperty(this,"item",{value:o,enumerable:!0})}s(y,u);function b(i,l,o){var p=i.slice(l+1||i.length);return i.length=l<0?i.length+l:l,i.push.apply(i,p),i}function E(i){var l=typeof i;return l!=="object"?l:i===Math?"math":i===null?"null":Array.isArray(i)?"array":Object.prototype.toString.call(i)==="[object Date]"?"date":typeof i.toString=="function"&&/^\/.*\//.test(i.toString())?"regexp":"object"}function O(i){var l=0;if(i.length===0)return l;for(var o=0;o<i.length;o++){var p=i.charCodeAt(o);l=(l<<5)-l+p,l=l&l}return l}function g(i){var l=0,o=E(i);if(o==="array"){i.forEach(function(K){l+=g(K)});var p="[type: array, hash: "+l+"]";return l+O(p)}if(o==="object"){for(var v in i)if(i.hasOwnProperty(v)){var S="[ type: object, key: "+v+", value hash: "+g(i[v])+"]";l+=O(S)}return l}var T="[ type: "+o+" ; value: "+i+"]";return l+O(T)}function m(i,l,o,p,v,S,T,K){o=o||[],v=v||[],T=T||[];var F=v.slice(0);if(typeof S<"u"&&S!==null){if(p){if(typeof p=="function"&&p(F,S))return;if(typeof p=="object"){if(p.prefilter&&p.prefilter(F,S))return;if(p.normalize){var V=p.normalize(F,S,i,l);V&&(i=V[0],l=V[1])}}}F.push(S)}E(i)==="regexp"&&E(l)==="regexp"&&(i=i.toString(),l=l.toString());var B=typeof i,re=typeof l,a,C,_,j,z=B!=="undefined"||T&&T.length>0&&T[T.length-1].lhs&&Object.getOwnPropertyDescriptor(T[T.length-1].lhs,S),W=re!=="undefined"||T&&T.length>0&&T[T.length-1].rhs&&Object.getOwnPropertyDescriptor(T[T.length-1].rhs,S);if(!z&&W)o.push(new c(F,l));else if(!W&&z)o.push(new d(F,i));else if(E(i)!==E(l))o.push(new f(F,i,l));else if(E(i)==="date"&&i-l!==0)o.push(new f(F,i,l));else if(B==="object"&&i!==null&&l!==null){for(a=T.length-1;a>-1;--a)if(T[a].lhs===i){j=!0;break}if(j)i!==l&&o.push(new f(F,i,l));else{if(T.push({lhs:i,rhs:l}),Array.isArray(i)){for(K&&(i.sort(function(I,U){return g(I)-g(U)}),l.sort(function(I,U){return g(I)-g(U)})),a=l.length-1,C=i.length-1;a>C;)o.push(new y(F,a,new c(void 0,l[a--])));for(;C>a;)o.push(new y(F,C,new d(void 0,i[C--])));for(;a>=0;--a)m(i[a],l[a],o,p,F,a,T,K)}else{var G=Object.keys(i),J=Object.keys(l);for(a=0;a<G.length;++a)_=G[a],j=J.indexOf(_),j>=0?(m(i[_],l[_],o,p,F,_,T,K),J[j]=null):m(i[_],void 0,o,p,F,_,T,K);for(a=0;a<J.length;++a)_=J[a],_&&m(void 0,l[_],o,p,F,_,T,K)}T.length=T.length-1}}else i!==l&&(B==="number"&&isNaN(i)&&isNaN(l)||o.push(new f(F,i,l)))}function k(i,l,o,p,v){var S=[];if(m(i,l,S,p,null,null,null,v),o)for(var T=0;T<S.length;++T)o(S[T]);return S}function A(i,l,o,p,v,S,T){return m(i,l,o,p,v,S,T,!0)}function D(i,l,o,p){var v=p?function(T){T&&p.push(T)}:void 0,S=k(i,l,v,o);return p||(S.length?S:void 0)}function h(i,l,o,p){var v=p?function(T){T&&p.push(T)}:void 0,S=k(i,l,v,o,!0);return p||(S.length?S:void 0)}function w(i,l,o){if(o.path&&o.path.length){var p=i[l],v,S=o.path.length-1;for(v=0;v<S;v++)p=p[o.path[v]];switch(o.kind){case"A":w(p[o.path[v]],o.index,o.item);break;case"D":delete p[o.path[v]];break;case"E":case"N":p[o.path[v]]=o.rhs;break}}else switch(o.kind){case"A":w(i[l],o.index,o.item);break;case"D":i=b(i,l);break;case"E":case"N":i[l]=o.rhs;break}return i}function R(i,l,o){if(typeof o>"u"&&l&&~t.indexOf(l.kind)&&(o=l),i&&o&&o.kind){for(var p=i,v=-1,S=o.path?o.path.length-1:0;++v<S;)typeof p[o.path[v]]>"u"&&(p[o.path[v]]=typeof o.path[v+1]<"u"&&typeof o.path[v+1]=="number"?[]:{}),p=p[o.path[v]];switch(o.kind){case"A":o.path&&typeof p[o.path[v]]>"u"&&(p[o.path[v]]=[]),w(o.path?p[o.path[v]]:p,o.index,o.item);break;case"D":delete p[o.path[v]];break;case"E":case"N":p[o.path[v]]=o.rhs;break}}}function P(i,l,o){if(o.path&&o.path.length){var p=i[l],v,S=o.path.length-1;for(v=0;v<S;v++)p=p[o.path[v]];switch(o.kind){case"A":P(p[o.path[v]],o.index,o.item);break;case"D":p[o.path[v]]=o.lhs;break;case"E":p[o.path[v]]=o.lhs;break;case"N":delete p[o.path[v]];break}}else switch(o.kind){case"A":P(i[l],o.index,o.item);break;case"D":i[l]=o.lhs;break;case"E":i[l]=o.lhs;break;case"N":i=b(i,l);break}return i}function L(i,l,o){if(i&&l&&o&&o.kind){var p=i,v,S;for(S=o.path.length-1,v=0;v<S;v++)typeof p[o.path[v]]>"u"&&(p[o.path[v]]={}),p=p[o.path[v]];switch(o.kind){case"A":P(p[o.path[v]],o.index,o.item);break;case"D":p[o.path[v]]=o.lhs;break;case"E":p[o.path[v]]=o.lhs;break;case"N":delete p[o.path[v]];break}}}function N(i,l,o){if(i&&l){var p=function(v){(!o||o(i,l,v))&&R(i,l,v)};k(i,l,p)}}return Object.defineProperties(D,{diff:{value:D,enumerable:!0},orderIndependentDiff:{value:h,enumerable:!0},observableDiff:{value:k,enumerable:!0},orderIndependentObservableDiff:{value:A,enumerable:!0},orderIndepHash:{value:g,enumerable:!0},applyDiff:{value:N,enumerable:!0},applyChange:{value:R,enumerable:!0},revertChange:{value:L,enumerable:!0},isConflict:{value:function(){return typeof $conflict<"u"},enumerable:!0}}),D.DeepDiff=D,n&&(n.DeepDiff=D),D})}(te)),te.exports}var de=_e(),ne={exports:{}};const H=new Uint32Array(65536),je=(r,e)=>{const n=r.length,t=e.length,s=1<<n-1;let u=-1,f=0,c=n,d=n;for(;d--;)H[r.charCodeAt(d)]|=1<<d;for(d=0;d<t;d++){let y=H[e.charCodeAt(d)];const b=y|f;y|=(y&u)+u^u,f|=~(y|u),u&=y,f&s&&c++,u&s&&c--,f=f<<1|1,u=u<<1|~(b|f),f&=b}for(d=n;d--;)H[r.charCodeAt(d)]=0;return c},Ne=(r,e)=>{const n=e.length,t=r.length,s=[],u=[],f=Math.ceil(n/32),c=Math.ceil(t/32);for(let m=0;m<f;m++)u[m]=-1,s[m]=0;let d=0;for(;d<c-1;d++){let m=0,k=-1;const A=d*32,D=Math.min(32,t)+A;for(let h=A;h<D;h++)H[r.charCodeAt(h)]|=1<<h;for(let h=0;h<n;h++){const w=H[e.charCodeAt(h)],R=u[h/32|0]>>>h&1,P=s[h/32|0]>>>h&1,L=w|m,N=((w|P)&k)+k^k|w|P;let i=m|~(N|k),l=k&N;i>>>31^R&&(u[h/32|0]^=1<<h),l>>>31^P&&(s[h/32|0]^=1<<h),i=i<<1|R,l=l<<1|P,k=l|~(L|i),m=i&L}for(let h=A;h<D;h++)H[r.charCodeAt(h)]=0}let y=0,b=-1;const E=d*32,O=Math.min(32,t-E)+E;for(let m=E;m<O;m++)H[r.charCodeAt(m)]|=1<<m;let g=t;for(let m=0;m<n;m++){const k=H[e.charCodeAt(m)],A=u[m/32|0]>>>m&1,D=s[m/32|0]>>>m&1,h=k|y,w=((k|D)&b)+b^b|k|D;let R=y|~(w|b),P=b&w;g+=R>>>t-1&1,g-=P>>>t-1&1,R>>>31^A&&(u[m/32|0]^=1<<m),P>>>31^D&&(s[m/32|0]^=1<<m),R=R<<1|A,P=P<<1|D,b=P|~(h|R),y=R&h}for(let m=E;m<O;m++)H[r.charCodeAt(m)]=0;return g},pe=(r,e)=>{if(r.length<e.length){const n=e;e=r,r=n}return e.length===0?r.length:r.length<=32?je(r,e):Ne(r,e)},Ie=Pe(Object.freeze(Object.defineProperty({__proto__:null,closest:(r,e)=>{let n=1/0,t=0;for(let s=0;s<e.length;s++){const u=pe(r,e[s]);u<n&&(n=u,t=s)}return e[t]},distance:pe},Symbol.toStringTag,{value:"Module"})));var he;function Fe(){return he||(he=1,function(r,e){(function(){var n;try{n=typeof Intl<"u"&&typeof Intl.Collator<"u"?Intl.Collator("generic",{sensitivity:"base"}):null}catch{console.log("Collator could not be initialized and wouldn't be used")}var t=Ie,s=[],u=[],f={get:function(c,d,y){var b=y&&n&&y.useCollator;if(b){var E=c.length,O=d.length;if(E===0)return O;if(O===0)return E;var g,m,k,A,D;for(k=0;k<O;++k)s[k]=k,u[k]=d.charCodeAt(k);s[O]=O;var h;for(k=0;k<E;++k){for(m=k+1,A=0;A<O;++A)g=m,h=n.compare(c.charAt(k),String.fromCharCode(u[A]))===0,m=s[A]+(h?0:1),D=g+1,m>D&&(m=D),D=s[A+1]+1,m>D&&(m=D),s[A]=g;s[A]=m}return m}return t.distance(c,d)}};r!==null&&r.exports===e?r.exports=f:typeof self<"u"&&typeof self.postMessage=="function"&&typeof self.importScripts=="function"?self.Levenshtein=f:typeof window<"u"&&window!==null&&(window.Levenshtein=f)})()}(ne,ne.exports)),ne.exports}var Le=Fe();const Me=Ee(Le);class We{diff(e,n,t={}){let s;typeof t=="function"?(s=t,t={}):"callback"in t&&(s=t.callback);const u=this.castInput(e,t),f=this.castInput(n,t),c=this.removeEmpty(this.tokenize(u,t)),d=this.removeEmpty(this.tokenize(f,t));return this.diffWithOptionsObj(c,d,t,s)}diffWithOptionsObj(e,n,t,s){var u;const f=h=>{if(h=this.postProcess(h,t),s){setTimeout(function(){s(h)},0);return}else return h},c=n.length,d=e.length;let y=1,b=c+d;t.maxEditLength!=null&&(b=Math.min(b,t.maxEditLength));const E=(u=t.timeout)!==null&&u!==void 0?u:1/0,O=Date.now()+E,g=[{oldPos:-1,lastComponent:void 0}];let m=this.extractCommon(g[0],n,e,0,t);if(g[0].oldPos+1>=d&&m+1>=c)return f(this.buildValues(g[0].lastComponent,n,e));let k=-1/0,A=1/0;const D=()=>{for(let h=Math.max(k,-y);h<=Math.min(A,y);h+=2){let w;const R=g[h-1],P=g[h+1];R&&(g[h-1]=void 0);let L=!1;if(P){const i=P.oldPos-h;L=P&&0<=i&&i<c}const N=R&&R.oldPos+1<d;if(!L&&!N){g[h]=void 0;continue}if(!N||L&&R.oldPos<P.oldPos?w=this.addToPath(P,!0,!1,0,t):w=this.addToPath(R,!1,!0,1,t),m=this.extractCommon(w,n,e,h,t),w.oldPos+1>=d&&m+1>=c)return f(this.buildValues(w.lastComponent,n,e))||!0;g[h]=w,w.oldPos+1>=d&&(A=Math.min(A,h-1)),m+1>=c&&(k=Math.max(k,h+1))}y++};if(s)(function h(){setTimeout(function(){if(y>b||Date.now()>O)return s(void 0);D()||h()},0)})();else for(;y<=b&&Date.now()<=O;){const h=D();if(h)return h}}addToPath(e,n,t,s,u){const f=e.lastComponent;return f&&!u.oneChangePerToken&&f.added===n&&f.removed===t?{oldPos:e.oldPos+s,lastComponent:{count:f.count+1,added:n,removed:t,previousComponent:f.previousComponent}}:{oldPos:e.oldPos+s,lastComponent:{count:1,added:n,removed:t,previousComponent:f}}}extractCommon(e,n,t,s,u){const f=n.length,c=t.length;let d=e.oldPos,y=d-s,b=0;for(;y+1<f&&d+1<c&&this.equals(t[d+1],n[y+1],u);)y++,d++,b++,u.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return b&&!u.oneChangePerToken&&(e.lastComponent={count:b,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=d,y}equals(e,n,t){return t.comparator?t.comparator(e,n):e===n||!!t.ignoreCase&&e.toLowerCase()===n.toLowerCase()}removeEmpty(e){const n=[];for(let t=0;t<e.length;t++)e[t]&&n.push(e[t]);return n}castInput(e,n){return e}tokenize(e,n){return Array.from(e)}join(e){return e.join("")}postProcess(e,n){return e}get useLongestToken(){return!1}buildValues(e,n,t){const s=[];let u;for(;e;)s.push(e),u=e.previousComponent,delete e.previousComponent,e=u;s.reverse();const f=s.length;let c=0,d=0,y=0;for(;c<f;c++){const b=s[c];if(b.removed)b.value=this.join(t.slice(y,y+b.count)),y+=b.count;else{if(!b.added&&this.useLongestToken){let E=n.slice(d,d+b.count);E=E.map(function(O,g){const m=t[y+g];return m.length>O.length?m:O}),b.value=this.join(E)}else b.value=this.join(n.slice(d,d+b.count));d+=b.count,b.added||(y+=b.count)}}return s}}class Ye extends We{constructor(){super(...arguments),this.tokenize=Ke}equals(e,n,t){return t.ignoreWhitespace?((!t.newlineIsToken||!e.includes(`
23
+ `))&&(e=e.trim()),(!t.newlineIsToken||!n.includes(`
24
+ `))&&(n=n.trim())):t.ignoreNewlineAtEof&&!t.newlineIsToken&&(e.endsWith(`
25
+ `)&&(e=e.slice(0,-1)),n.endsWith(`
26
+ `)&&(n=n.slice(0,-1))),super.equals(e,n,t)}}const ze=new Ye;function me(r,e,n){return ze.diff(r,e,n)}function Ke(r,e){e.stripTrailingCr&&(r=r.replace(/\r\n/g,`
27
+ `));const n=[],t=r.split(/(\n|\r\n)/);t[t.length-1]||t.pop();for(let s=0;s<t.length;s++){const u=t[s];s%2&&!e.newlineIsToken?n[n.length-1]+=u:n.push(u)}return n}function be(r,e,n,t,s,u,f){let c;f?typeof f=="function"?c={callback:f}:c=f:c={},typeof c.context>"u"&&(c.context=4);const d=c.context;if(c.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(c.callback){const{callback:b}=c;me(n,t,Object.assign(Object.assign({},c),{callback:E=>{const O=y(E);b(O)}}))}else return y(me(n,t,c));function y(b){if(!b)return;b.push({value:"",lines:[]});function E(h){return h.map(function(w){return" "+w})}const O=[];let g=0,m=0,k=[],A=1,D=1;for(let h=0;h<b.length;h++){const w=b[h],R=w.lines||He(w.value);if(w.lines=R,w.added||w.removed){if(!g){const P=b[h-1];g=A,m=D,P&&(k=d>0?E(P.lines.slice(-d)):[],g-=k.length,m-=k.length)}for(const P of R)k.push((w.added?"+":"-")+P);w.added?D+=R.length:A+=R.length}else{if(g)if(R.length<=d*2&&h<b.length-2)for(const P of E(R))k.push(P);else{const P=Math.min(R.length,d);for(const N of E(R.slice(0,P)))k.push(N);const L={oldStart:g,oldLines:A-g+P,newStart:m,newLines:D-m+P,lines:k};O.push(L),g=0,m=0,k=[]}A+=R.length,D+=R.length}}for(const h of O)for(let w=0;w<h.lines.length;w++)h.lines[w].endsWith(`
28
+ `)?h.lines[w]=h.lines[w].slice(0,-1):(h.lines.splice(w+1,0,"\"),w++);return{oldFileName:r,newFileName:e,oldHeader:s,newHeader:u,hunks:O}}}function se(r){if(Array.isArray(r))return r.map(se).join(`
29
+ `);const e=[];r.oldFileName==r.newFileName&&e.push("Index: "+r.oldFileName),e.push("==================================================================="),e.push("--- "+r.oldFileName+(typeof r.oldHeader>"u"?"":" "+r.oldHeader)),e.push("+++ "+r.newFileName+(typeof r.newHeader>"u"?"":" "+r.newHeader));for(let n=0;n<r.hunks.length;n++){const t=r.hunks[n];t.oldLines===0&&(t.oldStart-=1),t.newLines===0&&(t.newStart-=1),e.push("@@ -"+t.oldStart+","+t.oldLines+" +"+t.newStart+","+t.newLines+" @@");for(const s of t.lines)e.push(s)}return e.join(`
30
+ `)+`
31
+ `}function Ue(r,e,n,t,s,u,f){if(typeof f=="function"&&(f={callback:f}),f?.callback){const{callback:c}=f;be(r,e,n,t,s,u,Object.assign(Object.assign({},f),{callback:d=>{c(d?se(d):void 0)}}))}else{const c=be(r,e,n,t,s,u,f);return c?se(c):void 0}}function He(r){const e=r.endsWith(`
32
+ `),n=r.split(`
33
+ `).map(t=>t+`
34
+ `);return e?n.pop():n.push(n.pop().slice(0,-1)),n}function Je(r,e,n="git",t=3){switch(n){case"git":return ve(r,e,t);case"object":return Ve(r,e);case"json":return Be(r,e);default:return ve(r,e,t)}}function ve(r,e,n=3){const t=ge(r),s=ge(e);return Ue("","",t,s,"","",{context:n}).split(`
35
+ `).slice(2).join(`
36
+ `)}function Ve(r,e){const n=de.diff(r,e)||[];return JSON.stringify(n,null,2)}function Be(r,e){return JSON.stringify({before:r,after:e},null,2)}function Ge(r,e){return typeof r=="string"&&typeof e=="string"?ye(r,e):typeof r=="number"&&typeof e=="number"?we(r,e):Xe(r,e)}function ye(r,e){if(r===e)return 0;if(r.length===0||e.length===0)return 1;const n=Me.get(r,e),t=Math.max(r.length,e.length);return n/t}function we(r,e){if(r===e)return 0;if(r===0)return 1;const n=Math.abs(e-r),t=Math.max(Math.abs(r),Math.abs(e));return Math.min(n/t,1)}function Xe(r,e){if(r===e)return 0;const n=de.diff(r,e)||[];if(n.length===0)return 0;const t=ke(r),s=ke(e),u=Math.max(t,s);if(u===0)return 0;let f=0;for(const c of n)switch(c.kind){case"N":f+=1;break;case"D":f+=1;break;case"E":if(typeof c.lhs=="string"&&typeof c.rhs=="string"){const d=ye(c.lhs,c.rhs);f+=d}else if(typeof c.lhs=="number"&&typeof c.rhs=="number"){const d=we(c.lhs,c.rhs);f+=d}else f+=1;break;case"A":f+=.5;break}return Math.min(f/u,1)}function ke(r){if(r==null)return 0;if(typeof r!="object")return 1;if(Array.isArray(r))return r.length;let e=0;for(const n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e+=1);return e}function ge(r){try{return JSON.stringify(r,(e,n)=>typeof n=="function"?"[Function]":n===void 0?"[undefined]":n===1/0?"[Infinity]":Number.isNaN(n)?"[NaN]":n,2)}catch{return String(r)}}function Ze(r,e,n){const[t,s]=x.useState(r),u=x.useRef(r),f=x.useRef(r),c=x.useRef(!0),d=x.useRef(null),y=x.useRef(void 0),b=oe(),E=n?.onFeedback||b,O=n?.debounceMs??1500,g=n?.diffType??"git",m=n?.compareWith,k=n?.default_trigger_name??"auto_state_change",A=x.useCallback((h,w,R)=>{const P=Ge(h,w),L=Je(h,w,g);let N;n?.vote?typeof n.vote=="function"?N=n.vote(h,w,P):N=n.vote:N=P>.5?"downvote":"upvote";const i=typeof e=="function"?e(w):e;E({identifier:i,vote:N,explanation:`State change with diff percentage: ${(P*100).toFixed(1)}%`,correction:L,source:"IMPLICIT",extra_metadata:n?.metadata,trigger_name:R})},[n,e,g,E]),D=(h,w)=>{const R=w||k;if(d.current&&y.current&&y.current!==R){clearTimeout(d.current);const P=f.current;A(P,t,y.current),d.current=null}y.current=R,s(P=>typeof h=="function"?h(P):h)};return x.useEffect(()=>{if(c.current){c.current=!1,u.current=t,f.current=t;return}const h=u.current;return(m?m(h,t):JSON.stringify(h)===JSON.stringify(t))||(d.current||(f.current=h),d.current&&clearTimeout(d.current),u.current=t,d.current=setTimeout(()=>{const R=f.current,P=t;A(R,P,y.current||k),f.current=P,d.current=null},O)),()=>{d.current&&clearTimeout(d.current)}},[t,e,n,r,E,g,O,m,k,A]),[t,D]}Y.KeletContext=Q,Y.KeletProvider=Se,Y.VoteFeedback=Ae,Y.useDefaultFeedbackHandler=oe,Y.useFeedbackState=Ze,Y.useKelet=Oe,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
@@ -1,6 +1,6 @@
1
1
  import { DownvoteButtonProps, PopoverProps, SubmitButtonProps, TextareaProps, UpvoteButtonProps, VoteFeedbackRootProps } from '../types';
2
2
  export declare const VoteFeedback: {
3
- Root: ({ children, onFeedback, defaultText, identifier, extra_metadata, }: VoteFeedbackRootProps) => import("react/jsx-runtime").JSX.Element;
3
+ Root: ({ children, onFeedback, defaultText, identifier, extra_metadata, trigger_name, }: VoteFeedbackRootProps) => import("react/jsx-runtime").JSX.Element;
4
4
  UpvoteButton: ({ asChild, children, onClick, ...props }: UpvoteButtonProps) => import("react/jsx-runtime").JSX.Element;
5
5
  DownvoteButton: ({ asChild, children, onClick, ...props }: DownvoteButtonProps) => string | number | bigint | true | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
6
6
  Popover: ({ asChild, children, ...props }: PopoverProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ export type DiffType = 'git' | 'object' | 'json';
2
+ /**
3
+ * Format the diff between two values based on the specified format
4
+ */
5
+ export declare function formatDiff<T>(oldValue: T, newValue: T, diffType?: DiffType, context?: number): string;
6
+ /**
7
+ * Calculate the difference percentage between two values
8
+ */
9
+ export declare function calculateDiffPercentage<T>(oldValue: T, newValue: T): number;
@@ -0,0 +1,3 @@
1
+ export * from './use-feedback-state';
2
+ export * from './types';
3
+ export type { DiffType } from './diff-utils';
@@ -0,0 +1,52 @@
1
+ import { SetStateAction } from 'react';
2
+ import { DiffType } from '..';
3
+ import { FeedbackData } from '../../types';
4
+ /**
5
+ * Options for the useFeedbackState hook
6
+ */
7
+ export interface FeedbackStateOptions<T> {
8
+ /**
9
+ * Time to wait before sending feedback after state changes (ms)
10
+ * @default 1500
11
+ */
12
+ debounceMs?: number;
13
+ /**
14
+ * Format for the diff output in the correction field
15
+ * @default 'git'
16
+ */
17
+ diffType?: DiffType;
18
+ /**
19
+ * Optional custom equality comparison function
20
+ */
21
+ compareWith?: (a: T, b: T) => boolean;
22
+ /**
23
+ * Additional metadata to send with the feedback
24
+ */
25
+ metadata?: Record<string, any>;
26
+ /**
27
+ * Optional custom feedback handler for testing
28
+ */
29
+ onFeedback?: FeedbackHandler;
30
+ /**
31
+ * Vote classification - static vote or function to determine vote based on changes
32
+ * @default Automatic determination based on diff percentage (>50% = downvote, ≤50% = upvote)
33
+ */
34
+ vote?: 'upvote' | 'downvote' | ((before: T, after: T, diffPercentage: number) => 'upvote' | 'downvote');
35
+ /**
36
+ * Default trigger name for state changes when no trigger_name is specified in setState
37
+ * @default 'auto_state_change'
38
+ */
39
+ default_trigger_name?: string;
40
+ }
41
+ /**
42
+ * Custom setState function that accepts an optional trigger_name parameter
43
+ */
44
+ export type FeedbackStateSetter<T> = (value: SetStateAction<T>, trigger_name?: string) => void;
45
+ /**
46
+ * Return type of the useFeedbackState hook - enhanced setState with trigger_name support
47
+ */
48
+ export type FeedbackStateReturn<T> = [T, FeedbackStateSetter<T>];
49
+ /**
50
+ * Function to handle feedback submission
51
+ */
52
+ export type FeedbackHandler = (data: FeedbackData) => Promise<void>;
@@ -0,0 +1,31 @@
1
+ import { FeedbackStateReturn, FeedbackStateOptions } from './types';
2
+ /**
3
+ * A drop-in replacement for React's useState that tracks changes to state over time
4
+ * and automatically sends these changes as implicit feedback through the Kelet system.
5
+ *
6
+ * @param initialState The initial state value
7
+ * @param identifier A unique identifier for the state (string or function that derives from state)
8
+ * @param options Optional configuration options
9
+ * @returns A tuple of [state, setState] just like React's useState
10
+ *
11
+ * @example
12
+ * // Basic usage with required identifier
13
+ * const [count, setCount] = useFeedbackState(0, 'counter');
14
+ *
15
+ * // Using with static identifier and options
16
+ * const [preferences, setPreferences] = useFeedbackState(
17
+ * {theme: 'light', notifications: true},
18
+ * 'user-preferences',
19
+ * {
20
+ * debounceMs: 1000,
21
+ * diffType: 'object'
22
+ * }
23
+ * );
24
+ *
25
+ * // With dynamic identifier derived from state
26
+ * const [items, setItems] = useFeedbackState(
27
+ * [1, 2, 3],
28
+ * (items) => `items-${items.length}`
29
+ * );
30
+ */
31
+ export declare function useFeedbackState<T>(initialState: T, identifier: string | ((state: T) => string), options?: FeedbackStateOptions<T>): FeedbackStateReturn<T>;
@@ -0,0 +1,20 @@
1
+ import { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { default as React } from 'react';
3
+ interface FeedbackStateTestProps {
4
+ initialState: any;
5
+ identifier: string | ((state: any) => string);
6
+ options?: any;
7
+ onFeedback?: (data: any) => void;
8
+ }
9
+ declare const FeedbackStateTest: React.FC<FeedbackStateTestProps>;
10
+ declare const meta: Meta<typeof FeedbackStateTest>;
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+ export declare const PrimitiveState: Story;
14
+ export declare const ObjectState: Story;
15
+ export declare const ArrayState: Story;
16
+ export declare const StringState: Story;
17
+ export declare const CustomValue: Story;
18
+ export declare const RapidChanges: Story;
19
+ export declare const CustomVoteLogic: Story;
20
+ export declare const StaticVoteConfiguration: Story;
@@ -0,0 +1 @@
1
+ export * from './feedback-state';
@@ -1,3 +1,5 @@
1
1
  export { VoteFeedback } from './components/vote-feedback';
2
2
  export type { FeedbackData, VoteFeedbackRootProps, UpvoteButtonProps, DownvoteButtonProps, PopoverProps, TextareaProps, SubmitButtonProps, } from './types';
3
- export { KeletProvider, KeletContext, useKelet, useDefaultFeedbackHandler } from './contexts/kelet';
3
+ export { KeletProvider, KeletContext, useKelet, useDefaultFeedbackHandler, } from './contexts/kelet';
4
+ export { useFeedbackState } from './hooks/feedback-state';
5
+ export type { FeedbackStateOptions, DiffType } from './hooks/feedback-state';
@@ -7,6 +7,10 @@ export interface FeedbackData {
7
7
  extra_metadata?: Record<string, any>;
8
8
  vote: 'upvote' | 'downvote';
9
9
  explanation?: string;
10
+ source?: 'IMPLICIT' | 'EXPLICIT';
11
+ correction?: string;
12
+ selection?: string;
13
+ trigger_name?: string;
10
14
  }
11
15
  /**
12
16
  * Props for the root VoteFeedback component
@@ -18,6 +22,7 @@ export interface VoteFeedbackRootProps {
18
22
  defaultText?: string;
19
23
  identifier: string;
20
24
  extra_metadata?: Record<string, any>;
25
+ trigger_name?: string;
21
26
  }
22
27
  /**
23
28
  * Props for the upvote button
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kelet-ai/feedback-ui",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/kelet-ai/feedback-ui.git"
@@ -8,48 +8,47 @@
8
8
  "main": "./dist/feedback-ui.umd.js",
9
9
  "module": "./dist/feedback-ui.es.js",
10
10
  "devDependencies": {
11
- "@chromatic-com/storybook": "^4.0.1",
11
+ "@chromatic-com/storybook": "^4.1.0",
12
12
  "@radix-ui/react-popover": "^1.1.14",
13
13
  "@radix-ui/react-slot": "^1.2.3",
14
- "@storybook/addon-a11y": "^9.0.17",
15
- "@storybook/addon-docs": "^9.0.17",
16
- "@storybook/addon-themes": "^9.0.17",
17
- "@storybook/addon-vitest": "^9.0.17",
18
- "@storybook/blocks": "^8.6.14",
19
- "@storybook/builder-vite": "^9.0.17",
20
- "@storybook/react-vite": "^9.0.17",
14
+ "@storybook/addon-a11y": "^9.1.0",
15
+ "@storybook/addon-docs": "^9.1.0",
16
+ "@storybook/addon-themes": "^9.1.0",
17
+ "@storybook/addon-vitest": "^9.1.0",
18
+ "@storybook/builder-vite": "^9.1.0",
19
+ "@storybook/react-vite": "^9.1.0",
21
20
  "@tailwindcss/forms": "^0.5.10",
22
21
  "@tailwindcss/vite": "^4.1.11",
23
- "@testing-library/jest-dom": "^6.6.3",
22
+ "@testing-library/jest-dom": "^6.6.4",
24
23
  "@testing-library/react": "^16.3.0",
25
24
  "@testing-library/user-event": "^14.6.1",
26
25
  "@types/bun": "latest",
27
- "@types/node": "^24.0.14",
28
- "@types/react": "^19.1.8",
29
- "@types/react-dom": "^19.1.6",
30
- "@vitejs/plugin-react": "^4.6.0",
26
+ "@types/node": "^24.1.0",
27
+ "@types/react": "^19.1.9",
28
+ "@types/react-dom": "^19.1.7",
29
+ "@vitejs/plugin-react": "^4.7.0",
31
30
  "@vitest/browser": "^3.2.4",
32
31
  "@vitest/coverage-v8": "^3.2.4",
33
32
  "ajv": "^8.17.1",
34
33
  "class-variance-authority": "^0.7.1",
35
34
  "clsx": "^2.1.1",
36
- "eslint": "^9.31.0",
35
+ "eslint": "^9.32.0",
37
36
  "eslint-plugin-react-hooks": "^5.2.0",
38
- "eslint-plugin-storybook": "9.0.17",
37
+ "eslint-plugin-storybook": "9.1.0",
39
38
  "jsdom": "^26.1.0",
40
39
  "lucide-react": "^0.525.0",
41
- "playwright": "^1.54.1",
40
+ "playwright": "^1.54.2",
42
41
  "prettier": "^3.6.2",
43
- "react": "^19.1.0",
44
- "react-dom": "^19.1.0",
45
- "shadcn": "^2.9.0",
46
- "storybook": "^9.0.17",
42
+ "react": "^19.1.1",
43
+ "react-dom": "^19.1.1",
44
+ "shadcn": "^2.10.0",
45
+ "storybook": "^9.1.0",
47
46
  "tailwind-merge": "^3.3.1",
48
47
  "tailwindcss": "^4.1.11",
49
- "tw-animate-css": "^1.3.5",
50
- "typescript": "^5.8.3",
51
- "typescript-eslint": "^8.37.0",
52
- "vite": "^7.0.4",
48
+ "tw-animate-css": "^1.3.6",
49
+ "typescript": "^5.9.2",
50
+ "typescript-eslint": "^8.38.0",
51
+ "vite": "^7.0.6",
53
52
  "vite-plugin-dts": "^4.5.4",
54
53
  "vitest": "^3.2.4"
55
54
  },
@@ -81,16 +80,26 @@
81
80
  "build": "vite build",
82
81
  "build-storybook": "storybook build",
83
82
  "test": "vitest",
83
+ "test:unit": "vitest --project=unit",
84
84
  "test:storybook": "vitest --project=storybook",
85
85
  "test:storybook:coverage": "vitest --project=storybook --coverage",
86
86
  "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
87
- "format": "prettier --write .",
88
- "format:check": "prettier --check .",
87
+ "lint:fix": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
88
+ "prettier": "prettier --check .",
89
+ "prettier:fix": "prettier --write .",
89
90
  "preview": "vite preview",
90
91
  "prepublishOnly": "bun run build",
91
92
  "storybook": "NODE_NO_WARNINGS=1 storybook dev -p 6006",
92
93
  "registry:build": "bun shadcn build"
93
94
  },
94
95
  "type": "module",
95
- "types": "./dist/index.d.ts"
96
+ "types": "./dist/index.d.ts",
97
+ "dependencies": {
98
+ "@types/deep-diff": "^1.0.5",
99
+ "@types/diff": "^8.0.0",
100
+ "@types/fast-levenshtein": "^0.0.4",
101
+ "deep-diff": "^1.0.2",
102
+ "diff": "^8.0.2",
103
+ "fast-levenshtein": "^3.0.0"
104
+ }
96
105
  }
@@ -1,2 +0,0 @@
1
- declare const _default: import("@typescript-eslint/utils/ts-eslint").FlatConfig.ConfigArray;
2
- export default _default;