PageSourceSearch

https://static2.ntv.ru/assets/js/search-hints-popular.type_style-CZHanoi6.js

js ntv.ru collected 2026-10-02 02:30:08 UTC 6,438 bytes, 1 lines download raw bytes

1import{W as useQuery,am as apiBase,an as API_NTV_HOST,ao as NTV_API_CONFIG,au as storeToRefs,av as use,al as keepPreviousData,a as unref,j as computed,y as ref,aw as watchDebounced,d as defineComponent,w as watch,o as openBlock,c as createElementBlock,F as Fragment,k as renderList,R as withKeys,h as createCommentVNode,b as withModifiers,v as createBlock,s as createTextVNode,t as toDisplayString,_ as _sfc_main$4,$ as renderSlot,f as withCtx,e as createVNode,q as hUi}from"../main-sKWLCJQt.js";const{isGuest:isGuest}=storeToRefs(use()),useSaveSearchHistory=async e=>{const t=e.trim();if(t)try{await apiBase.post("".concat(API_NTV_HOST,"/search/v1/history"),{query:t},NTV_API_CONFIG).then(({data:e})=>e)}catch(a){console.log(a)}};function useSearchData(e){const t=ref(!1),a=use(),s=ref(null),n=computed(()=>e.value.trim()),o=ref(n.value),c=computed(()=>0===n.value.length);watchDebounced(n,e=>{o.value=e},{debounce:250});const{data:r,refetch:l}=useQuery({enabled:computed(()=>!unref(isGuest)&&!0),queryKey:["search-history"],placeholderData:keepPreviousData,refetchOnWindowFocus:!1,queryFn:async()=>apiBase.get("".concat(API_NTV_HOST,"/search/v1/history"),{...NTV_API_CONFIG}).then(({data:e})=>e),retry:!1}),{data:i}=useQuery({enabled:!0,queryKey:["search-popular"],placeholderData:keepPreviousData,refetchOnWindowFocus:!1,queryFn:async()=>apiBase.get("".concat(API_NTV_HOST,"/search/v1/popular"),{...NTV_API_CONFIG}).then(({data:e})=>e),retry:!1}),u=computed(()=>{var e,t;return null!=(t=null==(e=r.value)?void 0:e.data.items)?t:[]}),h=computed(()=>{var e,t;return null!=(t=null==(e=i.value)?void 0:e.data.items.slice(0,7))?t:[]}),d=computed({get:()=>t.value&&n.value.length>0&&n.value!==s.value,set:e=>{e||p()}});function p(){t.value&&(s.value=n.value)}return{query:n,debouncedQuery:o,showLandingHints:c,isHintsOpen:d,inputFocused:t,historyItems:u,popularItems:h,refetchHistory:l,onInputFocus:function(){s.value=null,t.value=!0},onInputBlur:function(e){const a=null==e?void 0:e.relatedTarget;(null==a?void 0:a.closest(".dropdown-ui"))||(t.value=!1,s.value=null)},closeHints:p,selectHint:function(t){s.value=t.trim(),e.value=t},auth:a}}const _hoisted_1$2=["onClick","onKeydown"],_sfc_main$3=defineComponent({__name:"SearchHints",props:{modelValue:{},entity:{}},emits:["select","close","open"],setup(e,{emit:t}){const a=e,s=t,n=use(),o=computed(()=>a.modelValue.trim()),c=(e=>useQuery({enabled:computed(()=>e.value.replace(/\s+/g,"").length>0&&!unref(isGuest)&&!0),queryKey:["search-hints",e],placeholderData:keepPreviousData,queryFn:async()=>apiBase.get("".concat(API_NTV_HOST,"/search/v1/hints"),{params:{q:unref(e)},...NTV_API_CONFIG}).then(({data:e})=>e),retry:!1}))(o),r=(e=>useQuery({enabled:computed(()=>unref(isGuest)&&e.value.replace(/\s+/g,"").length>=4&&!0),queryKey:["search-suggest",e],placeholderData:keepPreviousData,queryFn:async()=>apiBase.get("".concat(API_NTV_HOST,"/search/v1/suggest"),{params:{q:unref(e)},...NTV_API_CONFIG}).then(({data:e})=>e),retry:!1}))(o),l=computed(()=>{var e,t;return null!=(t=null==(e=c.data.value)?void 0:e.data.suggest)?t:[]}),i=computed(()=>{var e,t;return null!=(t=null==(e=c.data.value)?void 0:e.data.history)?t:[]}),u=computed(()=>{var e,t;return null!=(t=null==(e=r.data.value)?void 0:e.data.items)?t:[]}),h=computed(()=>{if(n.isGuest)return u.value.map(e=>({search_text:e.search_text,icon:!1}));return[...i.value.map(e=>({search_text:e.search_text,icon:!0})),...l.value.map(e=>({search_text:e.search_text,icon:!1}))]}),d=computed(()=>n.isGuest?o.value.replace(/\s+/g,"").length>=4:o.value.replace(/\s+/g,"").length>=1),p=computed(()=>d.value&&h.value.length>0);function m(e){s("select",e)}function _(e){const t=e.relatedTarget;(null==t?void 0:t.closest(".dropdown-ui"))||s("close")}return watch(p,e=>{s("open",e)},{immediate:!0}),(e,t)=>{const a=_sfc_main$4;return unref(p)?(openBlock(),createElementBlock("ul",{key:0,class:"search-hints",role:"listbox",onFocusout:_,onKeydown:t[1]||(t[1]=withKeys(e=>s("close"),["esc"]))},[(openBlock(!0),createElementBlock(Fragment,null,renderList(unref(h),(e,s)=>(openBlock(),createElementBlock("li",{key:s,class:"search-hints__item",tabindex:"0",role:"option",onMousedown:t[0]||(t[0]=withModifiers(()=>{},["prevent"])),onClick:t=>m(e.search_text),onKeydown:withKeys(withModifiers(t=>m(e.search_text),["prevent"]),["enter"])},[e.icon?(openBlock(),createBlock(a,{key:0,width:"16",height:"16",name:"repeat"})):createCommentVNode("",!0),createTextVNode(" "+toDisplayString(e.search_text),1)],40,_hoisted_1$2))),128))],32)):createCommentVNode("",!0)}}}),_sfc_main$2=defineComponent({__name:"SearchHintTag",props:{text:{}},emits:["click"],setup(e,{emit:t}){const a=t;return(t,s)=>(openBlock(),createElementBlock("span",{class:"search-hint-tag",tabindex:"0",role:"button",onClick:s[0]||(s[0]=e=>a("click")),onKeydown:s[1]||(s[1]=withKeys(withModifiers(e=>a("click"),["prevent"]),["enter"]))}
1,[renderSlot(t.$slots,"icon"),createTextVNode(" "+toDisplayString(e.text),1)],32))}}),_hoisted_1$1={key:0,class:"search-hints__history"},_sfc_main$1=defineComponent({__name:"SearchHintsHistory",props:{items:{},show:{type:Boolean}},emits:["select"],setup(e,{emit:t}){const a=t;return(t,s)=>{const n=_sfc_main$4;return e.show&&e.items.length?(openBlock(),createElementBlock("div",_hoisted_1$1,[(openBlock(!0),createElementBlock(Fragment,null,renderList(e.items,(e,t)=>(openBlock(),createBlock(_sfc_main$2,{key:t,text:e.search_text,onClick:t=>a("select",e.search_text)},{icon:withCtx(()=>[createVNode(n,{width:"16",height:"16",name:"repeat",class:"search-hints__history-icon"})]),_:1},8,["text","onClick"]))),128))])):createCommentVNode("",!0)}}}),_hoisted_1={key:0,class:"search-hints-popular"},_sfc_main=defineComponent({__name:"SearchHintsPopular",props:{items:{},show:{type:Boolean}},emits:["select"],setup(e,{emit:t}){const a=t;return(t,s)=>{const n=hUi;return e.show&&e.items.length?(openBlock(),createElementBlock("div",_hoisted_1,[createVNode(n,{type:"subheading",size:"s",class:"search-hints-popular__title"},{default:withCtx(()=>[...s[0]||(s[0]=[createTextVNode("Сейчас ищут:",-1)])]),_:1}),(openBlock(!0),createElementBlock(Fragment,null,renderList(e.items,e=>(openBlock(),createBlock(_sfc_main$2,{key:e.search_text,text:e.search_text,onClick:t=>a("select",e.search_text)},null,8,["text","onClick"]))),128))])):createCommentVNode("",!0)}}});export{_sfc_main$3 as _,_sfc_main$1 as a,_sfc_main as b,useSaveSearchHistory as c,useSearchData as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.