mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-12 19:21:47 +00:00
2 lines
2.4 KiB
JavaScript
2 lines
2.4 KiB
JavaScript
import{d as g,ay as C,I as S,m as b,$ as N,at as _,s as m,az as $,a0 as k,N as A}from"./Bn13st12.js";const O=g({name:"ContentQuery",props:{path:{type:String,required:!1,default:void 0},only:{type:Array,required:!1,default:void 0},without:{type:Array,required:!1,default:void 0},where:{type:Object,required:!1,default:void 0},sort:{type:Object,required:!1,default:void 0},limit:{type:Number,required:!1,default:void 0},skip:{type:Number,required:!1,default:void 0},locale:{type:String,required:!1,default:void 0},find:{type:String,required:!1,default:void 0}},async setup(i){const{path:t,only:r,without:o,where:u,sort:l,limit:d,skip:f,locale:s,find:y}=C(i),p=S(()=>{var e;return(e=t.value)==null?void 0:e.includes("/_")}),h=!b().public.content.experimental.advanceQuery;N(()=>i,()=>n(),{deep:!0});const a=e=>h?e!=null&&e.surround?e.surround:e!=null&&e._id||Array.isArray(e)?e:e==null?void 0:e.result:e.result,{data:v,refresh:n}=await _(`content-query-${$(i)}`,()=>{let e;return t.value?e=m(t.value):e=m(),r.value&&(e=e.only(r.value)),o.value&&(e=e.without(o.value)),u.value&&(e=e.where(u.value)),l.value&&(e=e.sort(l.value)),d.value&&(e=e.limit(d.value)),f.value&&(e=e.skip(f.value)),s.value&&(e=e.where({_locale:s.value})),y.value==="one"?e.findOne().then(a):y.value==="surround"?t.value?h?e.findSurround(t.value):e.withSurround(t.value).findOne().then(a):(console.warn("[Content] Surround queries requires `path` prop to be set."),console.warn("[Content] Query without `path` will return regular `find()` results."),e.find().then(a)):e.find().then(a)});return{isPartial:p,data:v,refresh:n}},render(i){var c;const t=k(),{data:r,refresh:o,isPartial:u,path:l,only:d,without:f,where:s,sort:y,limit:p,skip:h,locale:a,find:v}=i,n={path:l,only:d,without:f,where:s,sort:y,limit:p,skip:h,locale:a,find:v};if(n.find==="one"){if(!r&&(t!=null&&t["not-found"]))return t["not-found"]({props:n,...this.$attrs});if(t!=null&&t.empty&&(r==null?void 0:r._type)==="markdown"&&!((c=r==null?void 0:r.body)!=null&&c.children.length))return t.empty({props:n,...this.$attrs})}else if((!r||!r.length)&&t!=null&&t["not-found"])return t["not-found"]({props:n,...this.$attrs});return t!=null&&t.default?t.default({data:r,refresh:o,isPartial:u,props:n,...this.$attrs}):((w,q)=>A("pre",null,JSON.stringify({message:"You should use slots with <ContentQuery>!",slot:w,data:q},null,2)))("default",{data:r,props:n,isPartial:u})}}),R=O;export{R as default};
|