1import{At as e,C as t,D as a,Ft as n,Gt as s,It as l,J as i,Lt as o,R as c,St as u,ct as r,gt as d,it as p,pn as m,tt as f}from"./B8XHxhss.js";import{vt as h}from"#entry";var v=(t,a={})=>{a={clone:!1,populate:!1,enrichMagicKeys:!1,setDefaultValues:!0,includeList:[],excludeList:[],fetchOptions:{dataAppendage:{},includeList:[],excludeList:[],useNativeFormDataOnPost:!1},...a||{}},(t=a.clone?JSON.parse(JSON.stringify(t||{})):{...t||{}}).title=t.title??"",t.method=t.method??"GET",t.endpointUrl=t.endpointUrl??"",t.fields=t.fields??[],t.labels=t.labels??{},y(t?.fields,a);const s={dataAppendage:{},includeList:[],excludeList:[],useNativeFormDataOnPost:!1,...a.fetchOptions||{}},i=o(t.endpointUrl);if(t={...t,get endpointUrl(){let e=i.value,t={};return a?.enrichMagicKeys&&"object"==typeof a.enrichMagicKeys&&(t=a.enrichMagicKeys,e&&Object.keys(t).forEach(a=>{e=e.replaceAll(`{${a}}`,t[a])})),e},set endpointUrl(e){i.value=e},get fieldByName(){return this.fields?.reduce((e,t)=>(e[t.name]=t,e),{})??{}},get fieldsByName(){return this.fields?.reduce((e,t)=>(e[t.name]=e[t.name]??[],e[t.name].push(t),e),{})??{}},get fieldByType(){return this.fields?.reduce((e,t)=>(e[t.type]=t,e),{})??{}},get fieldsByType(){return this.fields?.reduce((e,t)=>(e[t.type]=e[t.type]??[],e[t.type].push(t),e),{})??{}},async fetch(e=s){e={...s,...e||{}};const t={...e};delete t.dataAppendage,delete t.includeList,delete t.excludeList,delete t.useNativeFormDataOnPost;const a=new FormData;try{if(this.fields.filter(t=>t&&!e.excludeList?.includes?.(t.name)&&!["button","submit"].includes(t.type)).forEach(e=>{e.name&&a.set(e.name,e.value)}),e.includeList?.length)for(const[t]of a.entries())e.includeList?.includes?.(t)||a.delete(t);for(const t in e.dataAppendage)e.excludeList?.includes?.(t)||a.set(t,e.dataAppendage[t]);const n=e.useNativeFormDataOnPost&&["POST","PUT","PATCH"].includes(this.method?.toUpperCase?.())?a:Object.fromEntries(a.entries());if(["GET","DELETE"].includes(this.method?.toUpperCase?.())||!this.method){const e=new URL(this.endpointUrl,"https://example.com");return e.search=new URLSearchParams(n).toString(),await h(e.toString().startsWith("https://example.com")?e.toString().replace("https://example.com",""):e.toString(),{method:this.method||"GET",...t}).then(e=>e).finally(()=>{a.forEach((e,t)=>a.delete(t))})}return await h(this.endpointUrl,{method:this.method,body:n,...t}).then(e=>e).finally(()=>{a instanceof FormData&&a.forEach((e,t)=>a.delete(t))})}catch(n){throw a.forEach((e,t)=>a.delete(t)),n}}},a.includeList?.length)for(const e in t)a.includeList.includes(e)||delete t[e];a.excludeList?.forEach(e=>{delete t[e]});const c=l({});t.fields?.forEach(e=>{e.name&&(c[e.name]=e.value)}),Object.defineProperty(t,"fieldValues",{get(){return this.fields?.forEach(e=>{e.name&&(c[e.name]=e.value)}),c},set(e){"object"==typeof e&&null!==e&&this.fields?.forEach(t=>{t.name&&t.name in e&&(t.value=e[t.name],c[t.name]=e[t.name],t.items&&t.items.forEach(a=>{a.checked=a.value===e[t.name]||e[t.name]?.split(",").includes?.(a.value)}))})},enumerable:!0,configurable:!0});const r=u(c,e=>{t.fieldValues=e});return e()&&n(()=>{r()},!0),t};function y(e,t){let a={};t?.populate&&"object"==typeof t.populate&&(a=t.populate);let n={};t?.enrichMagicKeys&&"object"==typeof t.enrichMagicKeys&&(n=t.enrichMagicKeys),e?.forEach((e,s,l)=>{if(t?.setDefaultValues&&!("defaultValue"in e)&&(e.defaultValue="value"in e?e.value:e.items?.filter(e=>e.checked)?.map?.(e=>e.value)?.join?.(",")??e.items?.find(e=>!e.value)?.value),"checked"in e&&!("defaultChecked"in e)&&(e.defaultChecked=e.checked),!("value"in e)&&(e.value=e.defaultValue,e.items?.length)){const t=e.items.reduce((e,t)=>(t.checked&&e.push(t.value),e),[]);e.value=t.length?t.join(","):e.defaultValue}if(t?.populate&&Object.keys(a).length>0)for(const t in a)e?.name===t&&("checked"in e?"boolean"==typeof a[t]?e.checked=a[t]:e.value===a[t]?e.checked=!0:e.checked=!1:(e.value=a[t],e.items&&e.items.forEach(e=>{e.checked=e.value===a[t]})));if(t?.enrichMagicKeys&&Object.keys(n).length>0)for(const t in n)e?.value===`{${t}}`?(e.value=n[t],e.items&&e.items.forEach(a=>{a.checked=a.value===e.value[t]})):e?.value?.includes?.(`{${t}}`)&&(e.value=e.value.replaceAll(`{${t}}
1`,n[t]),e.items&&e.items.forEach(a=>{a.checked=a.value===e.value[t]}));"fields"in e&&y(e.fields,t)})}var g=["onsubmit","action","enctype","method"],b=Object.assign({inheritAttrs:!1},{__name:"FetchForm",props:{action:String,enctype:{type:String,default:"application/x-www-form-urlencoded"},method:String,options:{type:Object,default:()=>({})},dataAppendage:{type:Object,default:()=>({})},dataTransformation:{type:Function,default:e=>e},useNativeFormDataOnPost:Boolean,mockupResponse:null,disabled:Boolean},emits:["fetch","request","response","error","complete"],setup(e,{expose:n,emit:l}){const u=d(),v=e,y=l,b=o(null),E=o(!1),k=t(()=>(v.method||"GET").toUpperCase()),L=t(()=>({method:k.value,...v.options,onRequest:(...e)=>{v.options?.onRequest?.(...e),y("request",...e)}})),O=o(0),D=t(()=>O.value>0),S=o(null),T=o(null),j=t(()=>{const e={...u};return delete e.onSubmit,e});async function P(e){v.disabled?e.preventDefault():(u.onSubmit?.(e),e.defaultPrevented||"DIALOG"===v.method?.toUpperCase?.()||(e.preventDefault(),await U()))}async function U(e){e??={},e={...v,...e};const t=o({key:String(Math.random()),...L.value,...e.options,onRequest:(...t)=>{e.options?.onRequest?.(...t),y("request",...t)}});if(e.action){const a=new URL(e.action,"https://example.com");let n=b.value?.formData?b.value.formData():new FormData(b.value),s="https://example.com"===a.origin?"":a.origin,l=n;if(e.dataAppendage)for(const[t,c]of Object.entries(e.dataAppendage))l.set(t,c);e.dataTransformation&&(l=e.dataTransformation(l)),e.useNativeFormDataOnPost||(l=Object.fromEntries(l)),["GET","DELETE"].includes(k.value)&&(a.search=new URLSearchParams(l));let i=!0;if(O.value++,e.mockupResponse){const t="function"==typeof e.mockupResponse?e.mockupResponse?.(l):e.mockupResponse;return y("fetch",new Promise(a=>{y("response",t),y("complete",!0),a({meta:{code:200},data:t,error:null}),S.value=e.mockupResponse,T.value=null,O.value--})),t}const o=h(s+a.pathname+a.search,{body:["POST","PUT","PATCH"].includes(k.value)?l:void 0,...t.value}).then(e=>{y("response",e),S.value=e,T.value=null}).catch(e=>{y("error",e),i=!1,S.value=null,T.value=e}).finally(()=>{O.value--,y("complete",i)});return y("fetch",o),await o,S.value}}return f(()=>{E.value=!0}),n({isFetching:D.value,submit:U}),(t,n)=>(p(),a("form",i({ref_key:"$el",ref:b,onsubmit:s(E)?null:"return false;",action:e.action,enctype:e.enctype,method:s(k),class:"c-fetch-form"},s(j),{onSubmit:P}),[r(t.$slots,"default",m(c({isFetching:s(D),currentResponse:s(S),currentError:s(T)})))],16,g))}});export{v as n,b as t};
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.