@census-ai/census-sdk 0.2.2 → 0.2.3
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.
- package/dist/react/index.cjs +6 -2
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -44
- package/dist/react/index.d.ts +1 -44
- package/dist/react/index.js +6 -2
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -1161,55 +1161,12 @@ declare function Requests({ status, type, limit, className, showEmptyState, onRe
|
|
|
1161
1161
|
|
|
1162
1162
|
type HelpCenterTab = 'articles' | 'requests';
|
|
1163
1163
|
interface HelpCenterProps {
|
|
1164
|
-
/**
|
|
1165
|
-
* Which tabs to show
|
|
1166
|
-
* @default ['articles', 'requests']
|
|
1167
|
-
*/
|
|
1168
1164
|
tabs?: HelpCenterTab[];
|
|
1169
|
-
/**
|
|
1170
|
-
* Default active tab
|
|
1171
|
-
* @default 'articles'
|
|
1172
|
-
*/
|
|
1173
1165
|
defaultTab?: HelpCenterTab;
|
|
1174
|
-
/**
|
|
1175
|
-
* Custom labels for tabs
|
|
1176
|
-
*/
|
|
1177
1166
|
tabLabels?: Partial<Record<HelpCenterTab, string>>;
|
|
1178
|
-
/**
|
|
1179
|
-
* Show search in knowledge base
|
|
1180
|
-
* @default true
|
|
1181
|
-
*/
|
|
1182
1167
|
showSearch?: boolean;
|
|
1183
|
-
/**
|
|
1184
|
-
* Show categories in knowledge base
|
|
1185
|
-
* @default true
|
|
1186
|
-
*/
|
|
1187
|
-
showCategories?: boolean;
|
|
1188
|
-
/**
|
|
1189
|
-
* Custom CSS class
|
|
1190
|
-
*/
|
|
1191
1168
|
className?: string;
|
|
1192
1169
|
}
|
|
1193
|
-
|
|
1194
|
-
* HelpCenter component that combines KnowledgeBase and Requests with tabs.
|
|
1195
|
-
*
|
|
1196
|
-
* @example
|
|
1197
|
-
* ```tsx
|
|
1198
|
-
* import { CensusProvider, HelpCenter } from '@census-ai/census-sdk/react';
|
|
1199
|
-
*
|
|
1200
|
-
* function HelpPage() {
|
|
1201
|
-
* return (
|
|
1202
|
-
* <CensusProvider apiKey="cs_live_xxx">
|
|
1203
|
-
* <HelpCenter
|
|
1204
|
-
* tabs={['articles', 'requests']}
|
|
1205
|
-
* defaultTab="articles"
|
|
1206
|
-
* showSearch
|
|
1207
|
-
* />
|
|
1208
|
-
* </CensusProvider>
|
|
1209
|
-
* );
|
|
1210
|
-
* }
|
|
1211
|
-
* ```
|
|
1212
|
-
*/
|
|
1213
|
-
declare function HelpCenter({ tabs, defaultTab, tabLabels, showSearch, showCategories, className, }: HelpCenterProps): react_jsx_runtime.JSX.Element;
|
|
1170
|
+
declare function HelpCenter({ tabs, defaultTab, tabLabels, showSearch, className, }: HelpCenterProps): react_jsx_runtime.JSX.Element;
|
|
1214
1171
|
|
|
1215
1172
|
export { type Article, type ArticlesOptions, CensusProvider, type CensusProviderProps, type CensusTheme, type Feature, type FeatureGroup, FeedbackButton, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, type FeedbackVisibility, HelpCenter, type HelpCenterProps, type HelpCenterTab, KnowledgeBase, type KnowledgeBaseProps, type Position, type Request, Requests, type RequestsOptions, type RequestsProps, type RequestsSettings, type UserIdentity, useArticle, useArticles, useCensus, useCensusContext, useFeatureGroups, useFeedback, useIdentify, useRequests, useTrack, useVote };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1161,55 +1161,12 @@ declare function Requests({ status, type, limit, className, showEmptyState, onRe
|
|
|
1161
1161
|
|
|
1162
1162
|
type HelpCenterTab = 'articles' | 'requests';
|
|
1163
1163
|
interface HelpCenterProps {
|
|
1164
|
-
/**
|
|
1165
|
-
* Which tabs to show
|
|
1166
|
-
* @default ['articles', 'requests']
|
|
1167
|
-
*/
|
|
1168
1164
|
tabs?: HelpCenterTab[];
|
|
1169
|
-
/**
|
|
1170
|
-
* Default active tab
|
|
1171
|
-
* @default 'articles'
|
|
1172
|
-
*/
|
|
1173
1165
|
defaultTab?: HelpCenterTab;
|
|
1174
|
-
/**
|
|
1175
|
-
* Custom labels for tabs
|
|
1176
|
-
*/
|
|
1177
1166
|
tabLabels?: Partial<Record<HelpCenterTab, string>>;
|
|
1178
|
-
/**
|
|
1179
|
-
* Show search in knowledge base
|
|
1180
|
-
* @default true
|
|
1181
|
-
*/
|
|
1182
1167
|
showSearch?: boolean;
|
|
1183
|
-
/**
|
|
1184
|
-
* Show categories in knowledge base
|
|
1185
|
-
* @default true
|
|
1186
|
-
*/
|
|
1187
|
-
showCategories?: boolean;
|
|
1188
|
-
/**
|
|
1189
|
-
* Custom CSS class
|
|
1190
|
-
*/
|
|
1191
1168
|
className?: string;
|
|
1192
1169
|
}
|
|
1193
|
-
|
|
1194
|
-
* HelpCenter component that combines KnowledgeBase and Requests with tabs.
|
|
1195
|
-
*
|
|
1196
|
-
* @example
|
|
1197
|
-
* ```tsx
|
|
1198
|
-
* import { CensusProvider, HelpCenter } from '@census-ai/census-sdk/react';
|
|
1199
|
-
*
|
|
1200
|
-
* function HelpPage() {
|
|
1201
|
-
* return (
|
|
1202
|
-
* <CensusProvider apiKey="cs_live_xxx">
|
|
1203
|
-
* <HelpCenter
|
|
1204
|
-
* tabs={['articles', 'requests']}
|
|
1205
|
-
* defaultTab="articles"
|
|
1206
|
-
* showSearch
|
|
1207
|
-
* />
|
|
1208
|
-
* </CensusProvider>
|
|
1209
|
-
* );
|
|
1210
|
-
* }
|
|
1211
|
-
* ```
|
|
1212
|
-
*/
|
|
1213
|
-
declare function HelpCenter({ tabs, defaultTab, tabLabels, showSearch, showCategories, className, }: HelpCenterProps): react_jsx_runtime.JSX.Element;
|
|
1170
|
+
declare function HelpCenter({ tabs, defaultTab, tabLabels, showSearch, className, }: HelpCenterProps): react_jsx_runtime.JSX.Element;
|
|
1214
1171
|
|
|
1215
1172
|
export { type Article, type ArticlesOptions, CensusProvider, type CensusProviderProps, type CensusTheme, type Feature, type FeatureGroup, FeedbackButton, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, type FeedbackVisibility, HelpCenter, type HelpCenterProps, type HelpCenterTab, KnowledgeBase, type KnowledgeBaseProps, type Position, type Request, Requests, type RequestsOptions, type RequestsProps, type RequestsSettings, type UserIdentity, useArticle, useArticles, useCensus, useCensusContext, useFeatureGroups, useFeedback, useIdentify, useRequests, useTrack, useVote };
|
package/dist/react/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {createContext,useState,useMemo,useEffect,useContext,useCallback}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Re="https://api.census.ai",Z=class{constructor(e){this.currentUserId=null;if(!e.apiKey)throw new Error("Census: apiKey is required");["cs_live_","cs_test_","op_live_","op_test_"].some(o=>e.apiKey.startsWith(o))||console.warn('Census: API key should start with "cs_live_" or "cs_test_"'),this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||Re,this.debug=e.debug||false,this.log("Initialized with base URL:",this.baseUrl);}async identify(e){if(!e.userId)throw new Error("Census: userId is required for identify()");this.currentUserId=e.userId,await this.request("/api/sdk/identify","POST",{userId:e.userId,email:e.email,name:e.name,avatarUrl:e.avatarUrl,metadata:e.metadata,organizationId:e.organizationId,organizationName:e.organizationName,organizationDomain:e.organizationDomain,organizationPlan:e.organizationPlan}),this.log("User identified:",e.userId);}reset(){this.currentUserId=null,this.log("User identity reset");}async submitFeedback(e){let t=["feedback","bug_report","feature_request","article_rating"];if(!e.type||!t.includes(e.type))throw new Error(`Census: type must be one of: ${t.join(", ")}`);if(e.type==="article_rating"){if(e.rating===void 0&&e.helpful===void 0)throw new Error("Census: article_rating requires rating or helpful field")}else if(!e.message)throw new Error("Census: message is required for this feedback type");let o=await this.request("/api/sdk/feedback","POST",{type:e.type,message:e.message,rating:e.rating,helpful:e.helpful,userId:this.currentUserId,articleId:e.articleId,pageUrl:typeof window<"u"?window.location.href:void 0,metadata:e.metadata});return this.log("Feedback submitted:",o.feedbackId),{feedbackId:o.feedbackId}}async getArticles(e){let t=new URLSearchParams;e?.category&&t.set("category",e.category),e?.search&&t.set("search",e.search),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let o=t.toString(),s=`/api/sdk/articles${o?`?${o}`:""}`,l=await this.request(s,"GET");return this.log("Fetched articles:",l.articles.length),l}async getArticle(e){try{let t=await this.request(`/api/sdk/articles/${encodeURIComponent(e)}`,"GET");return this.log("Fetched article:",e),t.article}catch(t){if(t.status===404)return null;throw t}}async getFeatureGroups(){let e=await this.request("/api/sdk/feature-groups","GET");return this.log("Fetched feature groups:",e.feature_groups.length),e}async getRequests(e){if(!this.currentUserId)throw new Error("Census: User must be identified before fetching requests. Call identify() first.");let t=new URLSearchParams;t.set("userId",this.currentUserId),e?.status&&t.set("status",e.status),e?.type&&t.set("type",e.type),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let o=await this.request(`/api/sdk/requests?${t.toString()}`,"GET");return this.log("Fetched requests:",o.requests.length),o}async vote(e){if(!this.currentUserId)throw new Error("Census: User must be identified before voting. Call identify() first.");if(!e)throw new Error("Census: feedbackId is required for vote()");let t=await this.request("/api/sdk/requests/vote","POST",{feedbackId:e,userId:this.currentUserId});return this.log("Vote result:",t.action,"for feedback:",e),t}async track(e,t){if(!e)throw new Error("Census: eventType is required for track()");await this.request("/api/sdk/events","POST",{eventType:e,userId:this.currentUserId,properties:t}),this.log("Event tracked:",e);}async trackBatch(e){if(!e.events||e.events.length===0)throw new Error("Census: at least one event is required");if(e.events.length>100)throw new Error("Census: maximum 100 events per batch");let t=e.events.map(o=>({eventType:o.eventType,userId:this.currentUserId,articleId:o.articleId,featureId:o.featureId,properties:o.properties}));await this.request("/api/sdk/events","POST",{events:t}),this.log("Batch events tracked:",e.events.length);}async getGuides(){let e=new URLSearchParams;this.currentUserId&&e.set("userId",this.currentUserId);let t=e.toString(),o=`/api/sdk/guides${t?`?${t}`:""}`,s=await this.request(o,"GET");return this.log("Fetched guides:",s.guides.length),s}async getGuide(e){try{let t=new URLSearchParams;this.currentUserId&&t.set("userId",this.currentUserId);let o=t.toString(),s=`/api/sdk/guides/${encodeURIComponent(e)}${o?`?${o}`:""}`,l=await this.request(s,"GET");return this.log("Fetched guide:",e),l.guide}catch(t){if(t.status===404)return null;throw t}}async trackGuideEvent(e){if(!e.guideId||!e.eventType||!e.sessionId)throw new Error("Census: guideId, eventType, and sessionId are required for trackGuideEvent()");await this.request("/api/sdk/guides/events","POST",{guideId:e.guideId,eventType:e.eventType,stepId:e.stepId,stepIndex:e.stepIndex,pageUrl:e.pageUrl||(typeof window<"u"?window.location.href:void 0),sessionId:e.sessionId,userId:e.userId||this.currentUserId,metadata:e.metadata}),this.log("Guide event tracked:",e.eventType,e.guideId);}async markGuideCompleted(e){if(!e)throw new Error("Census: guideId is required for markGuideCompleted()");if(!this.currentUserId)throw new Error("Census: User must be identified before marking guides complete. Call identify() first.");await this.request("/api/sdk/guides/complete","POST",{guideId:e,userId:this.currentUserId}),this.log("Guide marked completed:",e);}getCurrentUserId(){return this.currentUserId}isIdentified(){return this.currentUserId!==null}async request(e,t,o){let s=`${this.baseUrl}${e}`,l={"X-Census-Key":this.apiKey};o&&(l["Content-Type"]="application/json"),this.log(`${t} ${e}`,o);let d=await fetch(s,{method:t,headers:l,body:o?JSON.stringify(o):void 0});if(!d.ok){let i=`Request failed with status ${d.status}`;try{i=(await d.json()).error||i;}catch{}throw {error:i,status:d.status}}return d.json()}log(...e){this.debug&&console.log("[Census]",...e);}};function pe(r){return new Z(r)}var ee=createContext(null);function Fe({apiKey:r,baseUrl:e,debug:t,user:o,theme:s={},children:l}){let[d,i]=useState(false),[n,a]=useState(false),c=useMemo(()=>pe({apiKey:r,baseUrl:e,debug:t}),[r,e,t]);useEffect(()=>{o?c.identify(o).then(()=>{a(true),i(true);}).catch(C=>{console.error("[Census] Failed to identify user:",C),i(true);}):i(true);},[c,o]);let p=useMemo(()=>({client:c,theme:s,isReady:d,isIdentified:n}),[c,s,d,n]);return jsx(ee.Provider,{value:p,children:l})}function Te(){let r=useContext(ee);if(!r)throw new Error("useCensus must be used within a CensusProvider");return r.client}function v(){let r=useContext(ee);if(!r)throw new Error("useCensusContext must be used within a CensusProvider");return r}function qe(){let{client:r}=v(),[e,t]=useState(false),[o,s]=useState(null);return {identify:async i=>{t(true),s(null);try{await r.identify(i);}catch(n){throw s(n instanceof Error?n:new Error("Failed to identify user")),n}finally{t(false);}},reset:()=>{r.reset();},isIdentifying:e,isIdentified:r.isIdentified(),error:o}}function D(){let{client:r}=v(),[e,t]=useState(false),[o,s]=useState(false),[l,d]=useState(null),[i,n]=useState(null),a=useCallback(async p=>{t(true),s(false),d(null),n(null);try{let C=await r.submitFeedback(p);return n(C.feedbackId),s(!0),C}catch(C){let S=C instanceof Error?C:new Error("Failed to submit feedback");throw d(S),S}finally{t(false);}},[r]),c=useCallback(()=>{s(false),d(null),n(null);},[]);return {submitFeedback:a,reset:c,isSubmitting:e,isSuccess:o,error:l,feedbackId:i}}function te(r){let{client:e,isReady:t}=v(),[o,s]=useState(null),[l,d]=useState(true),[i,n]=useState(null),a=useCallback(async()=>{d(true),n(null);try{let c=await e.getArticles(r);s(c);}catch(c){n(c instanceof Error?c:new Error("Failed to fetch articles"));}finally{d(false);}},[e,r?.category,r?.search,r?.limit,r?.offset]);return useEffect(()=>{t&&a();},[t,a]),{articles:o?.articles||[],pagination:o?.pagination,isLoading:l,error:i,refetch:a}}function re(r){let{client:e,isReady:t}=v(),[o,s]=useState(null),[l,d]=useState(true),[i,n]=useState(null),a=useCallback(async()=>{if(!r){s(null),d(false);return}d(true),n(null);try{let c=await e.getArticle(r);s(c);}catch(c){n(c instanceof Error?c:new Error("Failed to fetch article"));}finally{d(false);}},[e,r]);return useEffect(()=>{t&&a();},[t,a]),{article:o,isLoading:l,error:i,refetch:a}}var Be={feedbackVisibility:"own",allowVoting:false,allowRequestCreation:true};function oe(r){let{client:e,isReady:t,isIdentified:o}=v(),[s,l]=useState(null),[d,i]=useState(true),[n,a]=useState(null),c=useCallback(async()=>{if(!o){l(null),i(false);return}i(true),a(null);try{let p=await e.getRequests(r);l(p);}catch(p){a(p instanceof Error?p:new Error("Failed to fetch requests"));}finally{i(false);}},[e,o,r?.status,r?.type,r?.limit,r?.offset]);return useEffect(()=>{t&&(o?c():i(false));},[t,o,c]),{requests:s?.requests||[],pagination:s?.pagination,settings:s?.settings||Be,isLoading:d,error:n,refetch:c}}function se(){let{client:r}=v(),[e,t]=useState(false),[o,s]=useState(null);return {vote:useCallback(async d=>{t(true),s(null);try{return await r.vote(d)}catch(i){let n=i instanceof Error?i:new Error("Failed to vote");throw s(n),n}finally{t(false);}},[r]),isVoting:e,error:o}}function _e(){let{client:r}=v(),e=useCallback(async(o,s)=>{await r.track(o,s);},[r]),t=useCallback(async o=>{await r.trackBatch({events:o});},[r]);return {track:e,trackBatch:t}}function Pe(){let{client:r,isReady:e}=v(),[t,o]=useState([]),[s,l]=useState(true),[d,i]=useState(null),n=useCallback(async()=>{l(true),i(null);try{let a=await r.getFeatureGroups();o(a.feature_groups);}catch(a){i(a instanceof Error?a:new Error("Failed to fetch feature groups"));}finally{l(false);}},[r]);return useEffect(()=>{e&&n();},[e,n]),{featureGroups:t,isLoading:s,error:d,refetch:n}}var M={button:{position:"fixed",padding:"12px 20px",border:"none",borderRadius:"8px",cursor:"pointer",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",fontWeight:"500",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",transition:"transform 0.2s, box-shadow 0.2s",zIndex:9999},modal:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",zIndex:1e4},modalContent:{backgroundColor:"white",borderRadius:"12px",padding:"24px",width:"100%",maxWidth:"400px",margin:"16px",boxShadow:"0 20px 50px rgba(0, 0, 0, 0.2)",fontFamily:"system-ui, -apple-system, sans-serif"},textarea:{width:"100%",padding:"10px 12px",border:"1px solid #e0e0e0",borderRadius:"6px",fontSize:"14px",marginBottom:"16px",minHeight:"100px",resize:"vertical",boxSizing:"border-box",fontFamily:"inherit"},submitButton:{width:"100%",padding:"12px",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"500",transition:"opacity 0.2s"},typeButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"6px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"}},Ae={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},Ue={feedback:"General Feedback",bug_report:"Bug Report",feature_request:"Feature Request",article_rating:"Article Rating"},ze={feedback:"\u{1F4AC}",bug_report:"\u{1F41B}",feature_request:"\u{1F4A1}",article_rating:"\u2B50"};function Le(r){return {primaryColor:r.primaryColor||"#000000",textColor:r.textColor||"#333333",backgroundColor:r.backgroundColor||"#ffffff",borderRadius:r.borderRadius||"8px",fontFamily:r.fontFamily||"system-ui, -apple-system, sans-serif"}}function Ge({position:r="bottom-right",text:e="Feedback",allowedTypes:t=["feedback","bug_report","feature_request"],theme:o,onSubmit:s,onError:l,children:d}){let{theme:i}=v(),{submitFeedback:n,isSubmitting:a,isSuccess:c,reset:p}=D(),[C,S]=useState(false),[m,E]=useState(t[0]),[I,B]=useState(""),F={...i,...o},A=Le(F),G=useCallback(()=>{S(true),p();},[p]),T=useCallback(()=>{S(false),B(""),E(t[0]);},[t]),V=useCallback(async U=>{U.preventDefault();let g={type:m,message:I};try{await n(g),s?.(g),setTimeout(T,1500);}catch(w){l?.(w instanceof Error?w:new Error("Failed to submit feedback"));}},[m,I,n,s,l,T]);return d?jsxs(Fragment,{children:[jsx("div",{onClick:G,style:{cursor:"pointer"},children:d}),C&&jsx(be,{isOpen:C,onClose:T,selectedType:m,onTypeChange:E,allowedTypes:t,message:I,onMessageChange:B,onSubmit:V,isSubmitting:a,isSuccess:c,themeStyles:A})]}):jsxs(Fragment,{children:[jsx("button",{onClick:G,style:{...M.button,...Ae[r],backgroundColor:A.primaryColor,color:"white",borderRadius:A.borderRadius,fontFamily:A.fontFamily},"aria-label":"Open feedback form",children:e}),C&&jsx(be,{isOpen:C,onClose:T,selectedType:m,onTypeChange:E,allowedTypes:t,message:I,onMessageChange:B,onSubmit:V,isSubmitting:a,isSuccess:c,themeStyles:A})]})}function be({isOpen:r,onClose:e,selectedType:t,onTypeChange:o,allowedTypes:s,message:l,onMessageChange:d,onSubmit:i,isSubmitting:n,isSuccess:a,themeStyles:c}){return r?a?jsx("div",{style:M.modal,onClick:e,children:jsxs("div",{style:{...M.modalContent,textAlign:"center",fontFamily:c.fontFamily},onClick:p=>p.stopPropagation(),children:[jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"\u{1F389}"}),jsx("h3",{style:{margin:"0 0 8px 0",color:c.textColor},children:"Thanks for your feedback!"}),jsx("p",{style:{margin:0,color:"#666"},children:"We appreciate you taking the time to share."})]})}):jsx("div",{style:M.modal,onClick:e,children:jsxs("div",{style:{...M.modalContent,fontFamily:c.fontFamily},onClick:p=>p.stopPropagation(),children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[jsx("h3",{style:{margin:0,color:c.textColor},children:"Send Feedback"}),jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer",color:"#999",padding:"0",lineHeight:"1"},"aria-label":"Close",children:"\xD7"})]}),jsxs("form",{onSubmit:i,children:[jsxs("div",{style:{marginBottom:"16px"},children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"What kind of feedback?"}),jsx("div",{style:{display:"flex",flexWrap:"wrap"},children:s.map(p=>jsxs("button",{type:"button",onClick:()=>o(p),style:{...M.typeButton,backgroundColor:t===p?c.primaryColor:"white",color:t===p?"white":c.textColor,borderColor:t===p?c.primaryColor:"#e0e0e0"},children:[ze[p]," ",Ue[p]]},p))})]}),jsxs("div",{children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"Your message"}),jsx("textarea",{value:l,onChange:p=>d(p.target.value),placeholder:t==="bug_report"?"Describe the bug and steps to reproduce...":t==="feature_request"?"Describe the feature you would like...":"Share your thoughts...",style:M.textarea,required:true})]}),jsx("button",{type:"submit",disabled:n||!l.trim(),style:{...M.submitButton,backgroundColor:c.primaryColor,color:"white",opacity:n||!l.trim()?.6:1,cursor:n||!l.trim()?"not-allowed":"pointer"},children:n?"Sending...":"Send Feedback"})]})]})}):null}var y={container:{fontFamily:"system-ui, -apple-system, sans-serif",maxWidth:"800px"},searchInput:{width:"100%",padding:"12px 16px",border:"1px solid #e0e0e0",borderRadius:"8px",fontSize:"15px",marginBottom:"24px",boxSizing:"border-box"},categoryButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"20px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"},articleCard:{padding:"20px",border:"1px solid #e0e0e0",borderRadius:"8px",marginBottom:"12px",cursor:"pointer",transition:"box-shadow 0.2s, border-color 0.2s",backgroundColor:"white"},articleTitle:{margin:"0 0 8px 0",fontSize:"16px",fontWeight:"600"},articleDescription:{margin:0,fontSize:"14px",color:"#666",lineHeight:1.5},articleMeta:{display:"flex",gap:"16px",marginTop:"12px",fontSize:"12px",color:"#999"},backButton:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"8px 0",border:"none",background:"none",cursor:"pointer",fontSize:"14px",color:"#666",marginBottom:"16px"},articleContent:{lineHeight:1.7,fontSize:"15px"},loading:{textAlign:"center",padding:"40px",color:"#666"},error:{padding:"20px",backgroundColor:"#fef2f2",borderRadius:"8px",color:"#b91c1c",textAlign:"center"},empty:{textAlign:"center",padding:"40px",color:"#666"}};function Oe(r){return {primaryColor:r.primaryColor||"#000000",textColor:r.textColor||"#333333",backgroundColor:r.backgroundColor||"#ffffff",borderRadius:r.borderRadius||"8px",fontFamily:r.fontFamily||"system-ui, -apple-system, sans-serif"}}function J({showSearch:r=true,showCategories:e=true,defaultCategory:t,theme:o,className:s,onArticleView:l}){let{theme:d}=v(),[i,n]=useState(""),[a,c]=useState(t),[p,C]=useState(null),S={...d,...o},m=Oe(S),{articles:E,isLoading:I,error:B}=te({category:a,search:i||void 0}),{article:F,isLoading:A,error:G}=re(p||""),T=useMemo(()=>{let g=new Set;return E.forEach(w=>{w.category&&g.add(w.category);}),Array.from(g).sort()},[E]),V=g=>{C(g.slug),l?.(g);},U=()=>{C(null);};return p?A?jsx("div",{style:{...y.container,fontFamily:m.fontFamily},className:s,children:jsx("div",{style:y.loading,children:"Loading article..."})}):G?jsxs("div",{style:{...y.container,fontFamily:m.fontFamily},className:s,children:[jsx("button",{onClick:U,style:y.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:y.error,children:"Failed to load article. Please try again."})]}):F?jsxs("div",{style:{...y.container,fontFamily:m.fontFamily},className:s,children:[jsx("button",{onClick:U,style:y.backButton,children:"\u2190 Back to articles"}),jsxs("article",{children:[jsx("h1",{style:{margin:"0 0 16px 0",color:m.textColor},children:F.title}),F.read_time_minutes&&jsxs("div",{style:{fontSize:"14px",color:"#666",marginBottom:"24px"},children:[F.read_time_minutes," min read"]}),F.content_html?jsx("div",{style:{...y.articleContent,color:m.textColor},dangerouslySetInnerHTML:{__html:F.content_html}}):jsx("div",{style:{...y.articleContent,color:m.textColor},children:typeof F.content=="string"?F.content:"No content available."})]})]}):jsxs("div",{style:{...y.container,fontFamily:m.fontFamily},className:s,children:[jsx("button",{onClick:U,style:y.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:y.empty,children:"Article not found."})]}):jsxs("div",{style:{...y.container,fontFamily:m.fontFamily},className:s,children:[r&&jsx("input",{type:"text",placeholder:"Search articles...",value:i,onChange:g=>n(g.target.value),style:y.searchInput}),e&&T.length>0&&jsxs("div",{style:{marginBottom:"24px"},children:[jsx("button",{onClick:()=>c(void 0),style:{...y.categoryButton,backgroundColor:a?"white":m.primaryColor,color:a?m.textColor:"white",borderColor:a?"#e0e0e0":m.primaryColor},children:"All"}),T.map(g=>jsx("button",{onClick:()=>c(g),style:{...y.categoryButton,backgroundColor:a===g?m.primaryColor:"white",color:a===g?"white":m.textColor,borderColor:a===g?m.primaryColor:"#e0e0e0"},children:g},g))]}),I&&jsx("div",{style:y.loading,children:"Loading articles..."}),B&&jsx("div",{style:y.error,children:"Failed to load articles. Please try again."}),!I&&!B&&E.length===0&&jsx("div",{style:y.empty,children:i?`No articles found for "${i}"`:"No articles available yet."}),!I&&!B&&E.length>0&&jsx("div",{children:E.map(g=>jsxs("div",{onClick:()=>V(g),style:y.articleCard,role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&V(g);},children:[jsx("h3",{style:{...y.articleTitle,color:m.textColor},children:g.title}),g.seo_description&&jsx("p",{style:y.articleDescription,children:g.seo_description}),jsxs("div",{style:y.articleMeta,children:[g.category&&jsx("span",{children:g.category}),g.read_time_minutes&&jsxs("span",{children:[g.read_time_minutes," min read"]})]})]},g.id))})]})}var f={container:{fontFamily:"system-ui, -apple-system, sans-serif"},list:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"12px"},card:{border:"1px solid #e5e7eb",borderRadius:"8px",padding:"16px",backgroundColor:"#ffffff",cursor:"pointer",transition:"border-color 0.15s, box-shadow 0.15s"},cardHover:{borderColor:"#d1d5db",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",marginBottom:"8px"},badges:{display:"flex",alignItems:"center",gap:"6px"},badge:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",fontSize:"12px",fontWeight:500},message:{fontSize:"14px",color:"#111827",margin:0,lineHeight:1.5},meta:{display:"flex",gap:"12px",marginTop:"8px",fontSize:"12px",color:"#6b7280"},empty:{textAlign:"center",padding:"32px 16px",color:"#6b7280"},emptyIcon:{width:"48px",height:"48px",margin:"0 auto 12px",color:"#d1d5db"},loading:{textAlign:"center",padding:"24px",color:"#6b7280"},error:{textAlign:"center",padding:"24px",color:"#dc2626"},voteButton:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"8px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",cursor:"pointer",minWidth:"48px",transition:"all 0.15s"},voteButtonActive:{backgroundColor:"#dbeafe",borderColor:"#2563eb",color:"#2563eb"},voteCount:{fontSize:"14px",fontWeight:600,color:"#111827"},cardWithVote:{display:"flex",gap:"12px"},cardContent:{flex:1},form:{marginBottom:"16px",padding:"16px",backgroundColor:"#f9fafb",borderRadius:"8px",border:"1px solid #e5e7eb"},formHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},formTitle:{fontSize:"14px",fontWeight:500,color:"#111827",margin:0},typeSelector:{display:"flex",gap:"8px",marginBottom:"12px"},typeButton:{padding:"6px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",fontSize:"13px",cursor:"pointer",transition:"all 0.15s"},typeButtonActive:{backgroundColor:"#111827",borderColor:"#111827",color:"#ffffff"},textarea:{width:"100%",padding:"10px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",fontSize:"14px",resize:"vertical",minHeight:"80px",fontFamily:"inherit",marginBottom:"12px"},submitButton:{padding:"8px 16px",borderRadius:"6px",border:"none",backgroundColor:"#111827",color:"#ffffff",fontSize:"14px",fontWeight:500,cursor:"pointer",transition:"opacity 0.15s"},successMessage:{padding:"12px",backgroundColor:"#d1fae5",borderRadius:"6px",color:"#059669",fontSize:"14px",marginBottom:"16px"},ownBadge:{display:"inline-flex",alignItems:"center",padding:"2px 6px",borderRadius:"9999px",fontSize:"11px",fontWeight:500,backgroundColor:"#f3f4f6",color:"#6b7280",marginLeft:"6px"}},ye={feedback:{label:"Feedback",color:"#2563eb",bg:"#dbeafe"},bug_report:{label:"Bug Report",color:"#dc2626",bg:"#fee2e2"},feature_request:{label:"Feature Request",color:"#d97706",bg:"#fef3c7"},article_rating:{label:"Article Rating",color:"#7c3aed",bg:"#ede9fe"}},he={new:{label:"New",color:"#6b7280",bg:"#f3f4f6"},reviewed:{label:"Reviewed",color:"#2563eb",bg:"#dbeafe"},in_progress:{label:"In Progress",color:"#d97706",bg:"#fef3c7"},resolved:{label:"Resolved",color:"#059669",bg:"#d1fae5"},closed:{label:"Closed",color:"#6b7280",bg:"#f3f4f6"}};function Me(r){return new Date(r).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}var He=[{value:"feedback",label:"Feedback"},{value:"bug_report",label:"Bug"},{value:"feature_request",label:"Feature"}];function X({status:r,type:e,limit:t=50,className:o,showEmptyState:s=true,onRequestClick:l}){let{isIdentified:d}=v(),[i,n]=useState(null),[a,c]=useState(false),[p,C]=useState("feedback"),[S,m]=useState(""),[E,I]=useState({}),{requests:B,isLoading:F,error:A,refetch:G,settings:T}=oe({status:r,type:e,limit:t}),{vote:V,isVoting:U}=se(),{submitFeedback:g,isSubmitting:w,isSuccess:Ce,reset:de}=D(),ce=useCallback(u=>{l?.(u);},[l]),ve=useCallback(async(u,_,H)=>{if(!U){I(O=>({...O,[u]:{count:H?_-1:_+1,hasVoted:!H}}));try{let O=await V(u);I(q=>({...q,[u]:{count:O.vote_count,hasVoted:O.user_has_voted}}));}catch{I(O=>({...O,[u]:{count:_,hasVoted:H}}));}}},[V,U]),ke=useCallback(async u=>{if(u.preventDefault(),!(!S.trim()||w))try{await g({type:p,message:S}),m(""),c(!1),setTimeout(()=>{G(),de();},500);}catch{}},[p,S,w,g,G,de]),we=u=>{let _=E[u.id];return {count:_?.count??u.vote_count,hasVoted:_?.hasVoted??u.user_has_voted}};if(!d)return s?jsx("div",{style:f.empty,children:jsx("p",{children:"Please sign in to view your requests."})}):null;if(F)return jsx("div",{style:f.loading,children:jsx("p",{children:"Loading requests..."})});if(A)return jsx("div",{style:f.error,children:jsxs("p",{children:["Failed to load requests. ",jsx("button",{onClick:G,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})});let ue=()=>T.allowRequestCreation?Ce?jsx("div",{style:f.successMessage,children:"Thanks for your feedback! It has been submitted."}):a?jsxs("form",{onSubmit:ke,style:f.form,children:[jsxs("div",{style:f.formHeader,children:[jsx("p",{style:f.formTitle,children:"Submit a request"}),jsx("button",{type:"button",onClick:()=>c(false),style:{background:"none",border:"none",cursor:"pointer",color:"#6b7280"},children:"\u2715"})]}),jsx("div",{style:f.typeSelector,children:He.map(u=>jsx("button",{type:"button",onClick:()=>C(u.value),style:{...f.typeButton,...p===u.value?f.typeButtonActive:{}},children:u.label},u.value))}),jsx("textarea",{value:S,onChange:u=>m(u.target.value),placeholder:"Describe your request...",style:f.textarea,required:true}),jsx("button",{type:"submit",style:{...f.submitButton,opacity:w?.6:1},disabled:w,children:w?"Submitting...":"Submit"})]}):jsxs("button",{onClick:()=>c(true),style:{...f.submitButton,marginBottom:"16px",display:"flex",alignItems:"center",gap:"6px"},children:[jsx("svg",{width:"14",height:"14",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"New Request"]}):null;if(B.length===0&&s)return jsxs("div",{style:f.container,className:o,children:[ue(),jsxs("div",{style:f.empty,children:[jsx("svg",{style:f.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:T.allowRequestCreation?"Submit your first request above.":"When you submit feedback, bug reports, or feature requests, they'll appear here."})]})]});let N=T.allowVoting&&T.feedbackVisibility!=="own";return jsxs("div",{style:f.container,className:o,children:[ue(),jsx("ul",{style:f.list,children:B.map(u=>{let _=ye[u.feedback_type]||ye.feedback,H=he[u.status]||he.new,O=i===u.id,q=we(u);return jsx("li",{style:{...f.card,...O?f.cardHover:{}},onMouseEnter:()=>n(u.id),onMouseLeave:()=>n(null),children:jsxs("div",{style:N?f.cardWithVote:void 0,children:[N&&jsxs("button",{onClick:j=>{j.stopPropagation(),ve(u.id,q.count,q.hasVoted);},disabled:U,style:{...f.voteButton,...q.hasVoted?f.voteButtonActive:{}},title:q.hasVoted?"Remove vote":"Upvote this request",children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:q.hasVoted?"currentColor":"none",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 15l7-7 7 7"})}),jsx("span",{style:{...f.voteCount,...q.hasVoted?{color:"#2563eb"}:{}},children:q.count})]}),jsxs("div",{style:N?f.cardContent:void 0,onClick:()=>ce(u),role:"button",tabIndex:0,onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&ce(u);},children:[jsx("div",{style:f.header,children:jsxs("div",{style:f.badges,children:[jsx("span",{style:{...f.badge,color:_.color,backgroundColor:_.bg},children:_.label}),jsx("span",{style:{...f.badge,color:H.color,backgroundColor:H.bg},children:H.label}),u.is_own&&jsx("span",{style:f.ownBadge,children:"You"})]})}),jsx("p",{style:f.message,children:u.message||"No message provided"}),jsxs("div",{style:f.meta,children:[jsx("span",{children:Me(u.created_at)}),!N&&q.count>0&&jsxs("span",{children:[q.count," vote",q.count!==1?"s":""]}),u.page_url&&jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",u.page_url]})]})]})]})},u.id)})})]})}var De={articles:"Articles",requests:"My Requests"},K={container:{fontFamily:"system-ui, -apple-system, sans-serif"},tabsContainer:{display:"flex",gap:"4px",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"8px",marginBottom:"24px"},tab:{flex:1,padding:"8px 16px",fontSize:"14px",fontWeight:500,border:"none",borderRadius:"6px",cursor:"pointer",transition:"all 0.15s",backgroundColor:"transparent",color:"#6b7280"},tabActive:{backgroundColor:"#ffffff",color:"#111827",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.05)"}};function $e({tabs:r=["articles","requests"],defaultTab:e="articles",tabLabels:t={},showSearch:o=true,showCategories:s=true,className:l}){let[d,i]=useState(e),n={...De,...t};return r.length===1?jsxs("div",{style:K.container,className:l,children:[r[0]==="articles"&&jsx(J,{showSearch:o,showCategories:s}),r[0]==="requests"&&jsx(X,{})]}):jsxs("div",{style:K.container,className:l,children:[jsx("div",{style:K.tabsContainer,children:r.map(a=>jsx("button",{onClick:()=>i(a),style:{...K.tab,...d===a?K.tabActive:{}},children:n[a]},a))}),d==="articles"&&r.includes("articles")&&jsx(J,{showSearch:o,showCategories:s}),d==="requests"&&r.includes("requests")&&jsx(X,{})]})}
|
|
2
|
-
|
|
1
|
+
import {createContext,useState,useMemo,useEffect,useContext,useCallback,useRef}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Me="https://api.census.ai",pe=class{constructor(e){this.currentUserId=null;if(!e.apiKey)throw new Error("Census: apiKey is required");["cs_live_","cs_test_","op_live_","op_test_"].some(n=>e.apiKey.startsWith(n))||console.warn('Census: API key should start with "cs_live_" or "cs_test_"'),this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||Me,this.debug=e.debug||false,this.log("Initialized with base URL:",this.baseUrl);}async identify(e){if(!e.userId)throw new Error("Census: userId is required for identify()");this.currentUserId=e.userId,await this.request("/api/sdk/identify","POST",{userId:e.userId,email:e.email,name:e.name,avatarUrl:e.avatarUrl,metadata:e.metadata,organizationId:e.organizationId,organizationName:e.organizationName,organizationDomain:e.organizationDomain,organizationPlan:e.organizationPlan}),this.log("User identified:",e.userId);}reset(){this.currentUserId=null,this.log("User identity reset");}async submitFeedback(e){let t=["feedback","bug_report","feature_request","article_rating"];if(!e.type||!t.includes(e.type))throw new Error(`Census: type must be one of: ${t.join(", ")}`);if(e.type==="article_rating"){if(e.rating===void 0&&e.helpful===void 0)throw new Error("Census: article_rating requires rating or helpful field")}else if(!e.message)throw new Error("Census: message is required for this feedback type");let n=await this.request("/api/sdk/feedback","POST",{type:e.type,message:e.message,rating:e.rating,helpful:e.helpful,userId:this.currentUserId,articleId:e.articleId,pageUrl:typeof window<"u"?window.location.href:void 0,metadata:e.metadata});return this.log("Feedback submitted:",n.feedbackId),{feedbackId:n.feedbackId}}async getArticles(e){let t=new URLSearchParams;e?.category&&t.set("category",e.category),e?.search&&t.set("search",e.search),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let n=t.toString(),i=`/api/sdk/articles${n?`?${n}`:""}`,d=await this.request(i,"GET");return this.log("Fetched articles:",d.articles.length),d}async getArticle(e){try{let t=await this.request(`/api/sdk/articles/${encodeURIComponent(e)}`,"GET");return this.log("Fetched article:",e),t.article}catch(t){if(t.status===404)return null;throw t}}async getFeatureGroups(){let e=await this.request("/api/sdk/feature-groups","GET");return this.log("Fetched feature groups:",e.feature_groups.length),e}async getRequests(e){if(!this.currentUserId)throw new Error("Census: User must be identified before fetching requests. Call identify() first.");let t=new URLSearchParams;t.set("userId",this.currentUserId),e?.status&&t.set("status",e.status),e?.type&&t.set("type",e.type),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let n=await this.request(`/api/sdk/requests?${t.toString()}`,"GET");return this.log("Fetched requests:",n.requests.length),n}async vote(e){if(!this.currentUserId)throw new Error("Census: User must be identified before voting. Call identify() first.");if(!e)throw new Error("Census: feedbackId is required for vote()");let t=await this.request("/api/sdk/requests/vote","POST",{feedbackId:e,userId:this.currentUserId});return this.log("Vote result:",t.action,"for feedback:",e),t}async track(e,t){if(!e)throw new Error("Census: eventType is required for track()");await this.request("/api/sdk/events","POST",{eventType:e,userId:this.currentUserId,properties:t}),this.log("Event tracked:",e);}async trackBatch(e){if(!e.events||e.events.length===0)throw new Error("Census: at least one event is required");if(e.events.length>100)throw new Error("Census: maximum 100 events per batch");let t=e.events.map(n=>({eventType:n.eventType,userId:this.currentUserId,articleId:n.articleId,featureId:n.featureId,properties:n.properties}));await this.request("/api/sdk/events","POST",{events:t}),this.log("Batch events tracked:",e.events.length);}async getGuides(){let e=new URLSearchParams;this.currentUserId&&e.set("userId",this.currentUserId);let t=e.toString(),n=`/api/sdk/guides${t?`?${t}`:""}`,i=await this.request(n,"GET");return this.log("Fetched guides:",i.guides.length),i}async getGuide(e){try{let t=new URLSearchParams;this.currentUserId&&t.set("userId",this.currentUserId);let n=t.toString(),i=`/api/sdk/guides/${encodeURIComponent(e)}${n?`?${n}`:""}`,d=await this.request(i,"GET");return this.log("Fetched guide:",e),d.guide}catch(t){if(t.status===404)return null;throw t}}async trackGuideEvent(e){if(!e.guideId||!e.eventType||!e.sessionId)throw new Error("Census: guideId, eventType, and sessionId are required for trackGuideEvent()");await this.request("/api/sdk/guides/events","POST",{guideId:e.guideId,eventType:e.eventType,stepId:e.stepId,stepIndex:e.stepIndex,pageUrl:e.pageUrl||(typeof window<"u"?window.location.href:void 0),sessionId:e.sessionId,userId:e.userId||this.currentUserId,metadata:e.metadata}),this.log("Guide event tracked:",e.eventType,e.guideId);}async markGuideCompleted(e){if(!e)throw new Error("Census: guideId is required for markGuideCompleted()");if(!this.currentUserId)throw new Error("Census: User must be identified before marking guides complete. Call identify() first.");await this.request("/api/sdk/guides/complete","POST",{guideId:e,userId:this.currentUserId}),this.log("Guide marked completed:",e);}getCurrentUserId(){return this.currentUserId}isIdentified(){return this.currentUserId!==null}async request(e,t,n){let i=`${this.baseUrl}${e}`,d={"X-Census-Key":this.apiKey};n&&(d["Content-Type"]="application/json"),this.log(`${t} ${e}`,n);let g=await fetch(i,{method:t,headers:d,body:n?JSON.stringify(n):void 0});if(!g.ok){let l=`Request failed with status ${g.status}`;try{l=(await g.json()).error||l;}catch{}throw {error:l,status:g.status}}return g.json()}log(...e){this.debug&&console.log("[Census]",...e);}};function ke(o){return new pe(o)}var fe=createContext(null);function De({apiKey:o,baseUrl:e,debug:t,user:n,theme:i={},children:d}){let[g,l]=useState(false),[u,f]=useState(false),c=useMemo(()=>ke({apiKey:o,baseUrl:e,debug:t}),[o,e,t]);useEffect(()=>{n?c.identify(n).then(()=>{f(true),l(true);}).catch(S=>{console.error("[Census] Failed to identify user:",S),l(true);}):l(true);},[c,n]);let b=useMemo(()=>({client:c,theme:i,isReady:g,isIdentified:u}),[c,i,g,u]);return jsx(fe.Provider,{value:b,children:d})}function Ge(){let o=useContext(fe);if(!o)throw new Error("useCensus must be used within a CensusProvider");return o.client}function R(){let o=useContext(fe);if(!o)throw new Error("useCensusContext must be used within a CensusProvider");return o}function He(){let{client:o}=R(),[e,t]=useState(false),[n,i]=useState(null);return {identify:async l=>{t(true),i(null);try{await o.identify(l);}catch(u){throw i(u instanceof Error?u:new Error("Failed to identify user")),u}finally{t(false);}},reset:()=>{o.reset();},isIdentifying:e,isIdentified:o.isIdentified(),error:n}}function X(){let{client:o}=R(),[e,t]=useState(false),[n,i]=useState(false),[d,g]=useState(null),[l,u]=useState(null),f=useCallback(async b=>{t(true),i(false),g(null),u(null);try{let S=await o.submitFeedback(b);return u(S.feedbackId),i(!0),S}catch(S){let I=S instanceof Error?S:new Error("Failed to submit feedback");throw g(I),I}finally{t(false);}},[o]),c=useCallback(()=>{i(false),g(null),u(null);},[]);return {submitFeedback:f,reset:c,isSubmitting:e,isSuccess:n,error:d,feedbackId:l}}function ee(o){let{client:e,isReady:t}=R(),[n,i]=useState(null),[d,g]=useState(true),[l,u]=useState(null),f=useCallback(async()=>{g(true),u(null);try{let c=await e.getArticles(o);i(c);}catch(c){u(c instanceof Error?c:new Error("Failed to fetch articles"));}finally{g(false);}},[e,o?.category,o?.search,o?.limit,o?.offset]);return useEffect(()=>{t&&f();},[t,f]),{articles:n?.articles||[],pagination:n?.pagination,isLoading:d,error:l,refetch:f}}function te(o){let{client:e,isReady:t}=R(),[n,i]=useState(null),[d,g]=useState(true),[l,u]=useState(null),f=useCallback(async()=>{if(!o){i(null),g(false);return}g(true),u(null);try{let c=await e.getArticle(o);i(c);}catch(c){u(c instanceof Error?c:new Error("Failed to fetch article"));}finally{g(false);}},[e,o]);return useEffect(()=>{t&&f();},[t,f]),{article:n,isLoading:d,error:l,refetch:f}}var Oe={feedbackVisibility:"own",allowVoting:false,allowRequestCreation:true};function re(o){let{client:e,isReady:t,isIdentified:n}=R(),[i,d]=useState(null),[g,l]=useState(true),[u,f]=useState(null),c=useCallback(async()=>{if(!n){d(null),l(false);return}l(true),f(null);try{let b=await e.getRequests(o);d(b);}catch(b){f(b instanceof Error?b:new Error("Failed to fetch requests"));}finally{l(false);}},[e,n,o?.status,o?.type,o?.limit,o?.offset]);return useEffect(()=>{t&&(n?c():l(false));},[t,n,c]),{requests:i?.requests||[],pagination:i?.pagination,settings:i?.settings||Oe,isLoading:g,error:u,refetch:c}}function ge(){let{client:o}=R(),[e,t]=useState(false),[n,i]=useState(null);return {vote:useCallback(async g=>{t(true),i(null);try{return await o.vote(g)}catch(l){let u=l instanceof Error?l:new Error("Failed to vote");throw i(u),u}finally{t(false);}},[o]),isVoting:e,error:n}}function Ne(){let{client:o}=R(),e=useCallback(async(n,i)=>{await o.track(n,i);},[o]),t=useCallback(async n=>{await o.trackBatch({events:n});},[o]);return {track:e,trackBatch:t}}function be(){let{client:o,isReady:e}=R(),[t,n]=useState([]),[i,d]=useState(true),[g,l]=useState(null),u=useCallback(async()=>{d(true),l(null);try{let f=await o.getFeatureGroups();n(f.feature_groups);}catch(f){l(f instanceof Error?f:new Error("Failed to fetch feature groups"));}finally{d(false);}},[o]);return useEffect(()=>{e&&u();},[e,u]),{featureGroups:t,isLoading:i,error:g,refetch:u}}var $={button:{position:"fixed",padding:"12px 20px",border:"none",borderRadius:"8px",cursor:"pointer",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",fontWeight:"500",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",transition:"transform 0.2s, box-shadow 0.2s",zIndex:9999},modal:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",zIndex:1e4},modalContent:{backgroundColor:"white",borderRadius:"12px",padding:"24px",width:"100%",maxWidth:"400px",margin:"16px",boxShadow:"0 20px 50px rgba(0, 0, 0, 0.2)",fontFamily:"system-ui, -apple-system, sans-serif"},textarea:{width:"100%",padding:"10px 12px",border:"1px solid #e0e0e0",borderRadius:"6px",fontSize:"14px",marginBottom:"16px",minHeight:"100px",resize:"vertical",boxSizing:"border-box",fontFamily:"inherit"},submitButton:{width:"100%",padding:"12px",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"500",transition:"opacity 0.2s"},typeButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"6px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"}},je={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},Ke={feedback:"General Feedback",bug_report:"Bug Report",feature_request:"Feature Request",article_rating:"Article Rating"},$e={feedback:"\u{1F4AC}",bug_report:"\u{1F41B}",feature_request:"\u{1F4A1}",article_rating:"\u2B50"};function Ye(o){return {primaryColor:o.primaryColor||"#000000",textColor:o.textColor||"#333333",backgroundColor:o.backgroundColor||"#ffffff",borderRadius:o.borderRadius||"8px",fontFamily:o.fontFamily||"system-ui, -apple-system, sans-serif"}}function Qe({position:o="bottom-right",text:e="Feedback",allowedTypes:t=["feedback","bug_report","feature_request"],theme:n,onSubmit:i,onError:d,children:g}){let{theme:l}=R(),{submitFeedback:u,isSubmitting:f,isSuccess:c,reset:b}=X(),[S,I]=useState(false),[v,M]=useState(t[0]),[T,A]=useState(""),E={...l,...n},L=Ye(E),D=useCallback(()=>{I(true),b();},[b]),_=useCallback(()=>{I(false),A(""),M(t[0]);},[t]),G=useCallback(async U=>{U.preventDefault();let m={type:v,message:T};try{await u(m),i?.(m),setTimeout(_,1500);}catch(C){d?.(C instanceof Error?C:new Error("Failed to submit feedback"));}},[v,T,u,i,d,_]);return g?jsxs(Fragment,{children:[jsx("div",{onClick:D,style:{cursor:"pointer"},children:g}),S&&jsx(Se,{isOpen:S,onClose:_,selectedType:v,onTypeChange:M,allowedTypes:t,message:T,onMessageChange:A,onSubmit:G,isSubmitting:f,isSuccess:c,themeStyles:L})]}):jsxs(Fragment,{children:[jsx("button",{onClick:D,style:{...$.button,...je[o],backgroundColor:L.primaryColor,color:"white",borderRadius:L.borderRadius,fontFamily:L.fontFamily},"aria-label":"Open feedback form",children:e}),S&&jsx(Se,{isOpen:S,onClose:_,selectedType:v,onTypeChange:M,allowedTypes:t,message:T,onMessageChange:A,onSubmit:G,isSubmitting:f,isSuccess:c,themeStyles:L})]})}function Se({isOpen:o,onClose:e,selectedType:t,onTypeChange:n,allowedTypes:i,message:d,onMessageChange:g,onSubmit:l,isSubmitting:u,isSuccess:f,themeStyles:c}){return o?f?jsx("div",{style:$.modal,onClick:e,children:jsxs("div",{style:{...$.modalContent,textAlign:"center",fontFamily:c.fontFamily},onClick:b=>b.stopPropagation(),children:[jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"\u{1F389}"}),jsx("h3",{style:{margin:"0 0 8px 0",color:c.textColor},children:"Thanks for your feedback!"}),jsx("p",{style:{margin:0,color:"#666"},children:"We appreciate you taking the time to share."})]})}):jsx("div",{style:$.modal,onClick:e,children:jsxs("div",{style:{...$.modalContent,fontFamily:c.fontFamily},onClick:b=>b.stopPropagation(),children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[jsx("h3",{style:{margin:0,color:c.textColor},children:"Send Feedback"}),jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer",color:"#999",padding:"0",lineHeight:"1"},"aria-label":"Close",children:"\xD7"})]}),jsxs("form",{onSubmit:l,children:[jsxs("div",{style:{marginBottom:"16px"},children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"What kind of feedback?"}),jsx("div",{style:{display:"flex",flexWrap:"wrap"},children:i.map(b=>jsxs("button",{type:"button",onClick:()=>n(b),style:{...$.typeButton,backgroundColor:t===b?c.primaryColor:"white",color:t===b?"white":c.textColor,borderColor:t===b?c.primaryColor:"#e0e0e0"},children:[$e[b]," ",Ke[b]]},b))})]}),jsxs("div",{children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"Your message"}),jsx("textarea",{value:d,onChange:b=>g(b.target.value),placeholder:t==="bug_report"?"Describe the bug and steps to reproduce...":t==="feature_request"?"Describe the feature you would like...":"Share your thoughts...",style:$.textarea,required:true})]}),jsx("button",{type:"submit",disabled:u||!d.trim(),style:{...$.submitButton,backgroundColor:c.primaryColor,color:"white",opacity:u||!d.trim()?.6:1,cursor:u||!d.trim()?"not-allowed":"pointer"},children:u?"Sending...":"Send Feedback"})]})]})}):null}var k={container:{fontFamily:"system-ui, -apple-system, sans-serif",maxWidth:"800px"},searchInput:{width:"100%",padding:"12px 16px",border:"1px solid #e0e0e0",borderRadius:"8px",fontSize:"15px",marginBottom:"24px",boxSizing:"border-box"},categoryButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"20px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"},articleCard:{padding:"20px",border:"1px solid #e0e0e0",borderRadius:"8px",marginBottom:"12px",cursor:"pointer",transition:"box-shadow 0.2s, border-color 0.2s",backgroundColor:"white"},articleTitle:{margin:"0 0 8px 0",fontSize:"16px",fontWeight:"600"},articleDescription:{margin:0,fontSize:"14px",color:"#666",lineHeight:1.5},articleMeta:{display:"flex",gap:"16px",marginTop:"12px",fontSize:"12px",color:"#999"},backButton:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"8px 0",border:"none",background:"none",cursor:"pointer",fontSize:"14px",color:"#666",marginBottom:"16px"},articleContent:{lineHeight:1.7,fontSize:"15px"},loading:{textAlign:"center",padding:"40px",color:"#666"},error:{padding:"20px",backgroundColor:"#fef2f2",borderRadius:"8px",color:"#b91c1c",textAlign:"center"},empty:{textAlign:"center",padding:"40px",color:"#666"}};function Xe(o){return {primaryColor:o.primaryColor||"#000000",textColor:o.textColor||"#333333",backgroundColor:o.backgroundColor||"#ffffff",borderRadius:o.borderRadius||"8px",fontFamily:o.fontFamily||"system-ui, -apple-system, sans-serif"}}function Ze({showSearch:o=true,showCategories:e=true,defaultCategory:t,theme:n,className:i,onArticleView:d}){let{theme:g}=R(),[l,u]=useState(""),[f,c]=useState(t),[b,S]=useState(null),I={...g,...n},v=Xe(I),{articles:M,isLoading:T,error:A}=ee({category:f,search:l||void 0}),{article:E,isLoading:L,error:D}=te(b||""),_=useMemo(()=>{let m=new Set;return M.forEach(C=>{C.category&&m.add(C.category);}),Array.from(m).sort()},[M]),G=m=>{S(m.slug),d?.(m);},U=()=>{S(null);};return b?L?jsx("div",{style:{...k.container,fontFamily:v.fontFamily},className:i,children:jsx("div",{style:k.loading,children:"Loading article..."})}):D?jsxs("div",{style:{...k.container,fontFamily:v.fontFamily},className:i,children:[jsx("button",{onClick:U,style:k.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:k.error,children:"Failed to load article. Please try again."})]}):E?jsxs("div",{style:{...k.container,fontFamily:v.fontFamily},className:i,children:[jsx("button",{onClick:U,style:k.backButton,children:"\u2190 Back to articles"}),jsxs("article",{children:[jsx("h1",{style:{margin:"0 0 16px 0",color:v.textColor},children:E.title}),E.read_time_minutes&&jsxs("div",{style:{fontSize:"14px",color:"#666",marginBottom:"24px"},children:[E.read_time_minutes," min read"]}),E.content_html?jsx("div",{style:{...k.articleContent,color:v.textColor},dangerouslySetInnerHTML:{__html:E.content_html}}):jsx("div",{style:{...k.articleContent,color:v.textColor},children:typeof E.content=="string"?E.content:"No content available."})]})]}):jsxs("div",{style:{...k.container,fontFamily:v.fontFamily},className:i,children:[jsx("button",{onClick:U,style:k.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:k.empty,children:"Article not found."})]}):jsxs("div",{style:{...k.container,fontFamily:v.fontFamily},className:i,children:[o&&jsx("input",{type:"text",placeholder:"Search articles...",value:l,onChange:m=>u(m.target.value),style:k.searchInput}),e&&_.length>0&&jsxs("div",{style:{marginBottom:"24px"},children:[jsx("button",{onClick:()=>c(void 0),style:{...k.categoryButton,backgroundColor:f?"white":v.primaryColor,color:f?v.textColor:"white",borderColor:f?"#e0e0e0":v.primaryColor},children:"All"}),_.map(m=>jsx("button",{onClick:()=>c(m),style:{...k.categoryButton,backgroundColor:f===m?v.primaryColor:"white",color:f===m?"white":v.textColor,borderColor:f===m?v.primaryColor:"#e0e0e0"},children:m},m))]}),T&&jsx("div",{style:k.loading,children:"Loading articles..."}),A&&jsx("div",{style:k.error,children:"Failed to load articles. Please try again."}),!T&&!A&&M.length===0&&jsx("div",{style:k.empty,children:l?`No articles found for "${l}"`:"No articles available yet."}),!T&&!A&&M.length>0&&jsx("div",{children:M.map(m=>jsxs("div",{onClick:()=>G(m),style:k.articleCard,role:"button",tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&G(m);},children:[jsx("h3",{style:{...k.articleTitle,color:v.textColor},children:m.title}),m.seo_description&&jsx("p",{style:k.articleDescription,children:m.seo_description}),jsxs("div",{style:k.articleMeta,children:[m.category&&jsx("span",{children:m.category}),m.read_time_minutes&&jsxs("span",{children:[m.read_time_minutes," min read"]})]})]},m.id))})]})}var y={container:{fontFamily:"system-ui, -apple-system, sans-serif"},list:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"12px"},card:{border:"1px solid #e5e7eb",borderRadius:"8px",padding:"16px",backgroundColor:"#ffffff",cursor:"pointer",transition:"border-color 0.15s, box-shadow 0.15s"},cardHover:{borderColor:"#d1d5db",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",marginBottom:"8px"},badges:{display:"flex",alignItems:"center",gap:"6px"},badge:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",fontSize:"12px",fontWeight:500},message:{fontSize:"14px",color:"#111827",margin:0,lineHeight:1.5},meta:{display:"flex",gap:"12px",marginTop:"8px",fontSize:"12px",color:"#6b7280"},empty:{textAlign:"center",padding:"32px 16px",color:"#6b7280"},emptyIcon:{width:"48px",height:"48px",margin:"0 auto 12px",color:"#d1d5db"},loading:{textAlign:"center",padding:"24px",color:"#6b7280"},error:{textAlign:"center",padding:"24px",color:"#dc2626"},voteButton:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"8px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",cursor:"pointer",minWidth:"48px",transition:"all 0.15s"},voteButtonActive:{backgroundColor:"#dbeafe",borderColor:"#2563eb",color:"#2563eb"},voteCount:{fontSize:"14px",fontWeight:600,color:"#111827"},cardWithVote:{display:"flex",gap:"12px"},cardContent:{flex:1},form:{marginBottom:"16px",padding:"16px",backgroundColor:"#f9fafb",borderRadius:"8px",border:"1px solid #e5e7eb"},formHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},formTitle:{fontSize:"14px",fontWeight:500,color:"#111827",margin:0},typeSelector:{display:"flex",gap:"8px",marginBottom:"12px"},typeButton:{padding:"6px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",fontSize:"13px",cursor:"pointer",transition:"all 0.15s"},typeButtonActive:{backgroundColor:"#111827",borderColor:"#111827",color:"#ffffff"},textarea:{width:"100%",padding:"10px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",fontSize:"14px",resize:"vertical",minHeight:"80px",fontFamily:"inherit",marginBottom:"12px"},submitButton:{padding:"8px 16px",borderRadius:"6px",border:"none",backgroundColor:"#111827",color:"#ffffff",fontSize:"14px",fontWeight:500,cursor:"pointer",transition:"opacity 0.15s"},successMessage:{padding:"12px",backgroundColor:"#d1fae5",borderRadius:"6px",color:"#059669",fontSize:"14px",marginBottom:"16px"},ownBadge:{display:"inline-flex",alignItems:"center",padding:"2px 6px",borderRadius:"9999px",fontSize:"11px",fontWeight:500,backgroundColor:"#f3f4f6",color:"#6b7280",marginLeft:"6px"}},Re={feedback:{label:"Feedback",color:"#2563eb",bg:"#dbeafe"},bug_report:{label:"Bug Report",color:"#dc2626",bg:"#fee2e2"},feature_request:{label:"Feature Request",color:"#d97706",bg:"#fef3c7"},article_rating:{label:"Article Rating",color:"#7c3aed",bg:"#ede9fe"}},Fe={new:{label:"New",color:"#6b7280",bg:"#f3f4f6"},reviewed:{label:"Reviewed",color:"#2563eb",bg:"#dbeafe"},in_progress:{label:"In Progress",color:"#d97706",bg:"#fef3c7"},resolved:{label:"Resolved",color:"#059669",bg:"#d1fae5"},closed:{label:"Closed",color:"#6b7280",bg:"#f3f4f6"}};function et(o){return new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}var tt=[{value:"feedback",label:"Feedback"},{value:"bug_report",label:"Bug"},{value:"feature_request",label:"Feature"}];function rt({status:o,type:e,limit:t=50,className:n,showEmptyState:i=true,onRequestClick:d}){let{isIdentified:g}=R(),[l,u]=useState(null),[f,c]=useState(false),[b,S]=useState("feedback"),[I,v]=useState(""),[M,T]=useState({}),{requests:A,isLoading:E,error:L,refetch:D,settings:_}=re({status:o,type:e,limit:t}),{vote:G,isVoting:U}=ge(),{submitFeedback:m,isSubmitting:C,isSuccess:ue,reset:Z}=X(),ne=useCallback(p=>{d?.(p);},[d]),se=useCallback(async(p,W,H)=>{if(!U){T(V=>({...V,[p]:{count:H?W-1:W+1,hasVoted:!H}}));try{let V=await G(p);T(z=>({...z,[p]:{count:V.vote_count,hasVoted:V.user_has_voted}}));}catch{T(V=>({...V,[p]:{count:W,hasVoted:H}}));}}},[G,U]),ie=useCallback(async p=>{if(p.preventDefault(),!(!I.trim()||C))try{await m({type:b,message:I}),v(""),c(!1),setTimeout(()=>{D(),Z();},500);}catch{}},[b,I,C,m,D,Z]),ae=p=>{let W=M[p.id];return {count:W?.count??p.vote_count,hasVoted:W?.hasVoted??p.user_has_voted}};if(!g)return i?jsx("div",{style:y.empty,children:jsx("p",{children:"Please sign in to view your requests."})}):null;if(E)return jsx("div",{style:y.loading,children:jsx("p",{children:"Loading requests..."})});if(L)return jsx("div",{style:y.error,children:jsxs("p",{children:["Failed to load requests. ",jsx("button",{onClick:D,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})});let le=()=>_.allowRequestCreation?ue?jsx("div",{style:y.successMessage,children:"Thanks for your feedback! It has been submitted."}):f?jsxs("form",{onSubmit:ie,style:y.form,children:[jsxs("div",{style:y.formHeader,children:[jsx("p",{style:y.formTitle,children:"Submit a request"}),jsx("button",{type:"button",onClick:()=>c(false),style:{background:"none",border:"none",cursor:"pointer",color:"#6b7280"},children:"\u2715"})]}),jsx("div",{style:y.typeSelector,children:tt.map(p=>jsx("button",{type:"button",onClick:()=>S(p.value),style:{...y.typeButton,...b===p.value?y.typeButtonActive:{}},children:p.label},p.value))}),jsx("textarea",{value:I,onChange:p=>v(p.target.value),placeholder:"Describe your request...",style:y.textarea,required:true}),jsx("button",{type:"submit",style:{...y.submitButton,opacity:C?.6:1},disabled:C,children:C?"Submitting...":"Submit"})]}):jsxs("button",{onClick:()=>c(true),style:{...y.submitButton,marginBottom:"16px",display:"flex",alignItems:"center",gap:"6px"},children:[jsx("svg",{width:"14",height:"14",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"New Request"]}):null;if(A.length===0&&i)return jsxs("div",{style:y.container,className:n,children:[le(),jsxs("div",{style:y.empty,children:[jsx("svg",{style:y.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:_.allowRequestCreation?"Submit your first request above.":"When you submit feedback, bug reports, or feature requests, they'll appear here."})]})]});let Q=_.allowVoting&&_.feedbackVisibility!=="own";return jsxs("div",{style:y.container,className:n,children:[le(),jsx("ul",{style:y.list,children:A.map(p=>{let W=Re[p.feedback_type]||Re.feedback,H=Fe[p.status]||Fe.new,V=l===p.id,z=ae(p);return jsx("li",{style:{...y.card,...V?y.cardHover:{}},onMouseEnter:()=>u(p.id),onMouseLeave:()=>u(null),children:jsxs("div",{style:Q?y.cardWithVote:void 0,children:[Q&&jsxs("button",{onClick:J=>{J.stopPropagation(),se(p.id,z.count,z.hasVoted);},disabled:U,style:{...y.voteButton,...z.hasVoted?y.voteButtonActive:{}},title:z.hasVoted?"Remove vote":"Upvote this request",children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:z.hasVoted?"currentColor":"none",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 15l7-7 7 7"})}),jsx("span",{style:{...y.voteCount,...z.hasVoted?{color:"#2563eb"}:{}},children:z.count})]}),jsxs("div",{style:Q?y.cardContent:void 0,onClick:()=>ne(p),role:"button",tabIndex:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&ne(p);},children:[jsx("div",{style:y.header,children:jsxs("div",{style:y.badges,children:[jsx("span",{style:{...y.badge,color:W.color,backgroundColor:W.bg},children:W.label}),jsx("span",{style:{...y.badge,color:H.color,backgroundColor:H.bg},children:H.label}),p.is_own&&jsx("span",{style:y.ownBadge,children:"You"})]})}),jsx("p",{style:y.message,children:p.message||"No message provided"}),jsxs("div",{style:y.meta,children:[jsx("span",{children:et(p.created_at)}),!Q&&z.count>0&&jsxs("span",{children:[z.count," vote",z.count!==1?"s":""]}),p.page_url&&jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",p.page_url]})]})]})]})},p.id)})})]})}var at={articles:"Documentation",requests:"My Requests"},Te={feedback:{label:"Feedback",color:"#2563eb",bg:"#dbeafe"},bug_report:{label:"Bug Report",color:"#dc2626",bg:"#fee2e2"},feature_request:{label:"Feature Request",color:"#d97706",bg:"#fef3c7"},article_rating:{label:"Article Rating",color:"#7c3aed",bg:"#ede9fe"}},Be={new:{label:"New",color:"#6b7280",bg:"#f3f4f6"},reviewed:{label:"Reviewed",color:"#2563eb",bg:"#dbeafe"},in_progress:{label:"In Progress",color:"#d97706",bg:"#fef3c7"},resolved:{label:"Resolved",color:"#059669",bg:"#d1fae5"},closed:{label:"Closed",color:"#6b7280",bg:"#f3f4f6"}};function lt(o){return new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}var dt=[{value:"feedback",label:"Feedback"},{value:"bug_report",label:"Bug"},{value:"feature_request",label:"Feature"}],ct=()=>jsx("svg",{width:"16",height:"16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),qe=()=>jsx("svg",{width:"20",height:"20",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})}),_e=()=>jsx("svg",{width:"20",height:"20",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),ut=()=>jsx("svg",{width:"16",height:"16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),pt=()=>jsx("svg",{width:"16",height:"16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),ft=()=>jsx("svg",{width:"16",height:"16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),gt=()=>jsx("svg",{width:"16",height:"16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),bt=()=>jsx("svg",{width:"48",height:"48",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),mt=()=>jsx("svg",{width:"16",height:"16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),ve=()=>jsx("svg",{width:"20",height:"20",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",style:{animation:"spin 1s linear infinite"},children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})}),s={container:{fontFamily:"system-ui, -apple-system, sans-serif",minHeight:"400px"},grid:{display:"grid",gridTemplateColumns:"240px 1fr",gap:"48px"},sidebar:{position:"sticky",top:"24px",height:"fit-content"},main:{minWidth:0},tabs:{display:"flex",gap:"4px",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"8px",marginBottom:"24px"},tab:{flex:1,padding:"8px 16px",fontSize:"14px",fontWeight:500,border:"none",borderRadius:"6px",cursor:"pointer",transition:"all 0.15s",backgroundColor:"transparent",color:"#6b7280"},tabActive:{backgroundColor:"#ffffff",color:"#111827",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.05)"},searchContainer:{position:"relative",marginBottom:"24px"},searchIcon:{position:"absolute",left:"12px",top:"50%",transform:"translateY(-50%)",color:"#9ca3af"},searchInput:{width:"100%",padding:"8px 12px 8px 36px",fontSize:"14px",border:"1px solid #e5e7eb",borderRadius:"8px",outline:"none"},sectionTitle:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#6b7280",marginBottom:"12px"},navList:{listStyle:"none",padding:0,margin:0},navItem:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",fontSize:"14px",color:"#4b5563",backgroundColor:"transparent",border:"none",borderRadius:"6px",cursor:"pointer",textAlign:"left"},navItemActive:{backgroundColor:"#f3f4f6",color:"#111827",fontWeight:500},subNav:{marginLeft:"24px",marginTop:"4px",paddingLeft:"12px",borderLeft:"1px solid #e5e7eb"},articleGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(280px, 1fr))",gap:"16px"},articleCard:{display:"flex",alignItems:"flex-start",gap:"16px",padding:"16px",border:"1px solid #e5e7eb",borderRadius:"8px",backgroundColor:"#ffffff",cursor:"pointer",transition:"all 0.15s",textAlign:"left"},articleIcon:{flexShrink:0,width:"40px",height:"40px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f3f4f6",borderRadius:"8px",color:"#6b7280"},articleContent:{flex:1,minWidth:0},articleTitle:{fontSize:"14px",fontWeight:500,color:"#111827",margin:0},articleDesc:{fontSize:"13px",color:"#6b7280",margin:"4px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},articleMeta:{fontSize:"12px",color:"#9ca3af",marginTop:"8px"},backButton:{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 0",fontSize:"14px",color:"#6b7280",backgroundColor:"transparent",border:"none",cursor:"pointer",marginBottom:"24px"},articleDetail:{maxWidth:"720px"},articleDetailTitle:{fontSize:"28px",fontWeight:700,color:"#111827",margin:0},articleDetailMeta:{display:"flex",alignItems:"center",gap:"4px",fontSize:"14px",color:"#6b7280",marginTop:"8px"},articleDetailContent:{marginTop:"32px",fontSize:"15px",lineHeight:1.7,color:"#374151"},emptyState:{textAlign:"center",padding:"48px 24px",color:"#6b7280"},emptyIcon:{color:"#d1d5db",marginBottom:"16px"},emptyTitle:{fontSize:"16px",fontWeight:500,color:"#111827",margin:"0 0 8px"},emptyText:{fontSize:"14px",margin:0},loading:{display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",padding:"48px",color:"#6b7280",fontSize:"14px"},requestCard:{border:"1px solid #e5e7eb",borderRadius:"8px",padding:"16px",backgroundColor:"#ffffff",marginBottom:"12px"},requestHeader:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},badge:{display:"inline-flex",alignItems:"center",padding:"2px 8px",borderRadius:"9999px",fontSize:"12px",fontWeight:500},requestMessage:{fontSize:"14px",color:"#111827",margin:0,lineHeight:1.5},requestMeta:{display:"flex",gap:"12px",marginTop:"8px",fontSize:"12px",color:"#6b7280"},form:{padding:"16px",backgroundColor:"#f9fafb",borderRadius:"8px",border:"1px solid #e5e7eb",marginBottom:"24px"},formHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},formTitle:{fontSize:"14px",fontWeight:500,color:"#111827",margin:0},typeSelector:{display:"flex",gap:"8px",marginBottom:"12px"},typeButton:{padding:"6px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",fontSize:"13px",cursor:"pointer",transition:"all 0.15s"},typeButtonActive:{backgroundColor:"#111827",borderColor:"#111827",color:"#ffffff"},textarea:{width:"100%",padding:"10px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",fontSize:"14px",resize:"vertical",minHeight:"80px",fontFamily:"inherit",marginBottom:"12px",boxSizing:"border-box"},submitButton:{padding:"8px 16px",borderRadius:"6px",border:"none",backgroundColor:"#111827",color:"#ffffff",fontSize:"14px",fontWeight:500,cursor:"pointer",transition:"opacity 0.15s"},newRequestButton:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 16px",borderRadius:"6px",border:"none",backgroundColor:"#111827",color:"#ffffff",fontSize:"14px",fontWeight:500,cursor:"pointer",marginBottom:"24px"},successMessage:{padding:"12px",backgroundColor:"#d1fae5",borderRadius:"6px",color:"#059669",fontSize:"14px",marginBottom:"16px"}},yt=`
|
|
2
|
+
@keyframes spin {
|
|
3
|
+
from { transform: rotate(0deg); }
|
|
4
|
+
to { transform: rotate(360deg); }
|
|
5
|
+
}
|
|
6
|
+
`;function ht({tabs:o=["articles","requests"],defaultTab:e="articles",tabLabels:t={},showSearch:n=true,className:i}){let[d,g]=useState(e),[l,u]=useState(""),[f,c]=useState(null),[b,S]=useState(new Set),[I,v]=useState(null),[M,T]=useState(false),[A,E]=useState("feedback"),[L,D]=useState(""),_=useRef(null),{isIdentified:G}=R(),{articles:U,isLoading:m}=ee({search:l||void 0}),{article:C,isLoading:ue}=te(f?.slug||""),{requests:Z,isLoading:ne,refetch:se,settings:ie}=re({limit:50}),{featureGroups:ae,isLoading:le}=be(),{submitFeedback:Q,isSubmitting:p,isSuccess:W,reset:H}=X(),V={...at,...t};useEffect(()=>{let a=B=>{(B.metaKey||B.ctrlKey)&&B.key==="k"&&(B.preventDefault(),_.current?.focus());};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[]);let z=a=>{S(B=>{let K=new Set(B);return K.has(a)?K.delete(a):K.add(a),K});},J=useMemo(()=>U.filter(a=>!I||a.feature_id===I),[U,I]),Ae=useCallback(async a=>{if(a.preventDefault(),!(!L.trim()||p))try{await Q({type:A,message:L}),D(""),T(!1),setTimeout(()=>{se(),H();},500);}catch{}},[A,L,p,Q,se,H]),Ee=()=>ue||!C?jsxs("div",{style:s.loading,children:[jsx(ve,{}),jsx("span",{children:"Loading article..."})]}):jsxs("div",{style:s.articleDetail,children:[jsxs("button",{onClick:()=>c(null),style:s.backButton,children:[jsx(pt,{}),"Back to articles"]}),jsx("h1",{style:s.articleDetailTitle,children:C.title}),C.read_time_minutes&&jsxs("div",{style:s.articleDetailMeta,children:[jsx(ft,{}),C.read_time_minutes," min read"]}),C.content_html?jsx("div",{style:s.articleDetailContent,dangerouslySetInnerHTML:{__html:C.content_html}}):jsx("p",{style:{...s.articleDetailContent,color:"#6b7280"},children:"No content available."})]}),Le=()=>f?Ee():m||le?jsxs("div",{style:s.loading,children:[jsx(ve,{}),jsx("span",{children:"Loading..."})]}):J.length===0?jsxs("div",{style:s.emptyState,children:[jsx("div",{style:s.emptyIcon,children:jsx(qe,{})}),jsx("h3",{style:s.emptyTitle,children:"No articles found"}),jsx("p",{style:s.emptyText,children:l?`No results for "${l}"`:"No documentation articles available yet."})]}):jsx("div",{style:s.articleGrid,children:J.map(a=>jsxs("button",{onClick:()=>c(a),style:s.articleCard,children:[jsx("div",{style:s.articleIcon,children:jsx(qe,{})}),jsxs("div",{style:s.articleContent,children:[jsx("h3",{style:s.articleTitle,children:a.title}),a.seo_description&&jsx("p",{style:s.articleDesc,children:a.seo_description}),a.read_time_minutes&&jsxs("p",{style:s.articleMeta,children:[a.read_time_minutes," min read"]})]}),jsx(_e,{})]},a.id))}),ze=()=>ie.allowRequestCreation?W?jsx("div",{style:s.successMessage,children:"Thanks for your feedback! It has been submitted."}):M?jsxs("form",{onSubmit:Ae,style:s.form,children:[jsxs("div",{style:s.formHeader,children:[jsx("p",{style:s.formTitle,children:"Submit a request"}),jsx("button",{type:"button",onClick:()=>T(false),style:{background:"none",border:"none",cursor:"pointer",color:"#6b7280",fontSize:"18px"},children:"\xD7"})]}),jsx("div",{style:s.typeSelector,children:dt.map(a=>jsx("button",{type:"button",onClick:()=>E(a.value),style:{...s.typeButton,...A===a.value?s.typeButtonActive:{}},children:a.label},a.value))}),jsx("textarea",{value:L,onChange:a=>D(a.target.value),placeholder:"Describe your request...",style:s.textarea,required:true}),jsx("button",{type:"submit",style:{...s.submitButton,opacity:p?.6:1},disabled:p,children:p?"Submitting...":"Submit"})]}):jsxs("button",{onClick:()=>T(true),style:s.newRequestButton,children:[jsx(mt,{}),"New Request"]}):null,Pe=()=>G?ne?jsxs("div",{style:s.loading,children:[jsx(ve,{}),jsx("span",{children:"Loading requests..."})]}):jsxs("div",{children:[ze(),Z.length===0?jsxs("div",{style:s.emptyState,children:[jsx("div",{style:s.emptyIcon,children:jsx(bt,{})}),jsx("h3",{style:s.emptyTitle,children:"No requests yet"}),jsx("p",{style:s.emptyText,children:ie.allowRequestCreation?"Submit your first request above.":"When you submit feedback, they'll appear here."})]}):jsx("div",{children:Z.map(a=>{let B=Te[a.feedback_type]||Te.feedback,K=Be[a.status]||Be.new;return jsxs("div",{style:s.requestCard,children:[jsxs("div",{style:s.requestHeader,children:[jsx("span",{style:{...s.badge,color:B.color,backgroundColor:B.bg},children:B.label}),jsx("span",{style:{...s.badge,color:K.color,backgroundColor:K.bg},children:K.label})]}),jsx("p",{style:s.requestMessage,children:a.message||"No message provided"}),jsx("div",{style:s.requestMeta,children:jsx("span",{children:lt(a.created_at)})})]},a.id)})})]}):jsx("div",{style:s.emptyState,children:jsx("p",{style:s.emptyText,children:"Please sign in to view your requests."})});return jsxs("div",{style:s.container,className:i,children:[jsx("style",{children:yt}),o.length>1&&jsx("div",{style:s.tabs,children:o.map(a=>jsx("button",{onClick:()=>g(a),style:{...s.tab,...d===a?s.tabActive:{}},children:V[a]},a))}),jsxs("div",{style:s.grid,children:[jsxs("aside",{style:s.sidebar,children:[n&&d==="articles"&&jsxs("div",{style:s.searchContainer,children:[jsx("div",{style:s.searchIcon,children:jsx(ct,{})}),jsx("input",{ref:_,type:"text",placeholder:"Search...",value:l,onChange:a=>u(a.target.value),style:s.searchInput})]}),d==="articles"&&ae.length>0&&jsxs("nav",{children:[jsx("h3",{style:s.sectionTitle,children:"Features"}),jsxs("ul",{style:s.navList,children:[jsx("li",{children:jsx("button",{onClick:()=>v(null),style:{...s.navItem,...I?{}:s.navItemActive},children:"All Articles"})}),ae.map(a=>jsxs("li",{children:[jsxs("button",{onClick:()=>z(a.id),style:s.navItem,children:[jsxs("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx(gt,{}),a.name]}),b.has(a.id)?jsx(ut,{}):jsx(_e,{})]}),b.has(a.id)&&a.features.length>0&&jsx("ul",{style:s.subNav,children:a.features.map(B=>jsx("li",{children:jsx("button",{onClick:()=>v(B.id),style:{...s.navItem,padding:"6px 12px",fontSize:"13px",...I===B.id?s.navItemActive:{}},children:B.name})},B.id))})]},a.id))]})]})]}),jsxs("main",{style:s.main,children:[d==="articles"&&Le(),d==="requests"&&Pe()]})]})]})}export{De as CensusProvider,Qe as FeedbackButton,ht as HelpCenter,Ze as KnowledgeBase,rt as Requests,te as useArticle,ee as useArticles,Ge as useCensus,R as useCensusContext,be as useFeatureGroups,X as useFeedback,He as useIdentify,re as useRequests,Ne as useTrack,ge as useVote};//# sourceMappingURL=index.js.map
|
|
3
7
|
//# sourceMappingURL=index.js.map
|