@akropolys/kiku 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{a as K,c as h,f as H,i as $,n as z}from"./chunk-RWGHGIF7.mjs";import{useState as G,useEffect as Q,useRef as W}from"react";import{useSearch as ae,useAkropolysContext as re,useCardFields as ie}from"@akropolys/sdk";import{Fragment as X,jsx as o,jsxs as r}from"react/jsx-runtime";var J=()=>r("svg",{width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("circle",{cx:"8.5",cy:"8.5",r:"5.5"}),o("line",{x1:"13",y1:"13",x2:"18",y2:"18"})]});function le({placeholder:g="Search products\u2026",limit:R=10,debounceMs:x=150,onSelect:P,className:A,inputClassName:_,dropdownClassName:F,renderResult:E,theme:s,classNames:m={}}){let[n,f]=G(""),[L,u]=G(!1),{results:l,loading:w,search:I,clear:i}=ae({debounceMs:x}),y=re(),k=ie(),b=W(null),v=W(!1);Q(()=>{if(v.current){v.current=!1;return}if(!n.trim()){i(),u(!1);return}u(!0),I(n,R)},[n]),Q(()=>{let e=a=>{b.current&&!b.current.contains(a.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let c=e=>{n.trim()&&y.api.searchVector(n,1,void 0,!0).catch(()=>{}),v.current=!0,u(!1),f(e.entity.title??e.entity.name??""),P?.(e)},D=()=>{n.trim()&&(y.api.searchVector(n,1,void 0,!0).catch(()=>{}),l.length>0&&c(l[0]))},C=L&&n.trim().length>0,S={...s?.primaryColor&&{"--hsk-primary":s.primaryColor},...s?.backgroundColor&&{"--hsk-bg":s.backgroundColor},...s?.textColor&&{"--hsk-text":s.textColor},...s?.fontFamily&&{"--hsk-font":s.fontFamily},...s?.borderRadius&&{"--hsk-border-radius":s.borderRadius}};return r("div",{className:h("hsk-sb-wrap",m.root,A),ref:b,style:S,children:[o("span",{className:"hsk-sb-icon",children:o(J,{})}),o("input",{className:h("hsk-sb-input",m.input,_),type:"text",value:n,placeholder:g,onChange:e=>f(e.target.value),onFocus:()=>l.length>0&&n.trim()&&u(!0),onKeyDown:e=>{e.key==="Enter"&&D()},autoComplete:"off",spellCheck:!1}),C&&r("div",{className:h("hsk-sb-drop",m.dropdown,F),style:{position:"absolute"},children:[w&&o("div",{className:"hsk-sb-loading-bar"}),w&&l.length===0?r(X,{children:[r("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),r("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1"}),o("div",{className:"hsk-sb-skeleton-text2"})]})]}),r("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),r("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1",style:{width:"45%"}}),o("div",{className:"hsk-sb-skeleton-text2",style:{width:"25%"}})]})]})]}):r(X,{children:[l.length===0&&!w&&r("div",{className:"hsk-sb-empty",children:["No results for \u201C",n,"\u201D"]}),l.map((e,a)=>{if(E)return o("div",{onClick:()=>c(e),className:"hsk-sb-fade",style:{animationDelay:`${a*18}ms`},children:E(e)},e.id);let N=e.entity.image??e.entity.thumbnail??e.entity.images?.[0];return r("div",{className:h("hsk-sb-row hsk-sb-fade",m.row),style:{animationDelay:`${a*18}ms`},onClick:()=>c(e),children:[o("span",{className:"hsk-sb-row-thumb",children:N?o("img",{src:N,alt:"",loading:"lazy",onError:M=>{M.currentTarget.style.display="none"}}):o(J,{})}),r("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-row-title",children:e.entity.title??e.entity.name}),K({fields:e.entity.fields??e.entity},k)[0]&&o("div",{className:"hsk-sb-row-sub",children:K({fields:e.entity.fields??e.entity},k)[0].value})]})]},e.id)})]})]})]})}import{useState as T,useEffect as Y,useCallback as Z,useRef as j}from"react";import{createPortal as ce}from"react-dom";import{useAkropolysContext as de}from"@akropolys/sdk";import{Fragment as ee,jsx as U,jsxs as q}from"react/jsx-runtime";var O=null;function ue(){return O??(O=import("./lazy-
|
|
2
|
+
import{a as K,c as h,f as H,i as $,n as z}from"./chunk-RWGHGIF7.mjs";import{useState as G,useEffect as Q,useRef as W}from"react";import{useSearch as ae,useAkropolysContext as re,useCardFields as ie}from"@akropolys/sdk";import{Fragment as X,jsx as o,jsxs as r}from"react/jsx-runtime";var J=()=>r("svg",{width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("circle",{cx:"8.5",cy:"8.5",r:"5.5"}),o("line",{x1:"13",y1:"13",x2:"18",y2:"18"})]});function le({placeholder:g="Search products\u2026",limit:R=10,debounceMs:x=150,onSelect:P,className:A,inputClassName:_,dropdownClassName:F,renderResult:E,theme:s,classNames:m={}}){let[n,f]=G(""),[L,u]=G(!1),{results:l,loading:w,search:I,clear:i}=ae({debounceMs:x}),y=re(),k=ie(),b=W(null),v=W(!1);Q(()=>{if(v.current){v.current=!1;return}if(!n.trim()){i(),u(!1);return}u(!0),I(n,R)},[n]),Q(()=>{let e=a=>{b.current&&!b.current.contains(a.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let c=e=>{n.trim()&&y.api.searchVector(n,1,void 0,!0).catch(()=>{}),v.current=!0,u(!1),f(e.entity.title??e.entity.name??""),P?.(e)},D=()=>{n.trim()&&(y.api.searchVector(n,1,void 0,!0).catch(()=>{}),l.length>0&&c(l[0]))},C=L&&n.trim().length>0,S={...s?.primaryColor&&{"--hsk-primary":s.primaryColor},...s?.backgroundColor&&{"--hsk-bg":s.backgroundColor},...s?.textColor&&{"--hsk-text":s.textColor},...s?.fontFamily&&{"--hsk-font":s.fontFamily},...s?.borderRadius&&{"--hsk-border-radius":s.borderRadius}};return r("div",{className:h("hsk-sb-wrap",m.root,A),ref:b,style:S,children:[o("span",{className:"hsk-sb-icon",children:o(J,{})}),o("input",{className:h("hsk-sb-input",m.input,_),type:"text",value:n,placeholder:g,onChange:e=>f(e.target.value),onFocus:()=>l.length>0&&n.trim()&&u(!0),onKeyDown:e=>{e.key==="Enter"&&D()},autoComplete:"off",spellCheck:!1}),C&&r("div",{className:h("hsk-sb-drop",m.dropdown,F),style:{position:"absolute"},children:[w&&o("div",{className:"hsk-sb-loading-bar"}),w&&l.length===0?r(X,{children:[r("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),r("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1"}),o("div",{className:"hsk-sb-skeleton-text2"})]})]}),r("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),r("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1",style:{width:"45%"}}),o("div",{className:"hsk-sb-skeleton-text2",style:{width:"25%"}})]})]})]}):r(X,{children:[l.length===0&&!w&&r("div",{className:"hsk-sb-empty",children:["No results for \u201C",n,"\u201D"]}),l.map((e,a)=>{if(E)return o("div",{onClick:()=>c(e),className:"hsk-sb-fade",style:{animationDelay:`${a*18}ms`},children:E(e)},e.id);let N=e.entity.image??e.entity.thumbnail??e.entity.images?.[0];return r("div",{className:h("hsk-sb-row hsk-sb-fade",m.row),style:{animationDelay:`${a*18}ms`},onClick:()=>c(e),children:[o("span",{className:"hsk-sb-row-thumb",children:N?o("img",{src:N,alt:"",loading:"lazy",onError:M=>{M.currentTarget.style.display="none"}}):o(J,{})}),r("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-row-title",children:e.entity.title??e.entity.name}),K({fields:e.entity.fields??e.entity},k)[0]&&o("div",{className:"hsk-sb-row-sub",children:K({fields:e.entity.fields??e.entity},k)[0].value})]})]},e.id)})]})]})]})}import{useState as T,useEffect as Y,useCallback as Z,useRef as j}from"react";import{createPortal as ce}from"react-dom";import{useAkropolysContext as de}from"@akropolys/sdk";import{Fragment as ee,jsx as U,jsxs as q}from"react/jsx-runtime";var O=null;function ue(){return O??(O=import("./lazy-HMHFTX2M.mjs").catch(g=>{throw O=null,g})),O}function pe({label:g="Ask AI",children:R,icon:x,title:P,logo:A,placeholder:_,backdropColor:F,backdropBlur:E,className:s,onSelectSource:m,chips:n,theme:f,classNames:L={},enableVoice:u=!1,voiceLang:l,ttsVoice:w,enableVision:I=!1}){let i=de(),[y,k]=T(!1),[b,v]=T(null),[c,D]=T(null),C=j(!0),[S,e]=T(0);Y(()=>{if(y){e(0);return}let t=!0;return i?.api?.unreadFromTeam?.().then(d=>{t&&e(d)}).catch(()=>{}),()=>{t=!1}},[y,i]);let a=Z(()=>{ue().then(t=>{t.getShadowContainer(),C.current&&D(t),t.warmChrome(i,i?.getShopperLanguage?.()??"",t.DEFAULT_UI_STRINGS),i?.api?.widgetSettings?.().then(d=>{d?.detectedLanguage&&d.detectedLanguage.toLowerCase()!=="english"&&t.warmLanguage(i,d.detectedLanguage,t.DEFAULT_UI_STRINGS)}).catch(()=>{})}).catch(()=>{})},[i]),N=j(null),M=Z(()=>{let t=N.current?.getBoundingClientRect();v(t?{x:t.left+t.width/2,y:t.top+t.height/2}:null),k(!0),a();try{H()}catch{}},[a]);Y(()=>{C.current=!0;let t=window.requestIdleCallback,d=t?t(a,{timeout:2e3}):setTimeout(a,300);if(typeof window<"u"&&!window.__akropolys_nav_patched){window.__akropolys_nav_patched=!0;let p=window.location.pathname,ne=window.history.pushState,se=window.history.replaceState;window.history.pushState=function(...V){ne.apply(this,V),window.location.pathname!==p&&(p=window.location.pathname,window.dispatchEvent(new CustomEvent("akropolys:navigation")))},window.history.replaceState=function(...V){se.apply(this,V),window.location.pathname!==p&&(p=window.location.pathname,window.dispatchEvent(new CustomEvent("akropolys:navigation")))}}let B=()=>{k(!1)};return window.addEventListener("popstate",B),window.addEventListener("akropolys:navigation",B),()=>{C.current=!1;let p=window.cancelIdleCallback;t&&p?p(d):clearTimeout(d),window.removeEventListener("popstate",B),window.removeEventListener("akropolys:navigation",B)}},[a]);let{themeAttr:te,vars:oe}=$(f);return z(f),q(ee,{children:[q("button",{ref:N,className:h("hsk-cb-btn",L.button,s),onClick:M,onPointerEnter:a,onPointerDown:a,style:oe,"data-hsk-theme":te,"aria-label":"Open AI chat",children:[R!==void 0?R:q(ee,{children:[x?U("span",{className:"hsk-cb-btn-icon",style:{display:"flex",alignItems:"center"},children:x}):null,g]}),S>0&&U("span",{className:"hsk-cb-btn-badge","aria-label":`${S} new replies`,children:S})]}),y&&c&&ce(U(c.ChatModal,{title:P,logo:A,placeholder:_,backdropColor:F,backdropBlur:E,origin:b,onClose:()=>k(!1),onSelectSource:m,chips:n??c.DEFAULT_CHIPS,theme:f,classNames:L,enableVoice:u,voiceLang:l,enableVision:I,ttsVoice:w}),c.getShadowContainer()??document.body)]})}export{pe as KikuButton,le as SearchBar};
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|