@perevorot/shop 2.0.66 → 2.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("vue"),t=require("vuex"),r=require("@perevorot/shop/dist/api"),n=require("simplebar"),o=require("secure-ls");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=a(n),c=a(o);var i=e.defineComponent({name:"search",props:{q:{type:String,default:""},placeholder:{type:String,default:""},parameter:{type:String,default:"/q{separator}"}},setup:function(n){var o=new c.default({isCompression:!1}),a=n.q;if(a){var i=document.createElement("textarea");i.innerHTML=a,a=i.value}var s=e.ref(!1),u=e.ref(a),d=e.ref([]),p=e.ref([]),m=e.ref(0),v=e.ref(-1),h=e.ref(!1),f=e.ref(),y=e.ref(""),g=e.ref(),k=e.ref(o.get("search")),E=e.ref([]),w=t.useStore(),V=e.computed((function(){return w.getters["auth/me"]})),N=[],B=function(){clearTimeout(void 0),v.value=-1,u.value.trim()?(s.value=!0,u.value.trim()&&r.shop.search(u.value).then((function(e){e.data&&(_(),d.value=e.data.products,m.value=e.data.total,y.value=e.data.separator,p.value=e.data.byCategory,new l.default(g.value))})).finally((function(){s.value=!1}))):(d.value=[],s.value=!1)},_=function(){if(u.value.length>1){var e=o.get("search")?o.get("search"):[];-1!==e.indexOf(u.value)&&(e=e.filter((function(e){return e!==u.value}))),e.length>4&&(e=e.slice(0,4)),e.unshift(u.value),o.set("search",e),k.value=e}};e.onBeforeUpdate((function(){N=[]})),e.watch((function(){return u.value}),(function(){h.value=!0,v.value=-1,B()}));var C=e.computed((function(){return u.value?$env.locale.url+"/search"+S.value:$env.locale.url+"/search"})),S=e.computed((function(){return n.parameter.replace("{separator}",y.value)+u.value.toLowerCase()})),D=function(e){e.target.closest(".cart")||(h.value=!1,v.value=-1)};window.addEventListener("click",D);var L,q=e.computed((function(){return u.value.length>3?E.value.filter((function(e){return-1!==e.search.indexOf(u.value)})):[]})),x=(L=function(){var e,t,r,o=document.getElementById("menu");return o&&o.querySelectorAll("[data-search]").forEach((function(e){var t=e.textContent.trim(),r=e.dataset.search;E.value.push({name:(r?r+" / ":"")+t,search:t.toLowerCase(),href:e.closest("a").href})})),n.q&&B(),r?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{return Promise.resolve(L.apply(this,e))}catch(e){return Promise.reject(e)}});return document.addEventListener("DOMContentLoaded",x,!1),{isLoading:s,term:u,results:d,next:function(){v.value<d.value.length-1&&v.value++},prev:function(){v.value>=0&&v.value--},current:v,add:function(e){v.value>=0&&(e.preventDefault(),N[v.value].add())},cartRefs:function(e){e&&N.push(e)},isDropdown:h,preventCaret:function(e){(38==e.which||40==e.which||32==e.which&&v.value>=0)&&e.preventDefault()},esc:function(e){f.value.blur(),D(e)},input:f,dropdown:function(){h.value=!0,v.value=-1},total:m,searchUrl:C,searchHrefWithParameter:S,open:function(){v.value>=0?window.location.href=d.value[v.value].href:window.location.href=C.value},categories:q,byCategory:p,dropdownContent:g,history:k,clearSearchHistory:function(e){o.remove("search"),k.value=[],f.value.focus()},setSearchHistory:function(e){e.value=e},user:V}}}),s={class:"dropdown-trigger"},u=["placeholder"],d={class:"icon is-small is-right"},p=[e.createElementVNode("i",{class:"fas fa-search"},null,-1)],m={key:0,class:"dropdown-menu"},v={class:"dropdown-content"},h={class:"history-list"},f={class:"dropdown-item history-list-title"},y=["onClick"],g={class:"dropdown-item history-list-clear"},k={class:"dropdown-menu"},E={class:"dropdown-content",style:{"max-height":"600px",overflow:"auto"},ref:"dropdownContent"},w={key:0,class:"results-list"},V=["href"],N={key:0,class:"dropdown-divider"},B={key:1,class:"results-list-category"},_={class:"dropdown-item categories-list-title"},C=["href"],S={key:2,class:"results-list-total"},D={class:"dropdown-item mb-3 mt-2"},L=e.createElementVNode("br",null,null,-1),q=["href"],x={key:3,class:"products-list"},b={class:"dropdown-item products-list-title"},H={class:"columns"},T={class:"column"},K={class:"title"},M=["href"],P=["innerHTML"],F={key:0,class:"price_old"},R=["innerHTML"],U={class:"code"},$={key:1,class:"quantity"},z={key:2,class:"no-quantity"},O={key:0,class:"column is-narrow"},j={key:1,class:"column is-eol"},W={key:0,class:"dropdown-content"},A={class:"dropdown-item"},I={class:"no-results"};i.render=function(t,r,n,o,a,l){var c=e.resolveComponent("cart-add");return e.openBlock(),e.createElementBlock("div",{class:"shop-search",onClick:r[10]||(r[10]=function(e){return e.stopPropagation()})},[e.createElementVNode("div",{class:e.normalizeClass(["dropdown",{"is-active":t.isDropdown,"is-dropdown-visible":t.isDropdown&&(t.history.length&&!t.term||t.results.length||t.categories.length||t.term&&!t.isLoading&&!t.results.length&&!t.categories.length)}])},[e.createElementVNode("div",{class:"overlay search-overlay",onClick:r[0]||(r[0]=function(e){return t.esc(e)})}),e.createElementVNode("div",s,[e.createElementVNode("div",{class:e.normalizeClass(["control has-icons-right",{"is-loading":t.isLoading}])},[e.withDirectives(e.createElementVNode("input",{class:"input",type:"text","onUpdate:modelValue":r[1]||(r[1]=function(e){return t.term=e}),ref:"input",placeholder:t.placeholder,onKeyup:[r[2]||(r[2]=e.withKeys((function(){return t.next&&t.next.apply(t,arguments)}),["arrow-down"])),r[3]||(r[3]=e.withKeys((function(){return t.prev&&t.prev.apply(t,arguments)}),["arrow-up"])),r[4]||(r[4]=e.withKeys((function(e){return t.add(e)}),["space"])),r[5]||(r[5]=e.withKeys((function(){return t.open&&t.open.apply(t,arguments)}),["enter"])),r[6]||(r[6]=e.withKeys((function(e){return t.esc(e)}),["esc"]))],onClick:r[7]||(r[7]=function(){return t.dropdown&&t.dropdown.apply(t,arguments)}),onKeydown:r[8]||(r[8]=function(e){return t.preventCaret(e)})},null,40,u),[[e.vModelText,t.term]]),e.renderSlot(t.$slots,"icon",{isLoading:t.isLoading},(function(){return[e.withDirectives(e.createElementVNode("span",d,p,512),[[e.vShow,!t.isLoading]])]}))],2)]),t.isDropdown&&t.history.length&&!t.term?(e.openBlock(),e.createElementBlock("div",m,[e.createElementVNode("div",v,[e.createElementVNode("div",h,[e.createElementVNode("div",f,[e.createElementVNode("p",null,e.toDisplayString(t.__("shop.search.history")),1)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.history,(function(r,n){return e.openBlock(),e.createElementBlock("div",{class:"dropdown-item",key:n},[e.createElementVNode("a",{onClick:function(e){return t.term=r}},e.toDisplayString(r),9,y)])})),128)),e.createElementVNode("div",g,[e.createElementVNode("a",{onClick:r[9]||(r[9]=function(e){return t.clearSearchHistory(e)})},e.toDisplayString(t.__("shop.search.history_clear")),1)])])])])):e.createCommentVNode("v-if",!0),e.withDirectives(e.createElementVNode("div",k,[e.withDirectives(e.createElementVNode("div",E,[t.categories.length?(e.openBlock(),e.createElementBlock("div",w,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.categories,(function(t,r){return e.openBlock(),e.createElementBlock("div",{class:"dropdown-item",key:r},[e.createElementVNode("div",null,[e.createElementVNode("a",{href:t.href},e.toDisplayString(t.name),9,V)])])})),128)),t.byCategory.length?(e.openBlock(),e.createElementBlock("hr",N)):e.createCommentVNode("v-if",!0)])):e.createCommentVNode("v-if",!0),t.byCategory.length?(e.openBlock(),e.createElementBlock("div",B,[e.createElementVNode("div",_,e.toDisplayString(t.__("shop.search.categories")),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.byCategory,(function(r,n){return e.openBlock(),e.createElementBlock("div",{class:"dropdown-item",key:n},[e.createElementVNode("div",null,[e.createElementVNode("a",{href:r.href+t.searchHrefWithParameter},e.toDisplayString(r.name),9,C)]),e.createElementVNode("div",null,e.toDisplayString(t.__("shop.search.category_found",{count:r.count})),1)])})),128))])):e.createCommentVNode("v-if",!0),t.total?(e.openBlock(),e.createElementBlock("div",S,[e.createElementVNode("p",D,[e.createTextVNode(e.toDisplayString(t.__("shop.search.total_found",{total:t.total}))+" ",1),L,e.createElementVNode("a",{href:t.searchUrl},e.toDisplayString(t.__("shop.search.open_results")),9,q)])])):e.createCommentVNode("v-if",!0),t.results.length?(e.openBlock(),e.createElementBlock("div",x,[e.createElementVNode("div",b,e.toDisplayString(t.__("shop.search.products")),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.results,(function(r,n){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["dropdown-item",{"is-active":t.current==n}]),key:r.id},[e.renderSlot(t.$slots,"item",{user:t.user,item:r,cartRefs:t.cartRefs},(function(){return[e.createElementVNode("div",H,[e.createElementVNode("div",T,[e.createElementVNode("div",K,[e.createElementVNode("a",{href:r.href},e.toDisplayString(r.name),9,M)]),e.createElementVNode("div",{class:"price",innerHTML:r.price},null,8,P),r.price_old?(e.openBlock(),e.createElementBlock("div",F,[e.createElementVNode("span",{innerHTML:r.price_old},null,8,R)])):e.createCommentVNode("v-if",!0),e.createElementVNode("div",U,e.toDisplayString(r.code),1),r.quantity?(e.openBlock(),e.createElementBlock("div",$,e.toDisplayString(t.__("shop.search.in_stock")),1)):(e.openBlock(),e.createElementBlock("span",z,e.toDisplayString(t.__("shop.search.out_stock")),1))]),r.is_eol?(e.openBlock(),e.createElementBlock("div",j,e.toDisplayString(t.__("shop.search.eol")),1)):(e.openBlock(),e.createElementBlock("div",O,[e.createVNode(c,{id:r.id,"is-change-quantity":!1,"is-already-in-cart":!1,ref_for:!0,ref:t.cartRefs},null,8,["id"])]))])]}))],2)})),128))])):e.createCommentVNode("v-if",!0)],512),[[e.vShow,t.results.length||t.categories.length]]),t.isLoading||t.results.length||t.categories.length?e.createCommentVNode("v-if",!0):(e.openBlock(),e.createElementBlock("div",W,[e.createElementVNode("div",A,[e.createElementVNode("div",I,e.toDisplayString(t.__("shop.search.no_results")),1)])]))],512),[[e.vShow,t.results.length||t.term]])],2)])},module.exports=i;
|
|
1
|
+
"use strict";var e=require("vue"),t=require("vuex"),r=require("@perevorot/shop/dist/api"),n=require("simplebar"),o=require("secure-ls");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=a(n),c=a(o);var i=e.defineComponent({name:"search",props:{q:{type:String,default:""},placeholder:{type:String,default:""},parameter:{type:String,default:"/q{separator}"}},setup:function(n){var o=new c.default({isCompression:!1}),a=n.q;if(a){var i=document.createElement("textarea");i.innerHTML=a,a=i.value}var s=e.ref(!1),u=e.ref(a),d=e.ref([]),p=e.ref([]),m=e.ref(0),v=e.ref(-1),h=e.ref(!1),f=e.ref(),y=e.ref(""),g=e.ref(),k=e.ref(o.get("search")),E=e.ref([]),w=t.useStore(),V=e.computed((function(){return w.getters["auth/me"]})),N=[],B=function(){clearTimeout(void 0),v.value=-1,u.value.trim()?(s.value=!0,u.value.trim()&&r.shop.search(u.value).then((function(e){e.data&&(_(),d.value=e.data.products,m.value=e.data.total,y.value=e.data.separator,p.value=e.data.byCategory,new l.default(g.value))})).finally((function(){s.value=!1}))):(d.value=[],s.value=!1)},_=function(){if(u.value.length>1){var e=o.get("search")?o.get("search"):[];-1!==e.indexOf(u.value)&&(e=e.filter((function(e){return e!==u.value}))),e.length>4&&(e=e.slice(0,4)),e.unshift(u.value),o.set("search",e),k.value=e}};e.onBeforeUpdate((function(){N=[]})),e.watch((function(){return u.value}),(function(){h.value=!0,v.value=-1,B()}));var C=e.computed((function(){return u.value?$env.locale.url+"/search"+S.value:$env.locale.url+"/search"})),S=e.computed((function(){return n.parameter.replace("{separator}",y.value)+u.value.toLowerCase()})),D=function(e){e.target.closest(".cart")||(h.value=!1,v.value=-1)};window.addEventListener("click",D);var L,q=e.computed((function(){return u.value.length>3?E.value.filter((function(e){return-1!==e.search.indexOf(u.value)})):[]})),x=(L=function(){var e,t,r,o=document.getElementById("menu");return o&&o.querySelectorAll("[data-search]").forEach((function(e){var t=e.textContent.trim(),r=e.dataset.search;E.value.push({name:(r?r+" / ":"")+t,search:t.toLowerCase(),href:e.closest("a").href})})),n.q&&B(),r?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{return Promise.resolve(L.apply(this,e))}catch(e){return Promise.reject(e)}});return document.addEventListener("DOMContentLoaded",x,!1),{isLoading:s,term:u,results:d,next:function(){v.value<d.value.length-1&&v.value++},prev:function(){v.value>=0&&v.value--},current:v,add:function(e){v.value>=0&&(e.preventDefault(),N[v.value].add())},cartRefs:function(e){e&&N.push(e)},isDropdown:h,preventCaret:function(e){(38==e.which||40==e.which||32==e.which&&v.value>=0)&&e.preventDefault()},esc:function(e){f.value.blur(),D(e)},input:f,dropdown:function(){h.value=!0,v.value=-1},total:m,searchUrl:C,searchHrefWithParameter:S,open:function(){v.value>=0?window.location.href=d.value[v.value].href:window.location.href=C.value},categories:q,byCategory:p,dropdownContent:g,history:k,clearSearchHistory:function(e){o.remove("search"),k.value=[],f.value.focus()},setSearchHistory:function(e){e.value=e},user:V}}}),s={class:"dropdown-trigger"},u=["placeholder"],d={class:"icon is-small is-right"},p=[e.createElementVNode("i",{class:"fas fa-search"},null,-1)],m={key:0,class:"dropdown-menu"},v={class:"dropdown-content"},h={class:"history-list"},f={class:"dropdown-item history-list-title"},y=["onClick"],g={class:"dropdown-item history-list-clear"},k={class:"dropdown-menu"},E={class:"dropdown-content",style:{"max-height":"600px",overflow:"auto"},ref:"dropdownContent"},w={key:0,class:"results-list"},V=["href"],N={key:0,class:"dropdown-divider"},B={key:1,class:"results-list-category"},_={class:"dropdown-item categories-list-title"},C=["href"],S={key:2,class:"results-list-total"},D={class:"dropdown-item mb-3 mt-2"},L=e.createElementVNode("br",null,null,-1),q=["href"],x={key:3,class:"products-list"},H={class:"dropdown-item products-list-title"},b={class:"columns"},P={class:"column"},T={class:"title"},K=["href"],M=["innerHTML"],$={key:0,class:"price_old"},F=["innerHTML"],R={class:"code"},U={key:1,class:"quantity"},W={key:2,class:"no-quantity"},z={key:0,class:"column is-narrow"},O={key:1,class:"column is-eol"},j={key:0,class:"dropdown-content"},A={class:"dropdown-item"},I={class:"no-results"};i.render=function(t,r,n,o,a,l){var c=e.resolveComponent("cart-add");return e.openBlock(),e.createElementBlock("div",{class:"shop-search",onClick:r[10]||(r[10]=function(e){return e.stopPropagation()})},[e.createElementVNode("div",{class:e.normalizeClass(["dropdown",{"is-active":t.isDropdown,"is-dropdown-visible":t.isDropdown&&(t.history.length&&!t.term||t.results.length||t.categories.length||t.term&&!t.isLoading&&!t.results.length&&!t.categories.length)}])},[e.createElementVNode("div",{class:"overlay search-overlay",onClick:r[0]||(r[0]=function(e){return t.esc(e)})}),e.createElementVNode("div",s,[e.createElementVNode("div",{class:e.normalizeClass(["control has-icons-right",{"is-loading":t.isLoading}])},[e.withDirectives(e.createElementVNode("input",{class:"input",type:"text","onUpdate:modelValue":r[1]||(r[1]=function(e){return t.term=e}),ref:"input",placeholder:t.placeholder,onKeyup:[r[2]||(r[2]=e.withKeys((function(){return t.next&&t.next.apply(t,arguments)}),["arrow-down"])),r[3]||(r[3]=e.withKeys((function(){return t.prev&&t.prev.apply(t,arguments)}),["arrow-up"])),r[4]||(r[4]=e.withKeys((function(e){return t.add(e)}),["space"])),r[5]||(r[5]=e.withKeys((function(){return t.open&&t.open.apply(t,arguments)}),["enter"])),r[6]||(r[6]=e.withKeys((function(e){return t.esc(e)}),["esc"]))],onClick:r[7]||(r[7]=function(){return t.dropdown&&t.dropdown.apply(t,arguments)}),onKeydown:r[8]||(r[8]=function(e){return t.preventCaret(e)})},null,40,u),[[e.vModelText,t.term]]),e.renderSlot(t.$slots,"icon",{isLoading:t.isLoading},(function(){return[e.withDirectives(e.createElementVNode("span",d,p,512),[[e.vShow,!t.isLoading]])]}))],2)]),t.isDropdown&&t.history.length&&!t.term?(e.openBlock(),e.createElementBlock("div",m,[e.createElementVNode("div",v,[e.createElementVNode("div",h,[e.createElementVNode("div",f,[e.createElementVNode("p",null,e.toDisplayString(t.__("shop.search.history")),1)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.history,(function(r,n){return e.openBlock(),e.createElementBlock("div",{class:"dropdown-item",key:n},[e.createElementVNode("a",{onClick:function(e){return t.term=r}},e.toDisplayString(r),9,y)])})),128)),e.createElementVNode("div",g,[e.createElementVNode("a",{onClick:r[9]||(r[9]=function(e){return t.clearSearchHistory(e)})},e.toDisplayString(t.__("shop.search.history_clear")),1)])])])])):e.createCommentVNode("v-if",!0),e.withDirectives(e.createElementVNode("div",k,[e.withDirectives(e.createElementVNode("div",E,[t.categories.length?(e.openBlock(),e.createElementBlock("div",w,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.categories,(function(t,r){return e.openBlock(),e.createElementBlock("div",{class:"dropdown-item",key:r},[e.createElementVNode("div",null,[e.createElementVNode("a",{href:t.href},e.toDisplayString(t.name),9,V)])])})),128)),t.byCategory.length?(e.openBlock(),e.createElementBlock("hr",N)):e.createCommentVNode("v-if",!0)])):e.createCommentVNode("v-if",!0),t.byCategory.length?(e.openBlock(),e.createElementBlock("div",B,[e.createElementVNode("div",_,e.toDisplayString(t.__("shop.search.categories")),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.byCategory,(function(r,n){return e.openBlock(),e.createElementBlock("div",{class:"dropdown-item",key:n},[e.renderSlot(t.$slots,"item-category",{item:r,searchHrefWithParameter:t.searchHrefWithParameter},(function(){return[e.createElementVNode("div",null,[e.createElementVNode("a",{href:r.href+t.searchHrefWithParameter},e.toDisplayString(r.name),9,C)]),e.createElementVNode("div",null,e.toDisplayString(t.__("shop.search.category_found",{count:r.count})),1)]}))])})),128))])):e.createCommentVNode("v-if",!0),t.total?(e.openBlock(),e.createElementBlock("div",S,[e.createElementVNode("p",D,[e.createTextVNode(e.toDisplayString(t.__("shop.search.total_found",{total:t.total}))+" ",1),L,e.createElementVNode("a",{href:t.searchUrl},e.toDisplayString(t.__("shop.search.open_results")),9,q)])])):e.createCommentVNode("v-if",!0),t.results.length?(e.openBlock(),e.createElementBlock("div",x,[e.createElementVNode("div",H,e.toDisplayString(t.__("shop.search.products")),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.results,(function(r,n){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["dropdown-item",{"is-active":t.current==n}]),key:r.id},[e.renderSlot(t.$slots,"item",{user:t.user,item:r,cartRefs:t.cartRefs},(function(){return[e.createElementVNode("div",b,[e.createElementVNode("div",P,[e.createElementVNode("div",T,[e.createElementVNode("a",{href:r.href},e.toDisplayString(r.name),9,K)]),e.createElementVNode("div",{class:"price",innerHTML:r.price},null,8,M),r.price_old?(e.openBlock(),e.createElementBlock("div",$,[e.createElementVNode("span",{innerHTML:r.price_old},null,8,F)])):e.createCommentVNode("v-if",!0),e.createElementVNode("div",R,e.toDisplayString(r.code),1),r.quantity?(e.openBlock(),e.createElementBlock("div",U,e.toDisplayString(t.__("shop.search.in_stock")),1)):(e.openBlock(),e.createElementBlock("span",W,e.toDisplayString(t.__("shop.search.out_stock")),1))]),r.is_eol?(e.openBlock(),e.createElementBlock("div",O,e.toDisplayString(t.__("shop.search.eol")),1)):(e.openBlock(),e.createElementBlock("div",z,[e.createVNode(c,{id:r.id,"is-change-quantity":!1,"is-already-in-cart":!1,ref_for:!0,ref:t.cartRefs},null,8,["id"])]))])]}))],2)})),128))])):e.createCommentVNode("v-if",!0)],512),[[e.vShow,t.results.length||t.categories.length]]),t.isLoading||t.results.length||t.categories.length?e.createCommentVNode("v-if",!0):(e.openBlock(),e.createElementBlock("div",j,[e.createElementVNode("div",A,[e.createElementVNode("div",I,e.toDisplayString(t.__("shop.search.no_results")),1)])]))],512),[[e.vShow,t.results.length||t.term]])],2)])},module.exports=i;
|
|
2
2
|
//# sourceMappingURL=Search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.js","sources":["../../../src/components/shop/Search.vue","../../../src/components/shop/Search.vue?vue&type=template&id=3dba7fa2&lang.js"],"sourcesContent":["<template>\n <div class=\"shop-search\" @click=\"$event.stopPropagation()\">\n <div\n class=\"dropdown\"\n v-bind:class=\"{\n 'is-active': isDropdown,\n 'is-dropdown-visible': isDropdown && ((history.length && !term) || results.length || categories.length || (term && !isLoading && !results.length && !categories.length))\n }\"\n >\n <div class=\"overlay search-overlay\" @click=\"esc($event)\"></div>\n <div class=\"dropdown-trigger\">\n <div class=\"control has-icons-right\" v-bind:class=\"{ 'is-loading': isLoading }\">\n <input class=\"input\" type=\"text\" v-model=\"term\" ref=\"input\" :placeholder=\"placeholder\" @keyup.arrow-down=\"next\" @keyup.arrow-up=\"prev\" @keyup.space=\"add($event)\" @keyup.enter=\"open\" @keyup.esc=\"esc($event)\" @click=\"dropdown\" @keydown=\"preventCaret($event)\" />\n <slot name=\"icon\" :isLoading=\"isLoading\">\n <span class=\"icon is-small is-right\" v-show=\"!isLoading\">\n <i class=\"fas fa-search\"></i>\n </span>\n </slot>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-if=\"isDropdown && history.length && !term\">\n <div class=\"dropdown-content\">\n <div class=\"history-list\">\n <div class=\"dropdown-item history-list-title\">\n <p>{{ __('shop.search.history') }}</p>\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in history\" v-bind:key=\"index\">\n <a @click=\"term = item\">{{ item }}</a>\n </div>\n <div class=\"dropdown-item history-list-clear\">\n <a @click=\"clearSearchHistory($event)\">{{ __('shop.search.history_clear') }}</a>\n </div>\n </div>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-show=\"results.length || term\">\n <div class=\"dropdown-content\" v-show=\"results.length || categories.length\" style=\"max-height: 600px; overflow: auto\" ref=\"dropdownContent\">\n <div class=\"results-list\" v-if=\"categories.length\">\n <div class=\"dropdown-item\" v-for=\"(item, index) in categories\" v-bind:key=\"index\">\n <div>\n <a :href=\"item.href\">{{ item.name }}</a>\n </div>\n </div>\n <hr class=\"dropdown-divider\" v-if=\"byCategory.length\" />\n </div>\n <div class=\"results-list-category\" v-if=\"byCategory.length\">\n <div class=\"dropdown-item categories-list-title\">\n {{ __('shop.search.categories') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in byCategory\" v-bind:key=\"index\">\n <div>\n <a :href=\"item.href + searchHrefWithParameter\">{{ item.name }}</a>\n </div>\n <div>\n {{\n __('shop.search.category_found', {\n count: item.count\n })\n }}\n </div>\n </div>\n </div>\n <div class=\"results-list-total\" v-if=\"total\">\n <p class=\"dropdown-item mb-3 mt-2\">\n {{\n __('shop.search.total_found', {\n total: total\n })\n }}\n <br />\n <a :href=\"searchUrl\">{{ __('shop.search.open_results') }}</a>\n </p>\n </div>\n <div class=\"products-list\" v-if=\"results.length\">\n <div class=\"dropdown-item products-list-title\">\n {{ __('shop.search.products') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in results\" v-bind:key=\"item.id\" v-bind:class=\"{ 'is-active': current == index }\">\n <slot name=\"item\" :user=\"user\" :item=\"item\" :cart-refs=\"cartRefs\">\n <div class=\"columns\">\n <div class=\"column\">\n <div class=\"title\">\n <a :href=\"item.href\">\n {{ item.name }}\n </a>\n </div>\n <div class=\"price\" v-html=\"item.price\"></div>\n <div class=\"price_old\" v-if=\"item.price_old\">\n <span v-html=\"item.price_old\"></span>\n </div>\n <div class=\"code\">{{ item.code }}</div>\n <div class=\"quantity\" v-if=\"item.quantity\">\n {{ __('shop.search.in_stock') }}\n </div>\n <span class=\"no-quantity\" v-else>\n {{ __('shop.search.out_stock') }}\n </span>\n </div>\n <div class=\"column is-narrow\" v-if=\"!item.is_eol\">\n <cart-add :id=\"item.id\" :is-change-quantity=\"false\" :is-already-in-cart=\"false\" :ref=\"cartRefs\"></cart-add>\n </div>\n <div v-else class=\"column is-eol\">\n {{ __('shop.search.eol') }}\n </div>\n </div>\n </slot>\n </div>\n </div>\n </div>\n <div class=\"dropdown-content\" v-if=\"!isLoading && !results.length && !categories.length\">\n <div class=\"dropdown-item\">\n <div class=\"no-results\">\n {{ __('shop.search.no_results') }}\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n</template>\n<script>\nimport { ref, watch, onBeforeUpdate, defineComponent, computed } from 'vue';\nimport { useStore } from 'vuex';\nimport { shop as api } from '@perevorot/shop/dist/api';\nimport SimpleBar from 'simplebar';\nimport SecureLS from 'secure-ls';\n\nexport default /*#__PURE__*/ defineComponent({\n name: 'search',\n props: {\n q: {\n type: String,\n default: ''\n },\n placeholder: {\n type: String,\n default: ''\n },\n parameter: {\n type: String,\n default: '/q{separator}'\n }\n },\n setup(props) {\n const ls = new SecureLS({\n isCompression: false\n });\n\n let q = props.q;\n\n if (q) {\n let encoder = document.createElement('textarea');\n encoder.innerHTML = q;\n q = encoder.value;\n }\n\n const isLoading = ref(false);\n const term = ref(q);\n const results = ref([]);\n const byCategory = ref([]);\n const total = ref(0);\n const current = ref(-1);\n const isDropdown = ref(false);\n const input = ref();\n const separator = ref('');\n const dropdownContent = ref();\n const history = ref(ls.get('search'));\n const menu = ref([]);\n const store = useStore();\n const user = computed(() => store.getters['auth/me']);\n\n let refs = [];\n let timeout;\n\n const search = () => {\n clearTimeout(timeout);\n\n current.value = -1;\n\n if (!term.value.trim()) {\n results.value = [];\n isLoading.value = false;\n } else {\n isLoading.value = true;\n\n //timeout = setTimeout(() => {\n if (term.value.trim()) {\n api.search(term.value)\n .then((response) => {\n if (response.data) {\n saveSearch();\n\n results.value = response.data.products;\n total.value = response.data.total;\n separator.value = response.data.separator;\n byCategory.value = response.data.byCategory;\n\n const scrollBar = new SimpleBar(dropdownContent.value);\n }\n })\n .finally(() => {\n isLoading.value = false;\n });\n }\n //}, 500);\n }\n };\n\n const saveSearch = () => {\n if (term.value.length > 1) {\n let search = ls.get('search') ? ls.get('search') : [];\n\n if (search.indexOf(term.value) !== -1) {\n search = search.filter((item) => item !== term.value);\n }\n\n if (search.length > 4) {\n search = search.slice(0, 4);\n }\n\n search.unshift(term.value);\n\n ls.set('search', search);\n\n history.value = search;\n }\n };\n\n const setSearchHistory = (term) => {\n term.value = term;\n };\n\n const clearSearchHistory = (event) => {\n ls.remove('search');\n\n history.value = [];\n\n input.value.focus();\n };\n\n onBeforeUpdate(() => {\n refs = [];\n });\n\n watch(\n () => term.value,\n () => {\n isDropdown.value = true;\n current.value = -1;\n search();\n }\n );\n\n const searchUrl = computed(() => {\n return term.value ? $env.locale.url + '/search' + searchHrefWithParameter.value : $env.locale.url + '/search';\n });\n\n const searchHrefWithParameter = computed(() => {\n return props.parameter.replace('{separator}', separator.value) + term.value.toLowerCase();\n });\n\n const preventCaret = (event) => {\n if (event.which == 38 || event.which == 40 || (event.which == 32 && current.value >= 0)) {\n event.preventDefault();\n }\n };\n\n const next = () => {\n if (current.value < results.value.length - 1) {\n current.value++;\n }\n };\n\n const prev = () => {\n if (current.value >= 0) {\n current.value--;\n }\n };\n\n const add = (event) => {\n if (current.value >= 0) {\n event.preventDefault();\n\n refs[current.value].add();\n }\n };\n\n const open = () => {\n if (current.value >= 0) {\n window.location.href = results.value[current.value].href;\n } else {\n window.location.href = searchUrl.value;\n }\n };\n\n const esc = (event) => {\n input.value.blur();\n close(event);\n };\n\n const cartRefs = (el) => {\n if (el) {\n refs.push(el);\n }\n };\n\n const close = (event) => {\n if (!event.target.closest('.cart')) {\n isDropdown.value = false;\n current.value = -1;\n }\n };\n\n const dropdown = () => {\n isDropdown.value = true;\n current.value = -1;\n };\n\n window.addEventListener('click', close);\n\n const categories = computed(() => {\n return term.value.length > 3 ? menu.value.filter((item) => item.search.indexOf(term.value) !== -1) : [];\n });\n\n const load = async () => {\n const menuElement = document.getElementById('menu');\n\n if (menuElement) {\n menuElement.querySelectorAll('[data-search]').forEach((element) => {\n const name = element.textContent.trim();\n const data = element.dataset.search;\n\n menu.value.push({\n name: (data ? data + ' / ' : '') + name,\n search: name.toLowerCase(),\n href: element.closest('a').href\n });\n });\n }\n\n if (props.q) {\n search();\n }\n };\n\n document.addEventListener('DOMContentLoaded', load, false);\n\n return {\n isLoading,\n term,\n results,\n next,\n prev,\n current,\n add,\n cartRefs,\n isDropdown,\n preventCaret,\n esc,\n input,\n dropdown,\n total,\n searchUrl,\n searchHrefWithParameter,\n open,\n categories,\n byCategory,\n dropdownContent,\n history,\n clearSearchHistory,\n setSearchHistory,\n user\n };\n }\n});\n</script>","<template>\n <div class=\"shop-search\" @click=\"$event.stopPropagation()\">\n <div\n class=\"dropdown\"\n v-bind:class=\"{\n 'is-active': isDropdown,\n 'is-dropdown-visible': isDropdown && ((history.length && !term) || results.length || categories.length || (term && !isLoading && !results.length && !categories.length))\n }\"\n >\n <div class=\"overlay search-overlay\" @click=\"esc($event)\"></div>\n <div class=\"dropdown-trigger\">\n <div class=\"control has-icons-right\" v-bind:class=\"{ 'is-loading': isLoading }\">\n <input class=\"input\" type=\"text\" v-model=\"term\" ref=\"input\" :placeholder=\"placeholder\" @keyup.arrow-down=\"next\" @keyup.arrow-up=\"prev\" @keyup.space=\"add($event)\" @keyup.enter=\"open\" @keyup.esc=\"esc($event)\" @click=\"dropdown\" @keydown=\"preventCaret($event)\" />\n <slot name=\"icon\" :isLoading=\"isLoading\">\n <span class=\"icon is-small is-right\" v-show=\"!isLoading\">\n <i class=\"fas fa-search\"></i>\n </span>\n </slot>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-if=\"isDropdown && history.length && !term\">\n <div class=\"dropdown-content\">\n <div class=\"history-list\">\n <div class=\"dropdown-item history-list-title\">\n <p>{{ __('shop.search.history') }}</p>\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in history\" v-bind:key=\"index\">\n <a @click=\"term = item\">{{ item }}</a>\n </div>\n <div class=\"dropdown-item history-list-clear\">\n <a @click=\"clearSearchHistory($event)\">{{ __('shop.search.history_clear') }}</a>\n </div>\n </div>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-show=\"results.length || term\">\n <div class=\"dropdown-content\" v-show=\"results.length || categories.length\" style=\"max-height: 600px; overflow: auto\" ref=\"dropdownContent\">\n <div class=\"results-list\" v-if=\"categories.length\">\n <div class=\"dropdown-item\" v-for=\"(item, index) in categories\" v-bind:key=\"index\">\n <div>\n <a :href=\"item.href\">{{ item.name }}</a>\n </div>\n </div>\n <hr class=\"dropdown-divider\" v-if=\"byCategory.length\" />\n </div>\n <div class=\"results-list-category\" v-if=\"byCategory.length\">\n <div class=\"dropdown-item categories-list-title\">\n {{ __('shop.search.categories') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in byCategory\" v-bind:key=\"index\">\n <div>\n <a :href=\"item.href + searchHrefWithParameter\">{{ item.name }}</a>\n </div>\n <div>\n {{\n __('shop.search.category_found', {\n count: item.count\n })\n }}\n </div>\n </div>\n </div>\n <div class=\"results-list-total\" v-if=\"total\">\n <p class=\"dropdown-item mb-3 mt-2\">\n {{\n __('shop.search.total_found', {\n total: total\n })\n }}\n <br />\n <a :href=\"searchUrl\">{{ __('shop.search.open_results') }}</a>\n </p>\n </div>\n <div class=\"products-list\" v-if=\"results.length\">\n <div class=\"dropdown-item products-list-title\">\n {{ __('shop.search.products') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in results\" v-bind:key=\"item.id\" v-bind:class=\"{ 'is-active': current == index }\">\n <slot name=\"item\" :user=\"user\" :item=\"item\" :cart-refs=\"cartRefs\">\n <div class=\"columns\">\n <div class=\"column\">\n <div class=\"title\">\n <a :href=\"item.href\">\n {{ item.name }}\n </a>\n </div>\n <div class=\"price\" v-html=\"item.price\"></div>\n <div class=\"price_old\" v-if=\"item.price_old\">\n <span v-html=\"item.price_old\"></span>\n </div>\n <div class=\"code\">{{ item.code }}</div>\n <div class=\"quantity\" v-if=\"item.quantity\">\n {{ __('shop.search.in_stock') }}\n </div>\n <span class=\"no-quantity\" v-else>\n {{ __('shop.search.out_stock') }}\n </span>\n </div>\n <div class=\"column is-narrow\" v-if=\"!item.is_eol\">\n <cart-add :id=\"item.id\" :is-change-quantity=\"false\" :is-already-in-cart=\"false\" :ref=\"cartRefs\"></cart-add>\n </div>\n <div v-else class=\"column is-eol\">\n {{ __('shop.search.eol') }}\n </div>\n </div>\n </slot>\n </div>\n </div>\n </div>\n <div class=\"dropdown-content\" v-if=\"!isLoading && !results.length && !categories.length\">\n <div class=\"dropdown-item\">\n <div class=\"no-results\">\n {{ __('shop.search.no_results') }}\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n</template>\n<script>\nimport { ref, watch, onBeforeUpdate, defineComponent, computed } from 'vue';\nimport { useStore } from 'vuex';\nimport { shop as api } from '@perevorot/shop/dist/api';\nimport SimpleBar from 'simplebar';\nimport SecureLS from 'secure-ls';\n\nexport default /*#__PURE__*/ defineComponent({\n name: 'search',\n props: {\n q: {\n type: String,\n default: ''\n },\n placeholder: {\n type: String,\n default: ''\n },\n parameter: {\n type: String,\n default: '/q{separator}'\n }\n },\n setup(props) {\n const ls = new SecureLS({\n isCompression: false\n });\n\n let q = props.q;\n\n if (q) {\n let encoder = document.createElement('textarea');\n encoder.innerHTML = q;\n q = encoder.value;\n }\n\n const isLoading = ref(false);\n const term = ref(q);\n const results = ref([]);\n const byCategory = ref([]);\n const total = ref(0);\n const current = ref(-1);\n const isDropdown = ref(false);\n const input = ref();\n const separator = ref('');\n const dropdownContent = ref();\n const history = ref(ls.get('search'));\n const menu = ref([]);\n const store = useStore();\n const user = computed(() => store.getters['auth/me']);\n\n let refs = [];\n let timeout;\n\n const search = () => {\n clearTimeout(timeout);\n\n current.value = -1;\n\n if (!term.value.trim()) {\n results.value = [];\n isLoading.value = false;\n } else {\n isLoading.value = true;\n\n //timeout = setTimeout(() => {\n if (term.value.trim()) {\n api.search(term.value)\n .then((response) => {\n if (response.data) {\n saveSearch();\n\n results.value = response.data.products;\n total.value = response.data.total;\n separator.value = response.data.separator;\n byCategory.value = response.data.byCategory;\n\n const scrollBar = new SimpleBar(dropdownContent.value);\n }\n })\n .finally(() => {\n isLoading.value = false;\n });\n }\n //}, 500);\n }\n };\n\n const saveSearch = () => {\n if (term.value.length > 1) {\n let search = ls.get('search') ? ls.get('search') : [];\n\n if (search.indexOf(term.value) !== -1) {\n search = search.filter((item) => item !== term.value);\n }\n\n if (search.length > 4) {\n search = search.slice(0, 4);\n }\n\n search.unshift(term.value);\n\n ls.set('search', search);\n\n history.value = search;\n }\n };\n\n const setSearchHistory = (term) => {\n term.value = term;\n };\n\n const clearSearchHistory = (event) => {\n ls.remove('search');\n\n history.value = [];\n\n input.value.focus();\n };\n\n onBeforeUpdate(() => {\n refs = [];\n });\n\n watch(\n () => term.value,\n () => {\n isDropdown.value = true;\n current.value = -1;\n search();\n }\n );\n\n const searchUrl = computed(() => {\n return term.value ? $env.locale.url + '/search' + searchHrefWithParameter.value : $env.locale.url + '/search';\n });\n\n const searchHrefWithParameter = computed(() => {\n return props.parameter.replace('{separator}', separator.value) + term.value.toLowerCase();\n });\n\n const preventCaret = (event) => {\n if (event.which == 38 || event.which == 40 || (event.which == 32 && current.value >= 0)) {\n event.preventDefault();\n }\n };\n\n const next = () => {\n if (current.value < results.value.length - 1) {\n current.value++;\n }\n };\n\n const prev = () => {\n if (current.value >= 0) {\n current.value--;\n }\n };\n\n const add = (event) => {\n if (current.value >= 0) {\n event.preventDefault();\n\n refs[current.value].add();\n }\n };\n\n const open = () => {\n if (current.value >= 0) {\n window.location.href = results.value[current.value].href;\n } else {\n window.location.href = searchUrl.value;\n }\n };\n\n const esc = (event) => {\n input.value.blur();\n close(event);\n };\n\n const cartRefs = (el) => {\n if (el) {\n refs.push(el);\n }\n };\n\n const close = (event) => {\n if (!event.target.closest('.cart')) {\n isDropdown.value = false;\n current.value = -1;\n }\n };\n\n const dropdown = () => {\n isDropdown.value = true;\n current.value = -1;\n };\n\n window.addEventListener('click', close);\n\n const categories = computed(() => {\n return term.value.length > 3 ? menu.value.filter((item) => item.search.indexOf(term.value) !== -1) : [];\n });\n\n const load = async () => {\n const menuElement = document.getElementById('menu');\n\n if (menuElement) {\n menuElement.querySelectorAll('[data-search]').forEach((element) => {\n const name = element.textContent.trim();\n const data = element.dataset.search;\n\n menu.value.push({\n name: (data ? data + ' / ' : '') + name,\n search: name.toLowerCase(),\n href: element.closest('a').href\n });\n });\n }\n\n if (props.q) {\n search();\n }\n };\n\n document.addEventListener('DOMContentLoaded', load, false);\n\n return {\n isLoading,\n term,\n results,\n next,\n prev,\n current,\n add,\n cartRefs,\n isDropdown,\n preventCaret,\n esc,\n input,\n dropdown,\n total,\n searchUrl,\n searchHrefWithParameter,\n open,\n categories,\n byCategory,\n dropdownContent,\n history,\n clearSearchHistory,\n setSearchHistory,\n user\n };\n }\n});\n</script>"],"names":["defineComponent","name","props","q","type","String","placeholder","parameter","setup","ls","SecureLS","isCompression","encoder","document","createElement","innerHTML","value","isLoading","ref","term","results","byCategory","total","current","isDropdown","input","separator","dropdownContent","history","get","menu","store","useStore","user","computed","getters","refs","search","clearTimeout","timeout","trim","api","then","response","data","saveSearch","products","SimpleBar","length","indexOf","filter","item","slice","unshift","set","onBeforeUpdate","watch","searchUrl","$env","locale","url","searchHrefWithParameter","replace","toLowerCase","close","event","target","closest","window","addEventListener","categories","load","menuElement","getElementById","querySelectorAll","forEach","element","textContent","dataset","push","href","resolve","arguments","i","next","prev","add","preventDefault","cartRefs","el","preventCaret","which","esc","blur","dropdown","open","location","clearSearchHistory","remove","focus","setSearchHistory","_createElementVNode","style","_createElementBlock","onClick","$event","stopPropagation","_ctx","_hoisted_1","onKeyup","onKeydown","_renderSlot","_hoisted_3","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","index","key","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_16","_hoisted_17","_hoisted_18","_hoisted_20","_hoisted_21","_hoisted_22","_hoisted_24","_hoisted_25","id","_hoisted_26","_hoisted_27","_hoisted_28","price","price_old","_hoisted_31","_hoisted_33","code","quantity","_hoisted_34","_hoisted_35","is_eol","_hoisted_37","_hoisted_36","_createVNode","_hoisted_38","_hoisted_39","_hoisted_40"],"mappings":"kOA+HA,MAA6BA,kBAAgB,CACzCC,KAAM,SACNC,MAAO,CACHC,EAAG,CACCC,KAAMC,eACG,IAEbC,YAAa,C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,2BAAA6B,oBACOvB,kDAEPJ,kDAAmDI,oBAAhBxD,EAAMkE,wBAAzCd,oDAAW,6BAAmGI,WAAWU,KAAtDC,IAAKnE,EAAKgF,KACzEpB,8BAAmB9E,KAAM0E,OAAOxD,KAAMA,EAAOqC,SAAWmB,aAAxD,kBACIN,2BAAA+B,GACI/B,2BAAAgC,GACIhC,2BAAAiC,GACIjC,0BAAIrB,KAAM7B,EAAK6B,wBACR7B,EAAKlD,aAGhBoG,kCAAW,QAAQtF,UAAQoC,EAAKoF,iBACHpF,EAAKqF,yBAAlCjC,2BAAAkC,GACIpC,6BAAMtF,UAAQoC,EAAKqF,wDAEvBnC,2BAAAqC,oBAAqBvF,EAAKwF,SACExF,EAAKyF,wBAAjCrC,2BAAAsC,oBACOlC,iDAEPJ,4BAAAuC,oBACOnC,qCAG0BxD,EAAK4F,sBAG1CxC,2BAAAyC,oBACOrC,4CAJPJ,2BAAA0C,GACIC,iBAAWf,GAAIhF,EAAKgF,yBAAyB,wBAA4B,aAAQjH,IAAKyF,oGA/DxEA,UAAQ3D,QAAU2D,aAAW3D,UAyE9B2D,aAAcA,UAAQ3D,QAAW2D,aAAW3D,sDAAjFuD,2BAAA4C,GACI9C,2BAAA+C,GACI/C,2BAAAgD,oBACO1C,wDA7EgBA,UAAQ3D,QAAU2D"}
|
|
1
|
+
{"version":3,"file":"Search.js","sources":["../../../src/components/shop/Search.vue","../../../src/components/shop/Search.vue?vue&type=template&id=07a12e50&lang.js"],"sourcesContent":["<template>\n <div class=\"shop-search\" @click=\"$event.stopPropagation()\">\n <div class=\"dropdown\" v-bind:class=\"{\n 'is-active': isDropdown,\n 'is-dropdown-visible': isDropdown && ((history.length && !term) || results.length || categories.length || (term && !isLoading && !results.length && !categories.length))\n }\">\n <div class=\"overlay search-overlay\" @click=\"esc($event)\"></div>\n <div class=\"dropdown-trigger\">\n <div class=\"control has-icons-right\" v-bind:class=\"{ 'is-loading': isLoading }\">\n <input class=\"input\" type=\"text\" v-model=\"term\" ref=\"input\" :placeholder=\"placeholder\" @keyup.arrow-down=\"next\" @keyup.arrow-up=\"prev\" @keyup.space=\"add($event)\" @keyup.enter=\"open\" @keyup.esc=\"esc($event)\" @click=\"dropdown\" @keydown=\"preventCaret($event)\" />\n <slot name=\"icon\" :isLoading=\"isLoading\">\n <span class=\"icon is-small is-right\" v-show=\"!isLoading\">\n <i class=\"fas fa-search\"></i>\n </span>\n </slot>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-if=\"isDropdown && history.length && !term\">\n <div class=\"dropdown-content\">\n <div class=\"history-list\">\n <div class=\"dropdown-item history-list-title\">\n <p>{{ __('shop.search.history') }}</p>\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in history\" v-bind:key=\"index\">\n <a @click=\"term = item\">{{ item }}</a>\n </div>\n <div class=\"dropdown-item history-list-clear\">\n <a @click=\"clearSearchHistory($event)\">{{ __('shop.search.history_clear') }}</a>\n </div>\n </div>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-show=\"results.length || term\">\n <div class=\"dropdown-content\" v-show=\"results.length || categories.length\" style=\"max-height: 600px; overflow: auto\" ref=\"dropdownContent\">\n <div class=\"results-list\" v-if=\"categories.length\">\n <div class=\"dropdown-item\" v-for=\"(item, index) in categories\" v-bind:key=\"index\">\n <div>\n <a :href=\"item.href\">{{ item.name }}</a>\n </div>\n </div>\n <hr class=\"dropdown-divider\" v-if=\"byCategory.length\" />\n </div>\n <div class=\"results-list-category\" v-if=\"byCategory.length\">\n <div class=\"dropdown-item categories-list-title\">\n {{ __('shop.search.categories') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in byCategory\" v-bind:key=\"index\">\n <slot name=\"item-category\" :item=\"item\" :searchHrefWithParameter=\"searchHrefWithParameter\">\n <div>\n <a :href=\"item.href + searchHrefWithParameter\">{{ item.name }}</a>\n </div>\n <div>\n {{ __('shop.search.category_found', { count: item.count }) }}\n </div>\n </slot>\n </div>\n </div>\n <div class=\"results-list-total\" v-if=\"total\">\n <p class=\"dropdown-item mb-3 mt-2\">\n {{\n __('shop.search.total_found', {\n total: total\n })\n }}\n <br />\n <a :href=\"searchUrl\">{{ __('shop.search.open_results') }}</a>\n </p>\n </div>\n <div class=\"products-list\" v-if=\"results.length\">\n <div class=\"dropdown-item products-list-title\">\n {{ __('shop.search.products') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in results\" v-bind:key=\"item.id\" v-bind:class=\"{ 'is-active': current == index }\">\n <slot name=\"item\" :user=\"user\" :item=\"item\" :cart-refs=\"cartRefs\">\n <div class=\"columns\">\n <div class=\"column\">\n <div class=\"title\">\n <a :href=\"item.href\">\n {{ item.name }}\n </a>\n </div>\n <div class=\"price\" v-html=\"item.price\"></div>\n <div class=\"price_old\" v-if=\"item.price_old\">\n <span v-html=\"item.price_old\"></span>\n </div>\n <div class=\"code\">{{ item.code }}</div>\n <div class=\"quantity\" v-if=\"item.quantity\">\n {{ __('shop.search.in_stock') }}\n </div>\n <span class=\"no-quantity\" v-else>\n {{ __('shop.search.out_stock') }}\n </span>\n </div>\n <div class=\"column is-narrow\" v-if=\"!item.is_eol\">\n <cart-add :id=\"item.id\" :is-change-quantity=\"false\" :is-already-in-cart=\"false\" :ref=\"cartRefs\"></cart-add>\n </div>\n <div v-else class=\"column is-eol\">\n {{ __('shop.search.eol') }}\n </div>\n </div>\n </slot>\n </div>\n </div>\n </div>\n <div class=\"dropdown-content\" v-if=\"!isLoading && !results.length && !categories.length\">\n <div class=\"dropdown-item\">\n <div class=\"no-results\">\n {{ __('shop.search.no_results') }}\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n</template>\n<script>\nimport { ref, watch, onBeforeUpdate, defineComponent, computed } from 'vue';\nimport { useStore } from 'vuex';\nimport { shop as api } from '@perevorot/shop/dist/api';\nimport SimpleBar from 'simplebar';\nimport SecureLS from 'secure-ls';\n\nexport default /*#__PURE__*/ defineComponent({\n name: 'search',\n props: {\n q: {\n type: String,\n default: ''\n },\n placeholder: {\n type: String,\n default: ''\n },\n parameter: {\n type: String,\n default: '/q{separator}'\n }\n },\n setup(props) {\n const ls = new SecureLS({\n isCompression: false\n });\n\n let q = props.q;\n\n if (q) {\n let encoder = document.createElement('textarea');\n encoder.innerHTML = q;\n q = encoder.value;\n }\n\n const isLoading = ref(false);\n const term = ref(q);\n const results = ref([]);\n const byCategory = ref([]);\n const total = ref(0);\n const current = ref(-1);\n const isDropdown = ref(false);\n const input = ref();\n const separator = ref('');\n const dropdownContent = ref();\n const history = ref(ls.get('search'));\n const menu = ref([]);\n const store = useStore();\n const user = computed(() => store.getters['auth/me']);\n\n let refs = [];\n let timeout;\n\n const search = () => {\n clearTimeout(timeout);\n\n current.value = -1;\n\n if (!term.value.trim()) {\n results.value = [];\n isLoading.value = false;\n } else {\n isLoading.value = true;\n\n //timeout = setTimeout(() => {\n if (term.value.trim()) {\n api.search(term.value)\n .then((response) => {\n if (response.data) {\n saveSearch();\n\n results.value = response.data.products;\n total.value = response.data.total;\n separator.value = response.data.separator;\n byCategory.value = response.data.byCategory;\n\n const scrollBar = new SimpleBar(dropdownContent.value);\n }\n })\n .finally(() => {\n isLoading.value = false;\n });\n }\n //}, 500);\n }\n };\n\n const saveSearch = () => {\n if (term.value.length > 1) {\n let search = ls.get('search') ? ls.get('search') : [];\n\n if (search.indexOf(term.value) !== -1) {\n search = search.filter((item) => item !== term.value);\n }\n\n if (search.length > 4) {\n search = search.slice(0, 4);\n }\n\n search.unshift(term.value);\n\n ls.set('search', search);\n\n history.value = search;\n }\n };\n\n const setSearchHistory = (term) => {\n term.value = term;\n };\n\n const clearSearchHistory = (event) => {\n ls.remove('search');\n\n history.value = [];\n\n input.value.focus();\n };\n\n onBeforeUpdate(() => {\n refs = [];\n });\n\n watch(\n () => term.value,\n () => {\n isDropdown.value = true;\n current.value = -1;\n search();\n }\n );\n\n const searchUrl = computed(() => {\n return term.value ? $env.locale.url + '/search' + searchHrefWithParameter.value : $env.locale.url + '/search';\n });\n\n const searchHrefWithParameter = computed(() => {\n return props.parameter.replace('{separator}', separator.value) + term.value.toLowerCase();\n });\n\n const preventCaret = (event) => {\n if (event.which == 38 || event.which == 40 || (event.which == 32 && current.value >= 0)) {\n event.preventDefault();\n }\n };\n\n const next = () => {\n if (current.value < results.value.length - 1) {\n current.value++;\n }\n };\n\n const prev = () => {\n if (current.value >= 0) {\n current.value--;\n }\n };\n\n const add = (event) => {\n if (current.value >= 0) {\n event.preventDefault();\n\n refs[current.value].add();\n }\n };\n\n const open = () => {\n if (current.value >= 0) {\n window.location.href = results.value[current.value].href;\n } else {\n window.location.href = searchUrl.value;\n }\n };\n\n const esc = (event) => {\n input.value.blur();\n close(event);\n };\n\n const cartRefs = (el) => {\n if (el) {\n refs.push(el);\n }\n };\n\n const close = (event) => {\n if (!event.target.closest('.cart')) {\n isDropdown.value = false;\n current.value = -1;\n }\n };\n\n const dropdown = () => {\n isDropdown.value = true;\n current.value = -1;\n };\n\n window.addEventListener('click', close);\n\n const categories = computed(() => {\n return term.value.length > 3 ? menu.value.filter((item) => item.search.indexOf(term.value) !== -1) : [];\n });\n\n const load = async () => {\n const menuElement = document.getElementById('menu');\n\n if (menuElement) {\n menuElement.querySelectorAll('[data-search]').forEach((element) => {\n const name = element.textContent.trim();\n const data = element.dataset.search;\n\n menu.value.push({\n name: (data ? data + ' / ' : '') + name,\n search: name.toLowerCase(),\n href: element.closest('a').href\n });\n });\n }\n\n if (props.q) {\n search();\n }\n };\n\n document.addEventListener('DOMContentLoaded', load, false);\n\n return {\n isLoading,\n term,\n results,\n next,\n prev,\n current,\n add,\n cartRefs,\n isDropdown,\n preventCaret,\n esc,\n input,\n dropdown,\n total,\n searchUrl,\n searchHrefWithParameter,\n open,\n categories,\n byCategory,\n dropdownContent,\n history,\n clearSearchHistory,\n setSearchHistory,\n user\n };\n }\n});\n</script>","<template>\n <div class=\"shop-search\" @click=\"$event.stopPropagation()\">\n <div class=\"dropdown\" v-bind:class=\"{\n 'is-active': isDropdown,\n 'is-dropdown-visible': isDropdown && ((history.length && !term) || results.length || categories.length || (term && !isLoading && !results.length && !categories.length))\n }\">\n <div class=\"overlay search-overlay\" @click=\"esc($event)\"></div>\n <div class=\"dropdown-trigger\">\n <div class=\"control has-icons-right\" v-bind:class=\"{ 'is-loading': isLoading }\">\n <input class=\"input\" type=\"text\" v-model=\"term\" ref=\"input\" :placeholder=\"placeholder\" @keyup.arrow-down=\"next\" @keyup.arrow-up=\"prev\" @keyup.space=\"add($event)\" @keyup.enter=\"open\" @keyup.esc=\"esc($event)\" @click=\"dropdown\" @keydown=\"preventCaret($event)\" />\n <slot name=\"icon\" :isLoading=\"isLoading\">\n <span class=\"icon is-small is-right\" v-show=\"!isLoading\">\n <i class=\"fas fa-search\"></i>\n </span>\n </slot>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-if=\"isDropdown && history.length && !term\">\n <div class=\"dropdown-content\">\n <div class=\"history-list\">\n <div class=\"dropdown-item history-list-title\">\n <p>{{ __('shop.search.history') }}</p>\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in history\" v-bind:key=\"index\">\n <a @click=\"term = item\">{{ item }}</a>\n </div>\n <div class=\"dropdown-item history-list-clear\">\n <a @click=\"clearSearchHistory($event)\">{{ __('shop.search.history_clear') }}</a>\n </div>\n </div>\n </div>\n </div>\n <div class=\"dropdown-menu\" v-show=\"results.length || term\">\n <div class=\"dropdown-content\" v-show=\"results.length || categories.length\" style=\"max-height: 600px; overflow: auto\" ref=\"dropdownContent\">\n <div class=\"results-list\" v-if=\"categories.length\">\n <div class=\"dropdown-item\" v-for=\"(item, index) in categories\" v-bind:key=\"index\">\n <div>\n <a :href=\"item.href\">{{ item.name }}</a>\n </div>\n </div>\n <hr class=\"dropdown-divider\" v-if=\"byCategory.length\" />\n </div>\n <div class=\"results-list-category\" v-if=\"byCategory.length\">\n <div class=\"dropdown-item categories-list-title\">\n {{ __('shop.search.categories') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in byCategory\" v-bind:key=\"index\">\n <slot name=\"item-category\" :item=\"item\" :searchHrefWithParameter=\"searchHrefWithParameter\">\n <div>\n <a :href=\"item.href + searchHrefWithParameter\">{{ item.name }}</a>\n </div>\n <div>\n {{ __('shop.search.category_found', { count: item.count }) }}\n </div>\n </slot>\n </div>\n </div>\n <div class=\"results-list-total\" v-if=\"total\">\n <p class=\"dropdown-item mb-3 mt-2\">\n {{\n __('shop.search.total_found', {\n total: total\n })\n }}\n <br />\n <a :href=\"searchUrl\">{{ __('shop.search.open_results') }}</a>\n </p>\n </div>\n <div class=\"products-list\" v-if=\"results.length\">\n <div class=\"dropdown-item products-list-title\">\n {{ __('shop.search.products') }}\n </div>\n <div class=\"dropdown-item\" v-for=\"(item, index) in results\" v-bind:key=\"item.id\" v-bind:class=\"{ 'is-active': current == index }\">\n <slot name=\"item\" :user=\"user\" :item=\"item\" :cart-refs=\"cartRefs\">\n <div class=\"columns\">\n <div class=\"column\">\n <div class=\"title\">\n <a :href=\"item.href\">\n {{ item.name }}\n </a>\n </div>\n <div class=\"price\" v-html=\"item.price\"></div>\n <div class=\"price_old\" v-if=\"item.price_old\">\n <span v-html=\"item.price_old\"></span>\n </div>\n <div class=\"code\">{{ item.code }}</div>\n <div class=\"quantity\" v-if=\"item.quantity\">\n {{ __('shop.search.in_stock') }}\n </div>\n <span class=\"no-quantity\" v-else>\n {{ __('shop.search.out_stock') }}\n </span>\n </div>\n <div class=\"column is-narrow\" v-if=\"!item.is_eol\">\n <cart-add :id=\"item.id\" :is-change-quantity=\"false\" :is-already-in-cart=\"false\" :ref=\"cartRefs\"></cart-add>\n </div>\n <div v-else class=\"column is-eol\">\n {{ __('shop.search.eol') }}\n </div>\n </div>\n </slot>\n </div>\n </div>\n </div>\n <div class=\"dropdown-content\" v-if=\"!isLoading && !results.length && !categories.length\">\n <div class=\"dropdown-item\">\n <div class=\"no-results\">\n {{ __('shop.search.no_results') }}\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n</template>\n<script>\nimport { ref, watch, onBeforeUpdate, defineComponent, computed } from 'vue';\nimport { useStore } from 'vuex';\nimport { shop as api } from '@perevorot/shop/dist/api';\nimport SimpleBar from 'simplebar';\nimport SecureLS from 'secure-ls';\n\nexport default /*#__PURE__*/ defineComponent({\n name: 'search',\n props: {\n q: {\n type: String,\n default: ''\n },\n placeholder: {\n type: String,\n default: ''\n },\n parameter: {\n type: String,\n default: '/q{separator}'\n }\n },\n setup(props) {\n const ls = new SecureLS({\n isCompression: false\n });\n\n let q = props.q;\n\n if (q) {\n let encoder = document.createElement('textarea');\n encoder.innerHTML = q;\n q = encoder.value;\n }\n\n const isLoading = ref(false);\n const term = ref(q);\n const results = ref([]);\n const byCategory = ref([]);\n const total = ref(0);\n const current = ref(-1);\n const isDropdown = ref(false);\n const input = ref();\n const separator = ref('');\n const dropdownContent = ref();\n const history = ref(ls.get('search'));\n const menu = ref([]);\n const store = useStore();\n const user = computed(() => store.getters['auth/me']);\n\n let refs = [];\n let timeout;\n\n const search = () => {\n clearTimeout(timeout);\n\n current.value = -1;\n\n if (!term.value.trim()) {\n results.value = [];\n isLoading.value = false;\n } else {\n isLoading.value = true;\n\n //timeout = setTimeout(() => {\n if (term.value.trim()) {\n api.search(term.value)\n .then((response) => {\n if (response.data) {\n saveSearch();\n\n results.value = response.data.products;\n total.value = response.data.total;\n separator.value = response.data.separator;\n byCategory.value = response.data.byCategory;\n\n const scrollBar = new SimpleBar(dropdownContent.value);\n }\n })\n .finally(() => {\n isLoading.value = false;\n });\n }\n //}, 500);\n }\n };\n\n const saveSearch = () => {\n if (term.value.length > 1) {\n let search = ls.get('search') ? ls.get('search') : [];\n\n if (search.indexOf(term.value) !== -1) {\n search = search.filter((item) => item !== term.value);\n }\n\n if (search.length > 4) {\n search = search.slice(0, 4);\n }\n\n search.unshift(term.value);\n\n ls.set('search', search);\n\n history.value = search;\n }\n };\n\n const setSearchHistory = (term) => {\n term.value = term;\n };\n\n const clearSearchHistory = (event) => {\n ls.remove('search');\n\n history.value = [];\n\n input.value.focus();\n };\n\n onBeforeUpdate(() => {\n refs = [];\n });\n\n watch(\n () => term.value,\n () => {\n isDropdown.value = true;\n current.value = -1;\n search();\n }\n );\n\n const searchUrl = computed(() => {\n return term.value ? $env.locale.url + '/search' + searchHrefWithParameter.value : $env.locale.url + '/search';\n });\n\n const searchHrefWithParameter = computed(() => {\n return props.parameter.replace('{separator}', separator.value) + term.value.toLowerCase();\n });\n\n const preventCaret = (event) => {\n if (event.which == 38 || event.which == 40 || (event.which == 32 && current.value >= 0)) {\n event.preventDefault();\n }\n };\n\n const next = () => {\n if (current.value < results.value.length - 1) {\n current.value++;\n }\n };\n\n const prev = () => {\n if (current.value >= 0) {\n current.value--;\n }\n };\n\n const add = (event) => {\n if (current.value >= 0) {\n event.preventDefault();\n\n refs[current.value].add();\n }\n };\n\n const open = () => {\n if (current.value >= 0) {\n window.location.href = results.value[current.value].href;\n } else {\n window.location.href = searchUrl.value;\n }\n };\n\n const esc = (event) => {\n input.value.blur();\n close(event);\n };\n\n const cartRefs = (el) => {\n if (el) {\n refs.push(el);\n }\n };\n\n const close = (event) => {\n if (!event.target.closest('.cart')) {\n isDropdown.value = false;\n current.value = -1;\n }\n };\n\n const dropdown = () => {\n isDropdown.value = true;\n current.value = -1;\n };\n\n window.addEventListener('click', close);\n\n const categories = computed(() => {\n return term.value.length > 3 ? menu.value.filter((item) => item.search.indexOf(term.value) !== -1) : [];\n });\n\n const load = async () => {\n const menuElement = document.getElementById('menu');\n\n if (menuElement) {\n menuElement.querySelectorAll('[data-search]').forEach((element) => {\n const name = element.textContent.trim();\n const data = element.dataset.search;\n\n menu.value.push({\n name: (data ? data + ' / ' : '') + name,\n search: name.toLowerCase(),\n href: element.closest('a').href\n });\n });\n }\n\n if (props.q) {\n search();\n }\n };\n\n document.addEventListener('DOMContentLoaded', load, false);\n\n return {\n isLoading,\n term,\n results,\n next,\n prev,\n current,\n add,\n cartRefs,\n isDropdown,\n preventCaret,\n esc,\n input,\n dropdown,\n total,\n searchUrl,\n searchHrefWithParameter,\n open,\n categories,\n byCategory,\n dropdownContent,\n history,\n clearSearchHistory,\n setSearchHistory,\n user\n };\n }\n});\n</script>"],"names":["defineComponent","name","props","q","type","String","placeholder","parameter","setup","ls","SecureLS","isCompression","encoder","document","createElement","innerHTML","value","isLoading","ref","term","results","byCategory","total","current","isDropdown","input","separator","dropdownContent","history","get","menu","store","useStore","user","computed","getters","refs","search","clearTimeout","timeout","trim","api","then","response","data","saveSearch","products","SimpleBar","length","indexOf","filter","item","slice","unshift","set","onBeforeUpdate","watch","searchUrl","$env","locale","url","searchHrefWithParameter","replace","toLowerCase","close","event","target","closest","window","addEventListener","categories","load","menuElement","getElementById","querySelectorAll","forEach","element","textContent","dataset","push","href","resolve","arguments","i","next","prev","add","preventDefault","cartRefs","el","preventCaret","which","esc","blur","dropdown","open","location","clearSearchHistory","remove","focus","setSearchHistory","_createElementVNode","style","_createElementBlock","onClick","$event","stopPropagation","_ctx","_hoisted_1","onKeyup","onKeydown","_renderSlot","_hoisted_3","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","index","key","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_16","_hoisted_17","_hoisted_18","count","_hoisted_20","_hoisted_21","_hoisted_22","_hoisted_24","_hoisted_25","id","_hoisted_26","_hoisted_27","_hoisted_28","price","price_old","_hoisted_31","_hoisted_33","code","quantity","_hoisted_34","_hoisted_35","is_eol","_hoisted_37","_hoisted_36","_createVNode","_hoisted_38","_hoisted_39","_hoisted_40"],"mappings":"kOA0HA,MAA6BA,kBAAgB,CACzCC,KAAM,SACNC,MAAO,CACHC,EAAG,CACCC,KAAMC,eACG,IAEbC,YAAa,CACTF,KAAMC,eACG,IAEbE,UAAW,CACPH,KAAMC,eACG,kBAGjBG,eAAMN,OACIO,EAAK,IAAIC,UAAS,CACpBC,eAAe,IAGfR,EAAID,EAAMC,KAEVA,EAAG,KACCS,EAAUC,SAASC,cAAc,YACrCF,EAAQG,UAA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AKiF,KACzErB,8BAAmB9E,KAAM0E,OAAOxD,KAAMA,EAAOqC,SAAWmB,aAAxD,kBACIN,2BAAAgC,GACIhC,2BAAAiC,GACIjC,2BAAAkC,GACIlC,0BAAIrB,KAAM7B,EAAK6B,wBACR7B,EAAKlD,aAGhBoG,kCAAW,QAAQtF,UAAQoC,EAAKqF,iBACHrF,EAAKsF,yBAAlClC,2BAAAmC,GACIrC,6BAAMtF,UAAQoC,EAAKsF,wDAEvBpC,2BAAAsC,oBAAqBxF,EAAKyF,SACEzF,EAAK0F,wBAAjCtC,2BAAAuC,oBACOnC,iDAEPJ,4BAAAwC,oBACOpC,qCAG0BxD,EAAK6F,sBAG1CzC,2BAAA0C,oBACOtC,4CAJPJ,2BAAA2C,GACIC,iBAAWf,GAAIjF,EAAKiF,yBAAyB,wBAA4B,aAAQlH,IAAKyF,oGA7DxEA,UAAQ3D,QAAU2D,aAAW3D,UAuE9B2D,aAAcA,UAAQ3D,QAAW2D,aAAW3D,sDAAjFuD,2BAAA6C,GACI/C,2BAAAgD,GACIhD,2BAAAiD,oBACO3C,wDA3EgBA,UAAQ3D,QAAU2D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("vue"),t=require("vuex"),n=e.defineComponent({name:"cart-trigger",setup:function(){var n=t.useStore();return{quantity:e.computed((function(){return n.getters["cart/quantity"]})),open:function(){n.commit("cart/modal",!0)}}}}),
|
|
1
|
+
"use strict";var e=require("vue"),t=require("vuex"),n=e.defineComponent({name:"cart-trigger",setup:function(){var n=t.useStore();return{quantity:e.computed((function(){return n.getters["cart/quantity"]})),open:function(){n.commit("cart/modal",!0)},close:function(){n.commit("cart/modal",!1)}}}}),o={class:"cart"},r={class:"dropdown is-right is-hoverable"},a={class:"dropdown-trigger"},c=e.createElementVNode("svg",{width:"22",height:"19"},[e.createElementVNode("use",{"xlink:href":"#cart"})],-1),i=["textContent"];n.render=function(t,n,l,u,s,d){return e.openBlock(),e.createElementBlock("div",o,[e.createElementVNode("div",r,[e.createElementVNode("div",a,[e.renderSlot(t.$slots,"default",{total:t.quantity,open:t.open,close:t.close},(function(){return[e.createElementVNode("button",{class:e.normalizeClass(["button",{"is-products":t.quantity}]),onClick:n[0]||(n[0]=function(){return t.open&&t.open.apply(t,arguments)})},[c,e.createElementVNode("span",{textContent:e.toDisplayString(t.quantity)},null,8,i)],2)]}))])])])},module.exports=n;
|
|
2
2
|
//# sourceMappingURL=CartTrigger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CartTrigger.js","sources":["../../../../src/components/shop/cart/CartTrigger.vue","../../../../src/components/shop/cart/CartTrigger.vue?vue&type=template&id=
|
|
1
|
+
{"version":3,"file":"CartTrigger.js","sources":["../../../../src/components/shop/cart/CartTrigger.vue","../../../../src/components/shop/cart/CartTrigger.vue?vue&type=template&id=6815b67f&lang.js"],"sourcesContent":["<template>\n <div class=\"cart\">\n <div class=\"dropdown is-right is-hoverable\">\n <div class=\"dropdown-trigger\">\n <slot :total=\"quantity\" :open=\"open\" :close=\"close\">\n <button class=\"button\" @click=\"open\" v-bind:class=\"{ 'is-products': quantity }\">\n <svg width=\"22\" height=\"19\">\n <use xlink:href=\"#cart\" />\n </svg>\n <span v-text=\"quantity\"></span>\n </button>\n </slot>\n </div>\n </div>\n </div>\n</template>\n<script>\nimport { computed, defineComponent } from 'vue';\nimport { useStore } from 'vuex';\n\nexport default defineComponent({\n name: 'cart-trigger',\n setup() {\n const store = useStore();\n const quantity = computed(() => store.getters['cart/quantity']);\n\n const open = () => {\n store.commit('cart/modal', true);\n };\n\n const close = () => {\n store.commit('cart/modal', false);\n };\n\n return {\n quantity,\n open,\n close,\n };\n }\n});\n</script>\n","<template>\n <div class=\"cart\">\n <div class=\"dropdown is-right is-hoverable\">\n <div class=\"dropdown-trigger\">\n <slot :total=\"quantity\" :open=\"open\" :close=\"close\">\n <button class=\"button\" @click=\"open\" v-bind:class=\"{ 'is-products': quantity }\">\n <svg width=\"22\" height=\"19\">\n <use xlink:href=\"#cart\" />\n </svg>\n <span v-text=\"quantity\"></span>\n </button>\n </slot>\n </div>\n </div>\n </div>\n</template>\n<script>\nimport { computed, defineComponent } from 'vue';\nimport { useStore } from 'vuex';\n\nexport default defineComponent({\n name: 'cart-trigger',\n setup() {\n const store = useStore();\n const quantity = computed(() => store.getters['cart/quantity']);\n\n const open = () => {\n store.commit('cart/modal', true);\n };\n\n const close = () => {\n store.commit('cart/modal', false);\n };\n\n return {\n quantity,\n open,\n close,\n };\n }\n});\n</script>\n"],"names":["defineComponent","name","setup","store","useStore","quantity","computed","getters","open","commit","close","_createElementVNode","width","height","_createElementBlock","_hoisted_1","_hoisted_2","_hoisted_3","_renderSlot","total","_ctx","onClick","_hoisted_4","_toDisplayString"],"mappings":"sDAoBeA,kBAAgB,CAC3BC,KAAM,eACNC,qBACUC,EAAQC,mBAWP,CACHC,SAXaC,YAAS,kBAAMH,EAAMI,QAAQ,oBAY1CC,KAVS,WACTL,EAAMM,OAAO,cAAc,IAU3BC,MAPU,WACVP,EAAMM,OAAO,cAAc,iBC9BxB,iBACI,2CACI,sBAGCE,4BAAKC,MAAM,KAAKC,OAAO,OACnBF,yCAAgB,qFANxCG,2BAAAC,GACIJ,2BAAAK,GACIL,2BAAAM,GACIC,iCAAOC,MAAOC,WAAWZ,KAAMY,OAAOV,MAAOU,UAA7C,kBACIT,uDAAc,wBAAsDS,cAA5CC,sCAAOD,sCAC3BE,EAGAX,yCAAMY,kBAAQH"}
|