@citruslime/vue-utils 1.2.1-beta.0 → 1.2.2-beta.0

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,12 +1,12 @@
1
- import { replacePlaceholders as te } from "@citruslime/utils";
2
- import { computed as ce, ref as D, readonly as ye, unref as he, getCurrentScope as me, onScopeDispose as Oe, watch as G, isRef as fe, shallowRef as M, reactive as ve, toRefs as we } from "vue";
1
+ import { replacePlaceholders as Z } from "@citruslime/utils";
2
+ import { computed as ce, ref as D, readonly as ye, unref as he, getCurrentScope as me, onScopeDispose as Oe, watch as G, isRef as fe, shallowRef as L, reactive as ve, toRefs as we } from "vue";
3
3
  const Je = [
4
4
  "GET",
5
5
  "POST",
6
6
  "PUT",
7
7
  "DELETE"
8
8
  ];
9
- function Ke(e, t, n = null, s = null) {
9
+ function Me(e, t, n = null, s = null) {
10
10
  return {
11
11
  url: e,
12
12
  type: t,
@@ -23,13 +23,13 @@ function de() {
23
23
  function ge(e, t) {
24
24
  return !!(t === null && (e === "PUT" || e === "POST") || t);
25
25
  }
26
- var ne;
27
- const X = typeof window < "u";
28
- X && ((ne = window == null ? void 0 : window.navigator) != null && ne.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
26
+ var ee;
27
+ const z = typeof window < "u";
28
+ z && ((ee = window == null ? void 0 : window.navigator) != null && ee.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
29
29
  function E(e) {
30
30
  return typeof e == "function" ? e() : he(e);
31
31
  }
32
- function re(e, t = !1, n = "Timeout") {
32
+ function te(e, t = !1, n = "Timeout") {
33
33
  return new Promise((s, a) => {
34
34
  setTimeout(t ? () => a(n) : s, e);
35
35
  });
@@ -77,7 +77,7 @@ function q(e, t = !1) {
77
77
  immediate: !0
78
78
  });
79
79
  })];
80
- return d != null && N.push(re(d, F).then(() => E(e)).finally(() => p == null ? void 0 : p())), Promise.race(N);
80
+ return d != null && N.push(te(d, F).then(() => E(e)).finally(() => p == null ? void 0 : p())), Promise.race(N);
81
81
  }
82
82
  function s(i, u) {
83
83
  if (!fe(i))
@@ -93,10 +93,10 @@ function q(e, t = !1) {
93
93
  immediate: !0
94
94
  });
95
95
  })];
96
- return F != null && I.push(re(F, p).then(() => E(e)).finally(() => (v == null || v(), E(e)))), Promise.race(I);
96
+ return F != null && I.push(te(F, p).then(() => E(e)).finally(() => (v == null || v(), E(e)))), Promise.race(I);
97
97
  }
98
98
  function a(i) {
99
- return n((u) => Boolean(u), i);
99
+ return n((u) => !!u, i);
100
100
  }
101
101
  function r(i) {
102
102
  return s(null, i);
@@ -161,15 +161,14 @@ function _e(e, t, n = {}) {
161
161
  a.value = !1, r = null, e(...O);
162
162
  }, E(t));
163
163
  }
164
- return s && (a.value = !0, X && y()), pe(g), {
164
+ return s && (a.value = !0, z && y()), pe(g), {
165
165
  isPending: ye(a),
166
166
  start: y,
167
167
  stop: g
168
168
  };
169
169
  }
170
- const Ee = X ? window : void 0, z = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, R = "__vueuse_ssr_handlers__";
171
- z[R] = z[R] || {};
172
- z[R];
170
+ const Ee = z ? window : void 0, ne = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, re = "__vueuse_ssr_handlers__";
171
+ ne[re] = ne[re] || {};
173
172
  var Fe = Object.defineProperty, Ie = Object.defineProperties, je = Object.getOwnPropertyDescriptors, oe = Object.getOwnPropertySymbols, Ne = Object.prototype.hasOwnProperty, Se = Object.prototype.propertyIsEnumerable, ae = (e, t, n) => t in e ? Fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, f = (e, t) => {
174
173
  for (var n in t || (t = {}))
175
174
  Ne.call(t, n) && ae(e, n, t[n]);
@@ -202,17 +201,17 @@ function Ce(e, ...t) {
202
201
  fetch: g = (n = Ee) == null ? void 0 : n.fetch,
203
202
  initialData: y,
204
203
  timeout: O
205
- } = r, b = W(), i = W(), u = W(), h = D(!1), d = D(!1), F = D(!1), p = D(null), v = M(null), N = M(null), I = M(y), j = ce(() => s && d.value);
204
+ } = r, b = W(), i = W(), u = W(), h = D(!1), d = D(!1), F = D(!1), p = D(null), v = L(null), N = L(null), I = L(y), j = ce(() => s && d.value);
206
205
  let P, S;
207
206
  const J = () => {
208
207
  s && P && (P.abort(), P = void 0);
209
- }, K = (l) => {
208
+ }, M = (l) => {
210
209
  d.value = l, h.value = !l;
211
210
  };
212
211
  O && (S = _e(J, O, { immediate: !1 }));
213
212
  const $ = async (l = !1) => {
214
213
  var w;
215
- K(!0), N.value = null, p.value = null, F.value = !1, s && (J(), P = new AbortController(), P.signal.onabort = () => F.value = !0, a = H(f({}, a), {
214
+ M(!0), N.value = null, p.value = null, F.value = !1, s && (J(), P = new AbortController(), P.signal.onabort = () => F.value = !0, a = H(f({}, a), {
216
215
  signal: P.signal
217
216
  }));
218
217
  const m = {
@@ -234,26 +233,26 @@ function Ce(e, ...t) {
234
233
  }
235
234
  };
236
235
  if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)), C || !g)
237
- return K(!1), Promise.resolve(null);
236
+ return M(!1), Promise.resolve(null);
238
237
  let _ = null;
239
238
  return S && S.start(), new Promise((Q, U) => {
240
- var Z;
239
+ var X;
241
240
  g(T.url, H(f(f({}, m), T.options), {
242
- headers: f(f({}, k(m.headers)), k((Z = T.options) == null ? void 0 : Z.headers))
241
+ headers: f(f({}, k(m.headers)), k((X = T.options) == null ? void 0 : X.headers))
243
242
  })).then(async (c) => {
244
243
  if (v.value = c, p.value = c.status, _ = await c[o.type](), r.afterFetch && p.value >= 200 && p.value < 300 && ({ data: _ } = await r.afterFetch({ data: _, response: c })), I.value = _, !c.ok)
245
244
  throw new Error(c.statusText);
246
245
  return b.trigger(c), Q(c);
247
246
  }).catch(async (c) => {
248
- let ee = c.message || c.name;
249
- return r.onFetchError && ({ data: _, error: ee } = await r.onFetchError({ data: _, error: c, response: v.value })), I.value = _, N.value = ee, i.trigger(c), l ? U(c) : Q(null);
247
+ let Y = c.message || c.name;
248
+ return r.onFetchError && ({ data: _, error: Y } = await r.onFetchError({ data: _, error: c, response: v.value })), I.value = _, N.value = Y, i.trigger(c), l ? U(c) : Q(null);
250
249
  }).finally(() => {
251
- K(!1), S && S.stop(), u.trigger(null);
250
+ M(!1), S && S.stop(), u.trigger(null);
252
251
  });
253
252
  });
254
- }, Y = V(r.refetch);
253
+ }, R = V(r.refetch);
255
254
  G([
256
- Y,
255
+ R,
257
256
  V(e)
258
257
  ], ([l]) => l && $(), { deep: !0 });
259
258
  const x = {
@@ -287,19 +286,19 @@ function Ce(e, ...t) {
287
286
  return (w, m) => {
288
287
  if (!d.value) {
289
288
  o.method = l, o.payload = w, o.payloadType = m, fe(o.payload) && G([
290
- Y,
289
+ R,
291
290
  V(o.payload)
292
291
  ], ([T]) => T && $(), { deep: !0 });
293
292
  const C = E(o.payload);
294
293
  return !m && C && Object.getPrototypeOf(C) === Object.prototype && !(C instanceof FormData) && (o.payloadType = "json"), H(f({}, x), {
295
294
  then(T, _) {
296
- return L().then(T, _);
295
+ return K().then(T, _);
297
296
  }
298
297
  });
299
298
  }
300
299
  };
301
300
  }
302
- function L() {
301
+ function K() {
303
302
  return new Promise((l, w) => {
304
303
  Te(h).toBe(!0).then(() => l(x)).catch((m) => w(m));
305
304
  });
@@ -309,14 +308,14 @@ function Ce(e, ...t) {
309
308
  if (!d.value)
310
309
  return o.type = l, H(f({}, x), {
311
310
  then(w, m) {
312
- return L().then(w, m);
311
+ return K().then(w, m);
313
312
  }
314
313
  });
315
314
  };
316
315
  }
317
316
  return r.immediate && setTimeout($, 0), H(f({}, x), {
318
317
  then(l, w) {
319
- return L().then(l, w);
318
+ return K().then(l, w);
320
319
  }
321
320
  });
322
321
  }
@@ -361,13 +360,13 @@ const xe = {
361
360
  $e({
362
361
  linear: be
363
362
  }, xe);
364
- function Le(e, t) {
363
+ function Ke(e, t) {
365
364
  const n = {};
366
365
  return Object.keys(e).forEach((a) => {
367
366
  n[a] = (...r) => {
368
367
  const o = e[a], g = o.type;
369
368
  let y = `/api/${o.url}`;
370
- o.hasBody ? y = te(y, ...r.splice(1)) : y = te(y, ...r);
369
+ o.hasBody ? y = Z(y, ...r.splice(1)) : y = Z(y, ...r);
371
370
  const O = {
372
371
  ...de(),
373
372
  ...o.headers()
@@ -400,7 +399,7 @@ function Le(e, t) {
400
399
  function Qe(e) {
401
400
  return e.accept ?? "*/*";
402
401
  }
403
- function Me(e) {
402
+ function Le(e) {
404
403
  return JSON.parse(JSON.stringify(e));
405
404
  }
406
405
  function We(e = 500) {
@@ -417,10 +416,10 @@ function We(e = 500) {
417
416
  };
418
417
  }
419
418
  export {
420
- Me as copy,
421
- Ke as createEndpoint,
419
+ Le as copy,
420
+ Me as createEndpoint,
422
421
  de as getDefaultHeaders,
423
422
  Je as requestTypes,
424
- Le as useApi,
423
+ Ke as useApi,
425
424
  We as useDebouncer
426
425
  };
@@ -1 +1 @@
1
- (function(p,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@citruslime/utils"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@citruslime/utils","vue"],A):(p=typeof globalThis<"u"?globalThis:p||self,A(p.CitrusLimeVueUtils={},p.CLUtils,p.Vue))})(this,function(p,A,u){"use strict";const fe=["GET","POST","PUT","DELETE"];function de(e,t,n=null,l=null){return{url:e,type:t,headers:n??q,hasBody:pe(t,l)}}function q(){return{accept:"application/json","content-type":"application/json"}}function pe(e,t){return!!(t===null&&(e==="PUT"||e==="POST")||t)}var Z;const J=typeof window<"u";J&&((Z=window==null?void 0:window.navigator)!=null&&Z.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent);function T(e){return typeof e=="function"?e():u.unref(e)}function ee(e,t=!1,n="Timeout"){return new Promise((l,a)=>{setTimeout(t?()=>a(n):l,e)})}function he(e){return e}function ye(e,...t){return t.some(n=>n in e)}function te(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}function M(){const e=[],t=a=>{const r=e.indexOf(a);r!==-1&&e.splice(r,1)};return{on:a=>{e.push(a);const r=()=>t(a);return te(r),{off:r}},off:t,trigger:a=>{e.forEach(r=>r(a))}}}function V(e){return typeof e=="function"?u.computed(e):u.ref(e)}function K(e,t=!1){function n(i,{flush:s="sync",deep:O=!1,timeout:h,throwOnTimeout:I}={}){let y=null;const D=[new Promise(S=>{y=u.watch(e,C=>{i(C)!==t&&(y==null||y(),S(C))},{flush:s,deep:O,immediate:!0})})];return h!=null&&D.push(ee(h,I).then(()=>T(e)).finally(()=>y==null?void 0:y())),Promise.race(D)}function l(i,s){if(!u.isRef(i))return n(C=>C===i,s);const{flush:O="sync",deep:h=!1,timeout:I,throwOnTimeout:y}=s??{};let b=null;const S=[new Promise(C=>{b=u.watch([e,i],([E,N])=>{t!==(E===N)&&(b==null||b(),C(E))},{flush:O,deep:h,immediate:!0})})];return I!=null&&S.push(ee(I,y).then(()=>T(e)).finally(()=>(b==null||b(),T(e)))),Promise.race(S)}function a(i){return n(s=>Boolean(s),i)}function r(i){return l(null,i)}function o(i){return l(void 0,i)}function _(i){return n(Number.isNaN,i)}function m(i,s){return n(O=>{const h=Array.from(O);return h.includes(i)||h.includes(T(i))},s)}function g(i){return v(1,i)}function v(i=1,s){let O=-1;return n(()=>(O+=1,O>=i),s)}return Array.isArray(T(e))?{toMatch:n,toContains:m,changed:g,changedTimes:v,get not(){return K(e,!t)}}:{toMatch:n,toBe:l,toBeTruthy:a,toBeNull:r,toBeNaN:_,toBeUndefined:o,changed:g,changedTimes:v,get not(){return K(e,!t)}}}function me(e){return K(e)}function Oe(e,t,n={}){const{immediate:l=!0}=n,a=u.ref(!1);let r=null;function o(){r&&(clearTimeout(r),r=null)}function _(){a.value=!1,o()}function m(...g){o(),a.value=!0,r=setTimeout(()=>{a.value=!1,r=null,e(...g)},T(t))}return l&&(a.value=!0,J&&m()),te(_),{isPending:u.readonly(a),start:m,stop:_}}const we=J?window:void 0,R=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},W="__vueuse_ssr_handlers__";R[W]=R[W]||{},R[W];var ge=Object.defineProperty,be=Object.defineProperties,Pe=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,Te=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,re=(e,t,n)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))Te.call(t,n)&&re(e,n,t[n]);if(ne)for(var n of ne(t))_e.call(t,n)&&re(e,n,t[n]);return e},U=(e,t)=>be(e,Pe(t));const ve={json:"application/json",text:"text/plain"};function oe(e){return e&&ye(e,"immediate","refetch","initialData","timeout","beforeFetch","afterFetch","onFetchError","fetch")}function k(e){return typeof Headers<"u"&&e instanceof Headers?Object.fromEntries([...e.entries()]):e}function Ee(e,...t){var n;const l=typeof AbortController=="function";let a={},r={immediate:!0,refetch:!1,timeout:0};const o={method:"GET",type:"text",payload:void 0};t.length>0&&(oe(t[0])?r=c(c({},r),t[0]):a=t[0]),t.length>1&&oe(t[1])&&(r=c(c({},r),t[1]));const{fetch:_=(n=we)==null?void 0:n.fetch,initialData:m,timeout:g}=r,v=M(),i=M(),s=M(),O=u.ref(!1),h=u.ref(!1),I=u.ref(!1),y=u.ref(null),b=u.shallowRef(null),D=u.shallowRef(null),S=u.shallowRef(m),C=u.computed(()=>l&&h.value);let E,N;const z=()=>{l&&E&&(E.abort(),E=void 0)},X=f=>{h.value=f,O.value=!f};g&&(N=Oe(z,g,{immediate:!1}));const Q=async(f=!1)=>{var P;X(!0),D.value=null,y.value=null,I.value=!1,l&&(z(),E=new AbortController,E.signal.onabort=()=>I.value=!0,a=U(c({},a),{signal:E.signal}));const w={method:o.method,headers:{}};if(o.payload){const G=k(w.headers);o.payloadType&&(G["Content-Type"]=(P=ve[o.payloadType])!=null?P:o.payloadType);const L=T(o.payload);w.body=o.payloadType==="json"?JSON.stringify(L):L}let H=!1;const F={url:T(e),options:c(c({},w),a),cancel:()=>{H=!0}};if(r.beforeFetch&&Object.assign(F,await r.beforeFetch(F)),H||!_)return X(!1),Promise.resolve(null);let j=null;return N&&N.start(),new Promise((G,L)=>{var le;_(F.url,U(c(c({},w),F.options),{headers:c(c({},k(w.headers)),k((le=F.options)==null?void 0:le.headers))})).then(async d=>{if(b.value=d,y.value=d.status,j=await d[o.type](),r.afterFetch&&y.value>=200&&y.value<300&&({data:j}=await r.afterFetch({data:j,response:d})),S.value=j,!d.ok)throw new Error(d.statusText);return v.trigger(d),G(d)}).catch(async d=>{let ce=d.message||d.name;return r.onFetchError&&({data:j,error:ce}=await r.onFetchError({data:j,error:d,response:b.value})),S.value=j,D.value=ce,i.trigger(d),f?L(d):G(null)}).finally(()=>{X(!1),N&&N.stop(),s.trigger(null)})})},ue=V(r.refetch);u.watch([ue,V(e)],([f])=>f&&Q(),{deep:!0});const x={isFinished:O,statusCode:y,response:b,error:D,data:S,isFetching:h,canAbort:C,aborted:I,abort:z,execute:Q,onFetchResponse:v.on,onFetchError:i.on,onFetchFinally:s.on,get:B("GET"),put:B("PUT"),post:B("POST"),delete:B("DELETE"),patch:B("PATCH"),head:B("HEAD"),options:B("OPTIONS"),json:$("json"),text:$("text"),blob:$("blob"),arrayBuffer:$("arrayBuffer"),formData:$("formData")};function B(f){return(P,w)=>{if(!h.value){o.method=f,o.payload=P,o.payloadType=w,u.isRef(o.payload)&&u.watch([ue,V(o.payload)],([F])=>F&&Q(),{deep:!0});const H=T(o.payload);return!w&&H&&Object.getPrototypeOf(H)===Object.prototype&&!(H instanceof FormData)&&(o.payloadType="json"),U(c({},x),{then(F,j){return Y().then(F,j)}})}}}function Y(){return new Promise((f,P)=>{me(O).toBe(!0).then(()=>f(x)).catch(w=>P(w))})}function $(f){return()=>{if(!h.value)return o.type=f,U(c({},x),{then(P,w){return Y().then(P,w)}})}}return r.immediate&&setTimeout(Q,0),U(c({},x),{then(f,P){return Y().then(f,P)}})}var ae;(function(e){e.UP="UP",e.RIGHT="RIGHT",e.DOWN="DOWN",e.LEFT="LEFT",e.NONE="NONE"})(ae||(ae={}));var Fe=Object.defineProperty,ie=Object.getOwnPropertySymbols,je=Object.prototype.hasOwnProperty,Ie=Object.prototype.propertyIsEnumerable,se=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))je.call(t,n)&&se(e,n,t[n]);if(ie)for(var n of ie(t))Ie.call(t,n)&&se(e,n,t[n]);return e};Se({linear:he},{easeInSine:[.12,0,.39,0],easeOutSine:[.61,1,.88,1],easeInOutSine:[.37,0,.63,1],easeInQuad:[.11,0,.5,0],easeOutQuad:[.5,1,.89,1],easeInOutQuad:[.45,0,.55,1],easeInCubic:[.32,0,.67,0],easeOutCubic:[.33,1,.68,1],easeInOutCubic:[.65,0,.35,1],easeInQuart:[.5,0,.75,0],easeOutQuart:[.25,1,.5,1],easeInOutQuart:[.76,0,.24,1],easeInQuint:[.64,0,.78,0],easeOutQuint:[.22,1,.36,1],easeInOutQuint:[.83,0,.17,1],easeInExpo:[.7,0,.84,0],easeOutExpo:[.16,1,.3,1],easeInOutExpo:[.87,0,.13,1],easeInCirc:[.55,0,1,.45],easeOutCirc:[0,.55,.45,1],easeInOutCirc:[.85,0,.15,1],easeInBack:[.36,0,.66,-.56],easeOutBack:[.34,1.56,.64,1],easeInOutBack:[.68,-.6,.32,1.6]});function Ce(e,t){const n={};return Object.keys(e).forEach(a=>{n[a]=(...r)=>{const o=e[a],_=o.type;let m=`/api/${o.url}`;o.hasBody?m=A.replacePlaceholders(m,...r.splice(1)):m=A.replacePlaceholders(m,...r);const g={...q(),...o.headers()},v=Ee(m,{method:_},{immediate:!1,beforeFetch({options:s}){return s.headers={...s.headers,...g},o.hasBody&&r.length&&(s.body=JSON.stringify(r[0])),{options:s}},onFetchError(s){return s!=null&&s.response&&t(s),s}});return{...De(g)==="application/json"?v.json():v.text()}}}),n}function De(e){return e.accept??"*/*"}function Ne(e){return JSON.parse(JSON.stringify(e))}function Be(e=500){const t=u.reactive({debouncer:null,timeout:e});function n(l,...a){t.debouncer!==null&&window.clearTimeout(t.debouncer),t.debouncer=window.setTimeout(()=>l(...a),t.timeout)}return{...u.toRefs(t),debounce:n}}p.copy=Ne,p.createEndpoint=de,p.getDefaultHeaders=q,p.requestTypes=fe,p.useApi=Ce,p.useDebouncer=Be,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(p,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@citruslime/utils"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@citruslime/utils","vue"],A):(p=typeof globalThis<"u"?globalThis:p||self,A(p.CitrusLimeVueUtils={},p.CLUtils,p.Vue))})(this,function(p,A,u){"use strict";const fe=["GET","POST","PUT","DELETE"];function de(e,t,n=null,l=null){return{url:e,type:t,headers:n??M,hasBody:pe(t,l)}}function M(){return{accept:"application/json","content-type":"application/json"}}function pe(e,t){return!!(t===null&&(e==="PUT"||e==="POST")||t)}var X;const q=typeof window<"u";q&&((X=window==null?void 0:window.navigator)!=null&&X.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent);function T(e){return typeof e=="function"?e():u.unref(e)}function Y(e,t=!1,n="Timeout"){return new Promise((l,a)=>{setTimeout(t?()=>a(n):l,e)})}function he(e){return e}function ye(e,...t){return t.some(n=>n in e)}function Z(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}function J(){const e=[],t=a=>{const r=e.indexOf(a);r!==-1&&e.splice(r,1)};return{on:a=>{e.push(a);const r=()=>t(a);return Z(r),{off:r}},off:t,trigger:a=>{e.forEach(r=>r(a))}}}function V(e){return typeof e=="function"?u.computed(e):u.ref(e)}function K(e,t=!1){function n(i,{flush:s="sync",deep:O=!1,timeout:h,throwOnTimeout:I}={}){let y=null;const D=[new Promise(S=>{y=u.watch(e,C=>{i(C)!==t&&(y==null||y(),S(C))},{flush:s,deep:O,immediate:!0})})];return h!=null&&D.push(Y(h,I).then(()=>T(e)).finally(()=>y==null?void 0:y())),Promise.race(D)}function l(i,s){if(!u.isRef(i))return n(C=>C===i,s);const{flush:O="sync",deep:h=!1,timeout:I,throwOnTimeout:y}=s??{};let b=null;const S=[new Promise(C=>{b=u.watch([e,i],([E,N])=>{t!==(E===N)&&(b==null||b(),C(E))},{flush:O,deep:h,immediate:!0})})];return I!=null&&S.push(Y(I,y).then(()=>T(e)).finally(()=>(b==null||b(),T(e)))),Promise.race(S)}function a(i){return n(s=>!!s,i)}function r(i){return l(null,i)}function o(i){return l(void 0,i)}function _(i){return n(Number.isNaN,i)}function m(i,s){return n(O=>{const h=Array.from(O);return h.includes(i)||h.includes(T(i))},s)}function g(i){return v(1,i)}function v(i=1,s){let O=-1;return n(()=>(O+=1,O>=i),s)}return Array.isArray(T(e))?{toMatch:n,toContains:m,changed:g,changedTimes:v,get not(){return K(e,!t)}}:{toMatch:n,toBe:l,toBeTruthy:a,toBeNull:r,toBeNaN:_,toBeUndefined:o,changed:g,changedTimes:v,get not(){return K(e,!t)}}}function me(e){return K(e)}function Oe(e,t,n={}){const{immediate:l=!0}=n,a=u.ref(!1);let r=null;function o(){r&&(clearTimeout(r),r=null)}function _(){a.value=!1,o()}function m(...g){o(),a.value=!0,r=setTimeout(()=>{a.value=!1,r=null,e(...g)},T(t))}return l&&(a.value=!0,q&&m()),Z(_),{isPending:u.readonly(a),start:m,stop:_}}const we=q?window:void 0,ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},te="__vueuse_ssr_handlers__";ee[te]=ee[te]||{};var ge=Object.defineProperty,be=Object.defineProperties,Pe=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,Te=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,re=(e,t,n)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))Te.call(t,n)&&re(e,n,t[n]);if(ne)for(var n of ne(t))_e.call(t,n)&&re(e,n,t[n]);return e},U=(e,t)=>be(e,Pe(t));const ve={json:"application/json",text:"text/plain"};function oe(e){return e&&ye(e,"immediate","refetch","initialData","timeout","beforeFetch","afterFetch","onFetchError","fetch")}function R(e){return typeof Headers<"u"&&e instanceof Headers?Object.fromEntries([...e.entries()]):e}function Ee(e,...t){var n;const l=typeof AbortController=="function";let a={},r={immediate:!0,refetch:!1,timeout:0};const o={method:"GET",type:"text",payload:void 0};t.length>0&&(oe(t[0])?r=c(c({},r),t[0]):a=t[0]),t.length>1&&oe(t[1])&&(r=c(c({},r),t[1]));const{fetch:_=(n=we)==null?void 0:n.fetch,initialData:m,timeout:g}=r,v=J(),i=J(),s=J(),O=u.ref(!1),h=u.ref(!1),I=u.ref(!1),y=u.ref(null),b=u.shallowRef(null),D=u.shallowRef(null),S=u.shallowRef(m),C=u.computed(()=>l&&h.value);let E,N;const W=()=>{l&&E&&(E.abort(),E=void 0)},k=f=>{h.value=f,O.value=!f};g&&(N=Oe(W,g,{immediate:!1}));const Q=async(f=!1)=>{var P;k(!0),D.value=null,y.value=null,I.value=!1,l&&(W(),E=new AbortController,E.signal.onabort=()=>I.value=!0,a=U(c({},a),{signal:E.signal}));const w={method:o.method,headers:{}};if(o.payload){const G=R(w.headers);o.payloadType&&(G["Content-Type"]=(P=ve[o.payloadType])!=null?P:o.payloadType);const L=T(o.payload);w.body=o.payloadType==="json"?JSON.stringify(L):L}let H=!1;const F={url:T(e),options:c(c({},w),a),cancel:()=>{H=!0}};if(r.beforeFetch&&Object.assign(F,await r.beforeFetch(F)),H||!_)return k(!1),Promise.resolve(null);let j=null;return N&&N.start(),new Promise((G,L)=>{var le;_(F.url,U(c(c({},w),F.options),{headers:c(c({},R(w.headers)),R((le=F.options)==null?void 0:le.headers))})).then(async d=>{if(b.value=d,y.value=d.status,j=await d[o.type](),r.afterFetch&&y.value>=200&&y.value<300&&({data:j}=await r.afterFetch({data:j,response:d})),S.value=j,!d.ok)throw new Error(d.statusText);return v.trigger(d),G(d)}).catch(async d=>{let ce=d.message||d.name;return r.onFetchError&&({data:j,error:ce}=await r.onFetchError({data:j,error:d,response:b.value})),S.value=j,D.value=ce,i.trigger(d),f?L(d):G(null)}).finally(()=>{k(!1),N&&N.stop(),s.trigger(null)})})},ue=V(r.refetch);u.watch([ue,V(e)],([f])=>f&&Q(),{deep:!0});const x={isFinished:O,statusCode:y,response:b,error:D,data:S,isFetching:h,canAbort:C,aborted:I,abort:W,execute:Q,onFetchResponse:v.on,onFetchError:i.on,onFetchFinally:s.on,get:B("GET"),put:B("PUT"),post:B("POST"),delete:B("DELETE"),patch:B("PATCH"),head:B("HEAD"),options:B("OPTIONS"),json:$("json"),text:$("text"),blob:$("blob"),arrayBuffer:$("arrayBuffer"),formData:$("formData")};function B(f){return(P,w)=>{if(!h.value){o.method=f,o.payload=P,o.payloadType=w,u.isRef(o.payload)&&u.watch([ue,V(o.payload)],([F])=>F&&Q(),{deep:!0});const H=T(o.payload);return!w&&H&&Object.getPrototypeOf(H)===Object.prototype&&!(H instanceof FormData)&&(o.payloadType="json"),U(c({},x),{then(F,j){return z().then(F,j)}})}}}function z(){return new Promise((f,P)=>{me(O).toBe(!0).then(()=>f(x)).catch(w=>P(w))})}function $(f){return()=>{if(!h.value)return o.type=f,U(c({},x),{then(P,w){return z().then(P,w)}})}}return r.immediate&&setTimeout(Q,0),U(c({},x),{then(f,P){return z().then(f,P)}})}var ae;(function(e){e.UP="UP",e.RIGHT="RIGHT",e.DOWN="DOWN",e.LEFT="LEFT",e.NONE="NONE"})(ae||(ae={}));var Fe=Object.defineProperty,ie=Object.getOwnPropertySymbols,je=Object.prototype.hasOwnProperty,Ie=Object.prototype.propertyIsEnumerable,se=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))je.call(t,n)&&se(e,n,t[n]);if(ie)for(var n of ie(t))Ie.call(t,n)&&se(e,n,t[n]);return e};Se({linear:he},{easeInSine:[.12,0,.39,0],easeOutSine:[.61,1,.88,1],easeInOutSine:[.37,0,.63,1],easeInQuad:[.11,0,.5,0],easeOutQuad:[.5,1,.89,1],easeInOutQuad:[.45,0,.55,1],easeInCubic:[.32,0,.67,0],easeOutCubic:[.33,1,.68,1],easeInOutCubic:[.65,0,.35,1],easeInQuart:[.5,0,.75,0],easeOutQuart:[.25,1,.5,1],easeInOutQuart:[.76,0,.24,1],easeInQuint:[.64,0,.78,0],easeOutQuint:[.22,1,.36,1],easeInOutQuint:[.83,0,.17,1],easeInExpo:[.7,0,.84,0],easeOutExpo:[.16,1,.3,1],easeInOutExpo:[.87,0,.13,1],easeInCirc:[.55,0,1,.45],easeOutCirc:[0,.55,.45,1],easeInOutCirc:[.85,0,.15,1],easeInBack:[.36,0,.66,-.56],easeOutBack:[.34,1.56,.64,1],easeInOutBack:[.68,-.6,.32,1.6]});function Ce(e,t){const n={};return Object.keys(e).forEach(a=>{n[a]=(...r)=>{const o=e[a],_=o.type;let m=`/api/${o.url}`;o.hasBody?m=A.replacePlaceholders(m,...r.splice(1)):m=A.replacePlaceholders(m,...r);const g={...M(),...o.headers()},v=Ee(m,{method:_},{immediate:!1,beforeFetch({options:s}){return s.headers={...s.headers,...g},o.hasBody&&r.length&&(s.body=JSON.stringify(r[0])),{options:s}},onFetchError(s){return s!=null&&s.response&&t(s),s}});return{...De(g)==="application/json"?v.json():v.text()}}}),n}function De(e){return e.accept??"*/*"}function Ne(e){return JSON.parse(JSON.stringify(e))}function Be(e=500){const t=u.reactive({debouncer:null,timeout:e});function n(l,...a){t.debouncer!==null&&window.clearTimeout(t.debouncer),t.debouncer=window.setTimeout(()=>l(...a),t.timeout)}return{...u.toRefs(t),debounce:n}}p.copy=Ne,p.createEndpoint=de,p.getDefaultHeaders=M,p.requestTypes=fe,p.useApi=Ce,p.useDebouncer=Be,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/vue-utils",
3
- "version": "1.2.1-beta.0",
3
+ "version": "1.2.2-beta.0",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Citrus-Lime Ltd",
@@ -23,14 +23,15 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "import": "./dist/citrus-lime-vue-utils.es.js",
26
- "require": "./dist/citrus-lime-vue-utils.umd.js"
26
+ "require": "./dist/citrus-lime-vue-utils.umd.js",
27
+ "types": "./dist/main.d.ts"
27
28
  }
28
29
  },
29
30
  "scripts": {
30
31
  "build": "vite build && copyfiles -u 2 \"dist/src/**/*\" dist && del-cli dist/src"
31
32
  },
32
33
  "dependencies": {
33
- "@citruslime/utils": "^1.1.1-beta.0"
34
+ "@citruslime/utils": "^1.1.2-beta.0"
34
35
  },
35
36
  "peerDependencies": {
36
37
  "@vueuse/core": "^9.13.0",