@inkeep/cxkit-primitives 0.5.15 → 0.5.17

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.
Files changed (237) hide show
  1. package/dist/components/embedded-search/use-inkeep-search.cjs +1 -1
  2. package/dist/components/embedded-search/use-inkeep-search.js +77 -76
  3. package/dist/index.d.cts +3695 -11
  4. package/dist/index.d.ts +3695 -11
  5. package/dist/providers/base-events-provider.cjs +1 -1
  6. package/dist/providers/base-events-provider.js +1 -1
  7. package/package.json +4 -4
  8. package/dist/atoms/api/analytics/conversation.d.cts +0 -3
  9. package/dist/atoms/api/analytics/conversation.d.ts +0 -3
  10. package/dist/atoms/api/analytics/events.d.cts +0 -2
  11. package/dist/atoms/api/analytics/events.d.ts +0 -2
  12. package/dist/atoms/api/analytics/feedback.d.cts +0 -11
  13. package/dist/atoms/api/analytics/feedback.d.ts +0 -11
  14. package/dist/atoms/avatars/ai.d.cts +0 -3
  15. package/dist/atoms/avatars/ai.d.ts +0 -3
  16. package/dist/atoms/avatars/user.d.cts +0 -3
  17. package/dist/atoms/avatars/user.d.ts +0 -3
  18. package/dist/atoms/cmdk/command-score.d.cts +0 -1
  19. package/dist/atoms/cmdk/command-score.d.ts +0 -1
  20. package/dist/atoms/cmdk/index.d.cts +0 -426
  21. package/dist/atoms/cmdk/index.d.ts +0 -426
  22. package/dist/atoms/codeblock/index.d.cts +0 -10
  23. package/dist/atoms/codeblock/index.d.ts +0 -10
  24. package/dist/atoms/custom-styles.d.cts +0 -5
  25. package/dist/atoms/custom-styles.d.ts +0 -5
  26. package/dist/atoms/dialog.d.cts +0 -95
  27. package/dist/atoms/dialog.d.ts +0 -95
  28. package/dist/atoms/icons/built-in-icon-renderer.d.cts +0 -6
  29. package/dist/atoms/icons/built-in-icon-renderer.d.ts +0 -6
  30. package/dist/atoms/icons/built-in-icons.d.cts +0 -72
  31. package/dist/atoms/icons/built-in-icons.d.ts +0 -72
  32. package/dist/atoms/icons/checkbox-icon.d.cts +0 -1
  33. package/dist/atoms/icons/checkbox-icon.d.ts +0 -1
  34. package/dist/atoms/icons/custom-icon.d.cts +0 -6
  35. package/dist/atoms/icons/custom-icon.d.ts +0 -6
  36. package/dist/atoms/icons/index.d.cts +0 -2
  37. package/dist/atoms/icons/index.d.ts +0 -2
  38. package/dist/atoms/icons/inkeep-default-icons.d.cts +0 -2
  39. package/dist/atoms/icons/inkeep-default-icons.d.ts +0 -2
  40. package/dist/atoms/link.d.cts +0 -14
  41. package/dist/atoms/link.d.ts +0 -14
  42. package/dist/atoms/markdown/components.d.cts +0 -27
  43. package/dist/atoms/markdown/components.d.ts +0 -27
  44. package/dist/atoms/markdown/index.d.cts +0 -15
  45. package/dist/atoms/markdown/index.d.ts +0 -15
  46. package/dist/atoms/markdown/rehype-inline-code-property.d.cts +0 -1
  47. package/dist/atoms/markdown/rehype-inline-code-property.d.ts +0 -1
  48. package/dist/atoms/portal-with-theme.d.cts +0 -2
  49. package/dist/atoms/portal-with-theme.d.ts +0 -2
  50. package/dist/atoms/portal.d.cts +0 -8
  51. package/dist/atoms/portal.d.ts +0 -8
  52. package/dist/atoms/shadow/context.d.cts +0 -14
  53. package/dist/atoms/shadow/context.d.ts +0 -14
  54. package/dist/atoms/shadow/create.d.cts +0 -8
  55. package/dist/atoms/shadow/create.d.ts +0 -8
  56. package/dist/atoms/shadow/index.d.cts +0 -1
  57. package/dist/atoms/shadow/index.d.ts +0 -1
  58. package/dist/atoms/shadow/root.d.cts +0 -5
  59. package/dist/atoms/shadow/root.d.ts +0 -5
  60. package/dist/atoms/shadow/use-ensured-forwarded-ref.d.cts +0 -2
  61. package/dist/atoms/shadow/use-ensured-forwarded-ref.d.ts +0 -2
  62. package/dist/atoms/shadow/utils.d.cts +0 -9
  63. package/dist/atoms/shadow/utils.d.ts +0 -9
  64. package/dist/components/chat-button.d.cts +0 -18
  65. package/dist/components/chat-button.d.ts +0 -18
  66. package/dist/components/embedded-chat/chat-provider.d.cts +0 -19
  67. package/dist/components/embedded-chat/chat-provider.d.ts +0 -19
  68. package/dist/components/embedded-chat/use-captcha.d.cts +0 -13
  69. package/dist/components/embedded-chat/use-captcha.d.ts +0 -13
  70. package/dist/components/embedded-chat/use-chat-action.d.cts +0 -9
  71. package/dist/components/embedded-chat/use-chat-action.d.ts +0 -9
  72. package/dist/components/embedded-chat/use-inkeep-chat.d.cts +0 -25
  73. package/dist/components/embedded-chat/use-inkeep-chat.d.ts +0 -25
  74. package/dist/components/embedded-chat.d.cts +0 -416
  75. package/dist/components/embedded-chat.d.ts +0 -416
  76. package/dist/components/embedded-search/search-provider.d.cts +0 -21
  77. package/dist/components/embedded-search/search-provider.d.ts +0 -21
  78. package/dist/components/embedded-search/transform-results.d.cts +0 -3
  79. package/dist/components/embedded-search/transform-results.d.ts +0 -3
  80. package/dist/components/embedded-search/use-inkeep-search.d.cts +0 -21
  81. package/dist/components/embedded-search/use-inkeep-search.d.ts +0 -21
  82. package/dist/components/embedded-search.d.cts +0 -216
  83. package/dist/components/embedded-search.d.ts +0 -216
  84. package/dist/components/factory.d.cts +0 -19
  85. package/dist/components/factory.d.ts +0 -19
  86. package/dist/components/index.d.cts +0 -11
  87. package/dist/components/index.d.ts +0 -11
  88. package/dist/components/intelligent-form/actions/context-model-response.d.cts +0 -10
  89. package/dist/components/intelligent-form/actions/context-model-response.d.ts +0 -10
  90. package/dist/components/intelligent-form/actions/escalation-schema.d.cts +0 -2
  91. package/dist/components/intelligent-form/actions/escalation-schema.d.ts +0 -2
  92. package/dist/components/intelligent-form/actions/qa-model-messages.d.cts +0 -2
  93. package/dist/components/intelligent-form/actions/qa-model-messages.d.ts +0 -2
  94. package/dist/components/intelligent-form/actions/qa-model-response.d.cts +0 -14
  95. package/dist/components/intelligent-form/actions/qa-model-response.d.ts +0 -14
  96. package/dist/components/intelligent-form/intelligent-form-provider.d.cts +0 -29
  97. package/dist/components/intelligent-form/intelligent-form-provider.d.ts +0 -29
  98. package/dist/components/intelligent-form/use-inkeep-intelligent-form.d.cts +0 -30
  99. package/dist/components/intelligent-form/use-inkeep-intelligent-form.d.ts +0 -30
  100. package/dist/components/intelligent-form.d.cts +0 -136
  101. package/dist/components/intelligent-form.d.ts +0 -136
  102. package/dist/components/modal/modal-provider.d.cts +0 -13
  103. package/dist/components/modal/modal-provider.d.ts +0 -13
  104. package/dist/components/modal/use-inkeep-modal.d.cts +0 -8
  105. package/dist/components/modal/use-inkeep-modal.d.ts +0 -8
  106. package/dist/components/modal.d.cts +0 -18
  107. package/dist/components/modal.d.ts +0 -18
  108. package/dist/components/searchbar.d.cts +0 -23
  109. package/dist/components/searchbar.d.ts +0 -23
  110. package/dist/components/tagline-logo-icon.d.cts +0 -1
  111. package/dist/components/tagline-logo-icon.d.ts +0 -1
  112. package/dist/hooks/index.d.cts +0 -12
  113. package/dist/hooks/index.d.ts +0 -12
  114. package/dist/hooks/use-boolean.d.cts +0 -10
  115. package/dist/hooks/use-boolean.d.ts +0 -10
  116. package/dist/hooks/use-browser-storage.d.cts +0 -17
  117. package/dist/hooks/use-browser-storage.d.ts +0 -17
  118. package/dist/hooks/use-component-classnames.d.cts +0 -6
  119. package/dist/hooks/use-component-classnames.d.ts +0 -6
  120. package/dist/hooks/use-container-size.d.cts +0 -5
  121. package/dist/hooks/use-container-size.d.ts +0 -5
  122. package/dist/hooks/use-copy-to-clipboard.d.cts +0 -3
  123. package/dist/hooks/use-copy-to-clipboard.d.ts +0 -3
  124. package/dist/hooks/use-instant-update.d.cts +0 -17
  125. package/dist/hooks/use-instant-update.d.ts +0 -17
  126. package/dist/hooks/use-is-mounted.d.cts +0 -1
  127. package/dist/hooks/use-is-mounted.d.ts +0 -1
  128. package/dist/hooks/use-media-query.d.cts +0 -1
  129. package/dist/hooks/use-media-query.d.ts +0 -1
  130. package/dist/hooks/use-resize-observer.d.cts +0 -12
  131. package/dist/hooks/use-resize-observer.d.ts +0 -12
  132. package/dist/hooks/use-scroll-to-bottom.d.cts +0 -13
  133. package/dist/hooks/use-scroll-to-bottom.d.ts +0 -13
  134. package/dist/hooks/use-scrolling-fades.d.cts +0 -2
  135. package/dist/hooks/use-scrolling-fades.d.ts +0 -2
  136. package/dist/hooks/use-settle-action.d.cts +0 -3
  137. package/dist/hooks/use-settle-action.d.ts +0 -3
  138. package/dist/providers/attachment-item-provider.d.cts +0 -9
  139. package/dist/providers/attachment-item-provider.d.ts +0 -9
  140. package/dist/providers/attachments-bar-provider.d.cts +0 -30
  141. package/dist/providers/attachments-bar-provider.d.ts +0 -30
  142. package/dist/providers/base-events-provider.d.cts +0 -8
  143. package/dist/providers/base-events-provider.d.ts +0 -8
  144. package/dist/providers/chat-events-provider.d.cts +0 -20
  145. package/dist/providers/chat-events-provider.d.ts +0 -20
  146. package/dist/providers/chat-form-provider.d.cts +0 -23
  147. package/dist/providers/chat-form-provider.d.ts +0 -23
  148. package/dist/providers/config-provider.d.cts +0 -24
  149. package/dist/providers/config-provider.d.ts +0 -24
  150. package/dist/providers/conversation-provider.d.cts +0 -12
  151. package/dist/providers/conversation-provider.d.ts +0 -12
  152. package/dist/providers/feedback-item-provider.d.cts +0 -10
  153. package/dist/providers/feedback-item-provider.d.ts +0 -10
  154. package/dist/providers/feedback-provider.d.cts +0 -19
  155. package/dist/providers/feedback-provider.d.ts +0 -19
  156. package/dist/providers/form-field-provider.d.cts +0 -15
  157. package/dist/providers/form-field-provider.d.ts +0 -15
  158. package/dist/providers/help-menu-provider.d.cts +0 -11
  159. package/dist/providers/help-menu-provider.d.ts +0 -11
  160. package/dist/providers/index.d.cts +0 -19
  161. package/dist/providers/index.d.ts +0 -19
  162. package/dist/providers/intelligent-form-field-provider.d.cts +0 -15
  163. package/dist/providers/intelligent-form-field-provider.d.ts +0 -15
  164. package/dist/providers/markdown-provider.d.cts +0 -9
  165. package/dist/providers/markdown-provider.d.ts +0 -9
  166. package/dist/providers/message-attachments-provider.d.cts +0 -13
  167. package/dist/providers/message-attachments-provider.d.ts +0 -13
  168. package/dist/providers/message-provider.d.cts +0 -10
  169. package/dist/providers/message-provider.d.ts +0 -10
  170. package/dist/providers/root-provider.d.cts +0 -8
  171. package/dist/providers/root-provider.d.ts +0 -8
  172. package/dist/providers/search-events-provider.d.cts +0 -11
  173. package/dist/providers/search-events-provider.d.ts +0 -11
  174. package/dist/providers/source-item-provider.d.cts +0 -12
  175. package/dist/providers/source-item-provider.d.ts +0 -12
  176. package/dist/providers/theme-provider.d.cts +0 -3
  177. package/dist/providers/theme-provider.d.ts +0 -3
  178. package/dist/providers/user-provider.d.cts +0 -13
  179. package/dist/providers/user-provider.d.ts +0 -13
  180. package/dist/providers/widget-provider.d.cts +0 -9
  181. package/dist/providers/widget-provider.d.ts +0 -9
  182. package/dist/utils/component-ids.d.cts +0 -632
  183. package/dist/utils/component-ids.d.ts +0 -632
  184. package/dist/utils/compose-event-handlers.d.cts +0 -3
  185. package/dist/utils/compose-event-handlers.d.ts +0 -3
  186. package/dist/utils/compose-refs.d.cts +0 -5
  187. package/dist/utils/compose-refs.d.ts +0 -5
  188. package/dist/utils/default-settings.d.cts +0 -249
  189. package/dist/utils/default-settings.d.ts +0 -249
  190. package/dist/utils/form.d.cts +0 -3
  191. package/dist/utils/form.d.ts +0 -3
  192. package/dist/utils/generate-uid.d.cts +0 -2
  193. package/dist/utils/generate-uid.d.ts +0 -2
  194. package/dist/utils/get-message-metadata.d.cts +0 -8
  195. package/dist/utils/get-message-metadata.d.ts +0 -8
  196. package/dist/utils/graphql-client.d.cts +0 -8
  197. package/dist/utils/graphql-client.d.ts +0 -8
  198. package/dist/utils/highlight-emphasis.d.cts +0 -4
  199. package/dist/utils/highlight-emphasis.d.ts +0 -4
  200. package/dist/utils/merge-props.d.cts +0 -7
  201. package/dist/utils/merge-props.d.ts +0 -7
  202. package/dist/utils/misc.d.cts +0 -13
  203. package/dist/utils/misc.d.ts +0 -13
  204. package/dist/utils/reset-query-params.d.cts +0 -1
  205. package/dist/utils/reset-query-params.d.ts +0 -1
  206. package/dist/utils/tools/links-schema.d.cts +0 -64
  207. package/dist/utils/tools/links-schema.d.ts +0 -64
  208. package/dist/utils/transform-source/breadcrumbs.d.cts +0 -2
  209. package/dist/utils/transform-source/breadcrumbs.d.ts +0 -2
  210. package/dist/utils/transform-source/common-words/long.d.cts +0 -1
  211. package/dist/utils/transform-source/common-words/long.d.ts +0 -1
  212. package/dist/utils/transform-source/common-words/lowercase.d.cts +0 -1
  213. package/dist/utils/transform-source/common-words/lowercase.d.ts +0 -1
  214. package/dist/utils/transform-source/common-words/short.d.cts +0 -1
  215. package/dist/utils/transform-source/common-words/short.d.ts +0 -1
  216. package/dist/utils/transform-source/description.d.cts +0 -2
  217. package/dist/utils/transform-source/description.d.ts +0 -2
  218. package/dist/utils/transform-source/icon.d.cts +0 -2
  219. package/dist/utils/transform-source/icon.d.ts +0 -2
  220. package/dist/utils/transform-source/tabs.d.cts +0 -2
  221. package/dist/utils/transform-source/tabs.d.ts +0 -2
  222. package/dist/utils/transform-source/title.d.cts +0 -2
  223. package/dist/utils/transform-source/title.d.ts +0 -2
  224. package/dist/utils/transform-source/utils/description-without-title.d.cts +0 -11
  225. package/dist/utils/transform-source/utils/description-without-title.d.ts +0 -11
  226. package/dist/utils/transform-source/utils/index.d.cts +0 -6
  227. package/dist/utils/transform-source/utils/index.d.ts +0 -6
  228. package/dist/utils/transform-source/utils/misc.d.cts +0 -2
  229. package/dist/utils/transform-source/utils/misc.d.ts +0 -2
  230. package/dist/utils/transform-source/utils/standardize-common-words.d.cts +0 -1
  231. package/dist/utils/transform-source/utils/standardize-common-words.d.ts +0 -1
  232. package/dist/utils/transform-source/utils/standardize-organization-display-name.d.cts +0 -8
  233. package/dist/utils/transform-source/utils/standardize-organization-display-name.d.ts +0 -8
  234. package/dist/utils/transform-source/utils/standardize-suffixes.d.cts +0 -5
  235. package/dist/utils/transform-source/utils/standardize-suffixes.d.ts +0 -5
  236. package/dist/utils/transform-source/utils/strip-branding-keywords.d.cts +0 -17
  237. package/dist/utils/transform-source/utils/strip-branding-keywords.d.ts +0 -17
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),W=require("../../providers/config-provider.cjs"),G=require("../../hooks/use-media-query.cjs"),J=require("./search-query.graphql.cjs"),V=require("./transform-results.cjs"),X=require("../../providers/search-events-provider.cjs"),Y=require("../../hooks/use-instant-update.cjs"),Z=require("../../utils/graphql-client.cjs"),ee=()=>{const{baseSettings:_,searchSettings:j}=W.useInkeepConfig(),{apiKey:p,aiApiBaseUrl:L,userAuthToken:l}=_,{maxResults:S,placeholder:R,defaultQuery:N,debounceTimeMs:Q,onQueryChange:O,searchFunctionsRef:x}=j,{logEvent:q}=X.useSearchEvents(),[c,C]=t.useState(N),T=t.useRef(null),[k,v]=t.useState(!1),[B,i]=t.useState(null),[F,a]=t.useState("NONE"),H=t.useCallback(e=>{a(e)},[]),[h,d]=t.useState([]),s=V.useTransformResults(h,c),[f,E]=t.useState("All"),{disableTransition:M,disabled:$}=Y.useInstantUpdate(),z=t.useCallback(e=>{M(),E(e);const r=s[e][0].id;a(r)},[s,M]);t.useEffect(()=>{let e=f in s?f:Object.keys(s)[0];if(!s[e]?.length){const n=Object.keys(s).find(u=>s[u]?.length);n?e=n:e="All"}if(!e)return;E(e);const r=s[e]?.[0];r&&a(r.id)},[s]);const y=G.useMediaQuery("(max-width: 768px)"),o=t.useRef({}),b=t.useRef(null),m=t.useRef(null);t.useImperativeHandle(x,()=>({updateQuery(e){C(e)},focusInput:()=>{T.current?.focus()}}));const w=`${L}/graphql`,A=t.useMemo(()=>({Authorization:`Bearer ${p}`,"Content-Type":"application/json",...l?{"User-Token":l}:{}}),[p,l]),I=t.useCallback(async e=>{b.current&&b.current.abort();const r=new AbortController;b.current=r;try{v(!0),i(null);const u=(await Z.graphqlRequest(w,J.default,{searchInput:e},A))?.search.searchHits;o.current[e.searchQuery]=u,d(u)}catch(n){if(n.name==="AbortError")return;i("Failed to fetch search results. Please try again.")}v(!1)},[w,A]),P=t.useCallback(e=>{const r=o.current[e.searchQuery];q({eventName:"search_query_response_received",properties:{searchQuery:e.searchQuery,totalResults:r?.length}})},[]),U=t.useCallback(e=>{if(m.current&&window.clearTimeout(m.current),!e.searchQuery){d([]),i(null);return}m.current=window.setTimeout(()=>{q({eventName:"search_query_submitted",properties:{searchQuery:e.searchQuery}}),o.current[e.searchQuery]?(d(o.current[e.searchQuery]),P(e)):I(e).then(()=>{P(e)})},Q)},[Q,I]),g=t.useMemo(()=>({searchQuery:c,filters:{limit:S}}),[c,S]);t.useEffect(()=>{O?.(g.searchQuery),U(g)},[U,g]);const D=t.useCallback(e=>C(e.target.value),[]),K=t.useMemo(()=>R||(y?"Search...":"Search for anything..."),[R,y]);return{results:s,resultsList:h,hasContent:h.length>0||k,loading:k,error:B,query:c,onInput:D,placeholder:K,tab:f,onTabChange:z,selectedItem:F,setSelectedItem:a,onSelectedItemChange:H,transitionsDisabled:$,inputRef:T,isMobile:y}};exports.useInkeepSearch=ee;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),J=require("../../providers/config-provider.cjs"),V=require("../../hooks/use-media-query.cjs"),X=require("./search-query.graphql.cjs"),Y=require("./transform-results.cjs"),Z=require("../../providers/search-events-provider.cjs"),ee=require("../../hooks/use-instant-update.cjs"),te=require("../../utils/graphql-client.cjs"),se=()=>{const{baseSettings:L,searchSettings:N}=J.useInkeepConfig(),{apiKey:S,aiApiBaseUrl:O,userAuthToken:l}=L,{maxResults:R,placeholder:Q,defaultQuery:x,debounceTimeMs:q,onQueryChange:B,searchFunctionsRef:F,tabs:i}=N,{logEvent:C}=Z.useSearchEvents(),[c,T]=t.useState(x),k=t.useRef(null),[v,E]=t.useState(!1),[H,h]=t.useState(null),[$,a]=t.useState("NONE"),z=t.useCallback(e=>{a(e)},[]),[d,f]=t.useState([]),s=Y.useTransformResults(d,c),M=typeof i?.[0]=="string"?i[0]:i[0][0],[y,w]=t.useState(M),{disableTransition:I,disabled:D}=ee.useInstantUpdate(),K=t.useCallback(e=>{I(),w(e);const r=s[e][0].id;a(r)},[s,I]);t.useEffect(()=>{let e=y in s?y:Object.keys(s)[0];if(!s[e]?.length){const n=Object.keys(s).find(u=>s[u]?.length);n?e=n:e=M}if(!e)return;w(e);const r=s[e]?.[0];r&&a(r.id)},[s]);const b=V.useMediaQuery("(max-width: 768px)"),o=t.useRef({}),m=t.useRef(null),g=t.useRef(null);t.useImperativeHandle(F,()=>({updateQuery(e){T(e)},focusInput:()=>{k.current?.focus()}}));const A=`${O}/graphql`,P=t.useMemo(()=>({Authorization:`Bearer ${S}`,"Content-Type":"application/json",...l?{"User-Token":l}:{}}),[S,l]),U=t.useCallback(async e=>{m.current&&m.current.abort();const r=new AbortController;m.current=r;try{E(!0),h(null);const u=(await te.graphqlRequest(A,X.default,{searchInput:e},P))?.search.searchHits;o.current[e.searchQuery]=u,f(u)}catch(n){if(n.name==="AbortError")return;h("Failed to fetch search results. Please try again.")}E(!1)},[A,P]),_=t.useCallback(e=>{const r=o.current[e.searchQuery];C({eventName:"search_query_response_received",properties:{searchQuery:e.searchQuery,totalResults:r?.length}})},[]),j=t.useCallback(e=>{if(g.current&&window.clearTimeout(g.current),!e.searchQuery){f([]),h(null);return}g.current=window.setTimeout(()=>{C({eventName:"search_query_submitted",properties:{searchQuery:e.searchQuery}}),o.current[e.searchQuery]?(f(o.current[e.searchQuery]),_(e)):U(e).then(()=>{_(e)})},q)},[q,U]),p=t.useMemo(()=>({searchQuery:c,filters:{limit:R}}),[c,R]);t.useEffect(()=>{B?.(p.searchQuery),j(p)},[j,p]);const W=t.useCallback(e=>T(e.target.value),[]),G=t.useMemo(()=>Q||(b?"Search...":"Search for anything..."),[Q,b]);return{results:s,resultsList:d,hasContent:d.length>0||v,loading:v,error:H,query:c,onInput:W,placeholder:G,tab:y,onTabChange:K,selectedItem:$,setSelectedItem:a,onSelectedItemChange:z,transitionsDisabled:D,inputRef:k,isMobile:b}};exports.useInkeepSearch=se;
@@ -1,139 +1,140 @@
1
1
  "use client";
2
- import { useState as s, useRef as l, useCallback as n, useEffect as j, useImperativeHandle as X, useMemo as R } from "react";
3
- import { useInkeepConfig as Y } from "../../providers/config-provider.js";
4
- import { useMediaQuery as Z } from "../../hooks/use-media-query.js";
5
- import ee from "./search-query.graphql.js";
6
- import { useTransformResults as te } from "./transform-results.js";
7
- import { useSearchEvents as re } from "../../providers/search-events-provider.js";
8
- import { useInstantUpdate as se } from "../../hooks/use-instant-update.js";
9
- import { graphqlRequest as ne } from "../../utils/graphql-client.js";
10
- const me = () => {
11
- const { baseSettings: O, searchSettings: B } = Y(), { apiKey: T, aiApiBaseUrl: F, userAuthToken: h } = O, {
12
- maxResults: S,
13
- placeholder: C,
14
- defaultQuery: H,
15
- debounceTimeMs: v,
16
- onQueryChange: P,
17
- searchFunctionsRef: $
18
- } = B, { logEvent: k } = re(), [c, w] = s(H), A = l(null), [q, E] = s(!1), [z, f] = s(null), [D, a] = s("NONE"), K = n((e) => {
2
+ import { useState as s, useRef as l, useCallback as n, useEffect as B, useImperativeHandle as Z, useMemo as T } from "react";
3
+ import { useInkeepConfig as ee } from "../../providers/config-provider.js";
4
+ import { useMediaQuery as te } from "../../hooks/use-media-query.js";
5
+ import re from "./search-query.graphql.js";
6
+ import { useTransformResults as se } from "./transform-results.js";
7
+ import { useSearchEvents as ne } from "../../providers/search-events-provider.js";
8
+ import { useInstantUpdate as oe } from "../../hooks/use-instant-update.js";
9
+ import { graphqlRequest as ce } from "../../utils/graphql-client.js";
10
+ const pe = () => {
11
+ const { baseSettings: F, searchSettings: H } = ee(), { apiKey: S, aiApiBaseUrl: P, userAuthToken: h } = F, {
12
+ maxResults: C,
13
+ placeholder: v,
14
+ defaultQuery: $,
15
+ debounceTimeMs: k,
16
+ onQueryChange: z,
17
+ searchFunctionsRef: D,
18
+ tabs: f
19
+ } = H, { logEvent: w } = ne(), [c, q] = s($), E = l(null), [A, I] = s(!1), [K, m] = s(null), [W, a] = s("NONE"), G = n((e) => {
19
20
  a(e);
20
- }, []), [m, d] = s([]), t = te(m, c), [p, I] = s("All"), { disableTransition: _, disabled: W } = se(), G = n(
21
+ }, []), [d, p] = s([]), t = se(d, c), _ = typeof f?.[0] == "string" ? f[0] : f[0][0], [y, x] = s(_), { disableTransition: L, disabled: J } = oe(), V = n(
21
22
  (e) => {
22
- _(), I(e);
23
+ L(), x(e);
23
24
  const r = t[e][0].id;
24
25
  a(r);
25
26
  },
26
- [t, _]
27
+ [t, L]
27
28
  );
28
- j(() => {
29
- let e = p in t ? p : Object.keys(t)[0];
29
+ B(() => {
30
+ let e = y in t ? y : Object.keys(t)[0];
30
31
  if (!t[e]?.length) {
31
32
  const o = Object.keys(t).find((i) => t[i]?.length);
32
- o ? e = o : e = "All";
33
+ o ? e = o : e = _;
33
34
  }
34
35
  if (!e) return;
35
- I(e);
36
+ x(e);
36
37
  const r = t[e]?.[0];
37
38
  r && a(r.id);
38
39
  }, [t]);
39
- const y = Z("(max-width: 768px)"), u = l({}), b = l(null), g = l(null);
40
- X($, () => ({
40
+ const b = te("(max-width: 768px)"), u = l({}), g = l(null), Q = l(null);
41
+ Z(D, () => ({
41
42
  updateQuery(e) {
42
- w(e);
43
+ q(e);
43
44
  },
44
45
  focusInput: () => {
45
- A.current?.focus();
46
+ E.current?.focus();
46
47
  }
47
48
  }));
48
- const x = `${F}/graphql`, L = R(
49
+ const M = `${P}/graphql`, N = T(
49
50
  () => ({
50
- Authorization: `Bearer ${T}`,
51
+ Authorization: `Bearer ${S}`,
51
52
  "Content-Type": "application/json",
52
53
  ...h ? { "User-Token": h } : {}
53
54
  }),
54
- [T, h]
55
- ), M = n(
55
+ [S, h]
56
+ ), U = n(
56
57
  async (e) => {
57
- b.current && b.current.abort();
58
+ g.current && g.current.abort();
58
59
  const r = new AbortController();
59
- b.current = r;
60
+ g.current = r;
60
61
  try {
61
- E(!0), f(null);
62
- const i = (await ne(x, ee, { searchInput: e }, L))?.search.searchHits;
63
- u.current[e.searchQuery] = i, d(i);
62
+ I(!0), m(null);
63
+ const i = (await ce(M, re, { searchInput: e }, N))?.search.searchHits;
64
+ u.current[e.searchQuery] = i, p(i);
64
65
  } catch (o) {
65
66
  if (o.name === "AbortError")
66
67
  return;
67
- f("Failed to fetch search results. Please try again.");
68
+ m("Failed to fetch search results. Please try again.");
68
69
  }
69
- E(!1);
70
+ I(!1);
70
71
  },
71
- [x, L]
72
- ), N = n((e) => {
72
+ [M, N]
73
+ ), j = n((e) => {
73
74
  const r = u.current[e.searchQuery];
74
- k({
75
+ w({
75
76
  eventName: "search_query_response_received",
76
77
  properties: {
77
78
  searchQuery: e.searchQuery,
78
79
  totalResults: r?.length
79
80
  }
80
81
  });
81
- }, []), U = n(
82
+ }, []), O = n(
82
83
  (e) => {
83
- if (g.current && window.clearTimeout(g.current), !e.searchQuery) {
84
- d([]), f(null);
84
+ if (Q.current && window.clearTimeout(Q.current), !e.searchQuery) {
85
+ p([]), m(null);
85
86
  return;
86
87
  }
87
- g.current = window.setTimeout(() => {
88
- k({
88
+ Q.current = window.setTimeout(() => {
89
+ w({
89
90
  eventName: "search_query_submitted",
90
91
  properties: {
91
92
  searchQuery: e.searchQuery
92
93
  }
93
- }), u.current[e.searchQuery] ? (d(u.current[e.searchQuery]), N(e)) : M(e).then(() => {
94
- N(e);
94
+ }), u.current[e.searchQuery] ? (p(u.current[e.searchQuery]), j(e)) : U(e).then(() => {
95
+ j(e);
95
96
  });
96
- }, v);
97
+ }, k);
97
98
  },
98
- [v, M]
99
- ), Q = R(
99
+ [k, U]
100
+ ), R = T(
100
101
  () => ({
101
102
  searchQuery: c,
102
103
  filters: {
103
- limit: S
104
+ limit: C
104
105
  }
105
106
  }),
106
- [c, S]
107
+ [c, C]
107
108
  );
108
- j(() => {
109
- P?.(Q.searchQuery), U(Q);
110
- }, [U, Q]);
111
- const J = n(
112
- (e) => w(e.target.value),
109
+ B(() => {
110
+ z?.(R.searchQuery), O(R);
111
+ }, [O, R]);
112
+ const X = n(
113
+ (e) => q(e.target.value),
113
114
  []
114
- ), V = R(
115
- () => C || (y ? "Search..." : "Search for anything..."),
116
- [C, y]
115
+ ), Y = T(
116
+ () => v || (b ? "Search..." : "Search for anything..."),
117
+ [v, b]
117
118
  );
118
119
  return {
119
120
  results: t,
120
- resultsList: m,
121
- hasContent: m.length > 0 || q,
122
- loading: q,
123
- error: z,
121
+ resultsList: d,
122
+ hasContent: d.length > 0 || A,
123
+ loading: A,
124
+ error: K,
124
125
  query: c,
125
- onInput: J,
126
- placeholder: V,
127
- tab: p,
128
- onTabChange: G,
129
- selectedItem: D,
126
+ onInput: X,
127
+ placeholder: Y,
128
+ tab: y,
129
+ onTabChange: V,
130
+ selectedItem: W,
130
131
  setSelectedItem: a,
131
- onSelectedItemChange: K,
132
- transitionsDisabled: W,
133
- inputRef: A,
134
- isMobile: y
132
+ onSelectedItemChange: G,
133
+ transitionsDisabled: J,
134
+ inputRef: E,
135
+ isMobile: b
135
136
  };
136
137
  };
137
138
  export {
138
- me as useInkeepSearch
139
+ pe as useInkeepSearch
139
140
  };