@citruslime/vue-utils 1.2.0-beta.0 → 1.2.0-beta.2

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.
package/README.md CHANGED
@@ -11,8 +11,8 @@ A TypeScript package containing various utilities for Vue-based projects. Used b
11
11
 
12
12
  ## Install
13
13
 
14
- `npm install @citruslime/vue-utils vue@next`
14
+ `npm install @citruslime/vue-utils vue`
15
15
 
16
16
  or
17
17
 
18
- `yarn add @citruslime/vue-utils vue@next`
18
+ `yarn add @citruslime/vue-utils vue`
@@ -1,47 +1,47 @@
1
- import "@citruslime/utils";
2
- import { computed as ce, ref as B, readonly as pe, unref as ye, getCurrentScope as he, onScopeDispose as me, watch as G, isRef as X, shallowRef as M, reactive as Oe, toRefs as ve } from "vue";
3
- const Je = [
1
+ import { replacePlaceholders as ne } from "@citruslime/utils";
2
+ import { computed as fe, ref as B, readonly as ye, unref as he, getCurrentScope as me, onScopeDispose as Oe, watch as G, isRef as X, shallowRef as M, reactive as ve, toRefs as ge } from "vue";
3
+ const Ke = [
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 Le(e, t, n = null, s = null) {
10
10
  return {
11
11
  url: e,
12
12
  type: t,
13
- headers: n ?? ge(),
14
- hasBody: we(t, s)
13
+ headers: n ?? we(),
14
+ hasBody: be(t, s)
15
15
  };
16
16
  }
17
- function ge() {
17
+ function we() {
18
18
  return {
19
19
  Accept: "application/json",
20
20
  "Content-Type": "application/json"
21
21
  };
22
22
  }
23
- function we(e, t) {
23
+ function be(e, t) {
24
24
  return !!(t === null && (e === "PUT" || e === "POST") || t);
25
25
  }
26
- var ne;
26
+ var re;
27
27
  const Y = typeof window < "u";
28
- Y && ((ne = window == null ? void 0 : window.navigator) != null && ne.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
28
+ Y && ((re = window == null ? void 0 : window.navigator) != null && re.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
29
29
  function E(e) {
30
- return typeof e == "function" ? e() : ye(e);
30
+ return typeof e == "function" ? e() : he(e);
31
31
  }
32
- function re(e, t = !1, n = "Timeout") {
32
+ function oe(e, t = !1, n = "Timeout") {
33
33
  return new Promise((s, a) => {
34
34
  setTimeout(t ? () => a(n) : s, e);
35
35
  });
36
36
  }
37
- function be(e) {
37
+ function Te(e) {
38
38
  return e;
39
39
  }
40
40
  function Pe(e, ...t) {
41
41
  return t.some((n) => n in e);
42
42
  }
43
- function fe(e) {
44
- return he() ? (me(e), !0) : !1;
43
+ function de(e) {
44
+ return me() ? (Oe(e), !0) : !1;
45
45
  }
46
46
  function W() {
47
47
  const e = [], t = (a) => {
@@ -52,7 +52,7 @@ function W() {
52
52
  on: (a) => {
53
53
  e.push(a);
54
54
  const r = () => t(a);
55
- return fe(r), {
55
+ return de(r), {
56
56
  off: r
57
57
  };
58
58
  },
@@ -63,7 +63,7 @@ function W() {
63
63
  };
64
64
  }
65
65
  function V(e) {
66
- return typeof e == "function" ? ce(e) : B(e);
66
+ return typeof e == "function" ? fe(e) : B(e);
67
67
  }
68
68
  function q(e, t = !1) {
69
69
  function n(i, { flush: u = "sync", deep: h = !1, timeout: d, throwOnTimeout: F } = {}) {
@@ -77,7 +77,7 @@ function q(e, t = !1) {
77
77
  immediate: !0
78
78
  });
79
79
  })];
80
- return d != null && C.push(re(d, F).then(() => E(e)).finally(() => p == null ? void 0 : p())), Promise.race(C);
80
+ return d != null && C.push(oe(d, F).then(() => E(e)).finally(() => p == null ? void 0 : p())), Promise.race(C);
81
81
  }
82
82
  function s(i, u) {
83
83
  if (!X(i))
@@ -85,15 +85,15 @@ function q(e, t = !1) {
85
85
  const { flush: h = "sync", deep: d = !1, timeout: F, throwOnTimeout: p } = u ?? {};
86
86
  let v = null;
87
87
  const j = [new Promise((I) => {
88
- v = G([e, i], ([P, N]) => {
89
- t !== (P === N) && (v == null || v(), I(P));
88
+ v = G([e, i], ([T, N]) => {
89
+ t !== (T === N) && (v == null || v(), I(T));
90
90
  }, {
91
91
  flush: h,
92
92
  deep: d,
93
93
  immediate: !0
94
94
  });
95
95
  })];
96
- return F != null && j.push(re(F, p).then(() => E(e)).finally(() => (v == null || v(), E(e)))), Promise.race(j);
96
+ return F != null && j.push(oe(F, p).then(() => E(e)).finally(() => (v == null || v(), E(e)))), Promise.race(j);
97
97
  }
98
98
  function a(i) {
99
99
  return n((u) => Boolean(u), i);
@@ -142,10 +142,10 @@ function q(e, t = !1) {
142
142
  }
143
143
  };
144
144
  }
145
- function Te(e) {
145
+ function _e(e) {
146
146
  return q(e);
147
147
  }
148
- function _e(e, t, n = {}) {
148
+ function Ee(e, t, n = {}) {
149
149
  const {
150
150
  immediate: s = !0
151
151
  } = n, a = B(!1);
@@ -161,34 +161,34 @@ 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, Y && y()), fe(w), {
165
- isPending: pe(a),
164
+ return s && (a.value = !0, Y && y()), de(w), {
165
+ isPending: ye(a),
166
166
  start: y,
167
167
  stop: w
168
168
  };
169
169
  }
170
- const Ee = Y ? window : void 0, R = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, z = "__vueuse_ssr_handlers__";
170
+ const Fe = Y ? window : void 0, R = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, z = "__vueuse_ssr_handlers__";
171
171
  R[z] = R[z] || {};
172
172
  R[z];
173
- var Fe = Object.defineProperty, je = Object.defineProperties, Ie = Object.getOwnPropertyDescriptors, oe = Object.getOwnPropertySymbols, Ce = Object.prototype.hasOwnProperty, Ne = 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) => {
173
+ var je = Object.defineProperty, Ie = Object.defineProperties, Ce = Object.getOwnPropertyDescriptors, ae = Object.getOwnPropertySymbols, Ne = Object.prototype.hasOwnProperty, Se = Object.prototype.propertyIsEnumerable, ie = (e, t, n) => t in e ? je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, f = (e, t) => {
174
174
  for (var n in t || (t = {}))
175
- Ce.call(t, n) && ae(e, n, t[n]);
176
- if (oe)
177
- for (var n of oe(t))
178
- Ne.call(t, n) && ae(e, n, t[n]);
175
+ Ne.call(t, n) && ie(e, n, t[n]);
176
+ if (ae)
177
+ for (var n of ae(t))
178
+ Se.call(t, n) && ie(e, n, t[n]);
179
179
  return e;
180
- }, H = (e, t) => je(e, Ie(t));
181
- const Se = {
180
+ }, H = (e, t) => Ie(e, Ce(t));
181
+ const Ae = {
182
182
  json: "application/json",
183
183
  text: "text/plain"
184
184
  };
185
- function ie(e) {
185
+ function ue(e) {
186
186
  return e && Pe(e, "immediate", "refetch", "initialData", "timeout", "beforeFetch", "afterFetch", "onFetchError", "fetch");
187
187
  }
188
188
  function k(e) {
189
189
  return typeof Headers < "u" && e instanceof Headers ? Object.fromEntries([...e.entries()]) : e;
190
190
  }
191
- function Ae(e, ...t) {
191
+ function Be(e, ...t) {
192
192
  var n;
193
193
  const s = typeof AbortController == "function";
194
194
  let a = {}, r = { immediate: !0, refetch: !1, timeout: 0 };
@@ -197,23 +197,23 @@ function Ae(e, ...t) {
197
197
  type: "text",
198
198
  payload: void 0
199
199
  };
200
- t.length > 0 && (ie(t[0]) ? r = f(f({}, r), t[0]) : a = t[0]), t.length > 1 && ie(t[1]) && (r = f(f({}, r), t[1]));
200
+ t.length > 0 && (ue(t[0]) ? r = f(f({}, r), t[0]) : a = t[0]), t.length > 1 && ue(t[1]) && (r = f(f({}, r), t[1]));
201
201
  const {
202
- fetch: w = (n = Ee) == null ? void 0 : n.fetch,
202
+ fetch: w = (n = Fe) == null ? void 0 : n.fetch,
203
203
  initialData: y,
204
204
  timeout: O
205
- } = r, b = W(), i = W(), u = W(), h = B(!1), d = B(!1), F = B(!1), p = B(null), v = M(null), C = M(null), j = M(y), I = ce(() => s && d.value);
206
- let P, N;
205
+ } = r, b = W(), i = W(), u = W(), h = B(!1), d = B(!1), F = B(!1), p = B(null), v = M(null), C = M(null), j = M(y), I = fe(() => s && d.value);
206
+ let T, N;
207
207
  const J = () => {
208
- s && P && (P.abort(), P = void 0);
208
+ s && T && (T.abort(), T = void 0);
209
209
  }, K = (l) => {
210
210
  d.value = l, h.value = !l;
211
211
  };
212
- O && (N = _e(J, O, { immediate: !1 }));
212
+ O && (N = Ee(J, O, { immediate: !1 }));
213
213
  const $ = async (l = !1) => {
214
214
  var g;
215
- K(!0), C.value = null, p.value = null, F.value = !1, s && (J(), P = new AbortController(), P.signal.onabort = () => F.value = !0, a = H(f({}, a), {
216
- signal: P.signal
215
+ K(!0), C.value = null, p.value = null, F.value = !1, s && (J(), T = new AbortController(), T.signal.onabort = () => F.value = !0, a = H(f({}, a), {
216
+ signal: T.signal
217
217
  }));
218
218
  const m = {
219
219
  method: o.method,
@@ -221,25 +221,25 @@ function Ae(e, ...t) {
221
221
  };
222
222
  if (o.payload) {
223
223
  const Q = k(m.headers);
224
- o.payloadType && (Q["Content-Type"] = (g = Se[o.payloadType]) != null ? g : o.payloadType);
224
+ o.payloadType && (Q["Content-Type"] = (g = Ae[o.payloadType]) != null ? g : o.payloadType);
225
225
  const U = E(o.payload);
226
226
  m.body = o.payloadType === "json" ? JSON.stringify(U) : U;
227
227
  }
228
228
  let A = !1;
229
- const T = {
229
+ const P = {
230
230
  url: E(e),
231
231
  options: f(f({}, m), a),
232
232
  cancel: () => {
233
233
  A = !0;
234
234
  }
235
235
  };
236
- if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)), A || !w)
236
+ if (r.beforeFetch && Object.assign(P, await r.beforeFetch(P)), A || !w)
237
237
  return K(!1), Promise.resolve(null);
238
238
  let _ = null;
239
239
  return N && N.start(), new Promise((Q, U) => {
240
240
  var ee;
241
- w(T.url, H(f(f({}, m), T.options), {
242
- headers: f(f({}, k(m.headers)), k((ee = T.options) == null ? void 0 : ee.headers))
241
+ w(P.url, H(f(f({}, m), P.options), {
242
+ headers: f(f({}, k(m.headers)), k((ee = P.options) == null ? void 0 : ee.headers))
243
243
  })).then(async (c) => {
244
244
  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 })), j.value = _, !c.ok)
245
245
  throw new Error(c.statusText);
@@ -289,11 +289,11 @@ function Ae(e, ...t) {
289
289
  o.method = l, o.payload = g, o.payloadType = m, X(o.payload) && G([
290
290
  Z,
291
291
  V(o.payload)
292
- ], ([T]) => T && $(), { deep: !0 });
292
+ ], ([P]) => P && $(), { deep: !0 });
293
293
  const A = E(o.payload);
294
294
  return !m && A && Object.getPrototypeOf(A) === Object.prototype && !(A instanceof FormData) && (o.payloadType = "json"), H(f({}, x), {
295
- then(T, _) {
296
- return L().then(T, _);
295
+ then(P, _) {
296
+ return L().then(P, _);
297
297
  }
298
298
  });
299
299
  }
@@ -301,7 +301,7 @@ function Ae(e, ...t) {
301
301
  }
302
302
  function L() {
303
303
  return new Promise((l, g) => {
304
- Te(h).toBe(!0).then(() => l(x)).catch((m) => g(m));
304
+ _e(h).toBe(!0).then(() => l(x)).catch((m) => g(m));
305
305
  });
306
306
  }
307
307
  function D(l) {
@@ -320,19 +320,19 @@ function Ae(e, ...t) {
320
320
  }
321
321
  });
322
322
  }
323
- var ue;
323
+ var se;
324
324
  (function(e) {
325
325
  e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
326
- })(ue || (ue = {}));
327
- var Be = Object.defineProperty, se = Object.getOwnPropertySymbols, De = Object.prototype.hasOwnProperty, He = Object.prototype.propertyIsEnumerable, le = (e, t, n) => t in e ? Be(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, $e = (e, t) => {
326
+ })(se || (se = {}));
327
+ var De = Object.defineProperty, le = Object.getOwnPropertySymbols, He = Object.prototype.hasOwnProperty, $e = Object.prototype.propertyIsEnumerable, ce = (e, t, n) => t in e ? De(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, xe = (e, t) => {
328
328
  for (var n in t || (t = {}))
329
- De.call(t, n) && le(e, n, t[n]);
330
- if (se)
331
- for (var n of se(t))
332
- He.call(t, n) && le(e, n, t[n]);
329
+ He.call(t, n) && ce(e, n, t[n]);
330
+ if (le)
331
+ for (var n of le(t))
332
+ $e.call(t, n) && ce(e, n, t[n]);
333
333
  return e;
334
334
  };
335
- const xe = {
335
+ const Qe = {
336
336
  easeInSine: [0.12, 0, 0.39, 0],
337
337
  easeOutSine: [0.61, 1, 0.88, 1],
338
338
  easeInOutSine: [0.37, 0, 0.63, 1],
@@ -358,21 +358,21 @@ const xe = {
358
358
  easeOutBack: [0.34, 1.56, 0.64, 1],
359
359
  easeInOutBack: [0.68, -0.6, 0.32, 1.6]
360
360
  };
361
- $e({
362
- linear: be
363
- }, xe);
364
- function Le(e, t) {
361
+ xe({
362
+ linear: Te
363
+ }, Qe);
364
+ function Me(e, t) {
365
365
  const n = {};
366
366
  return Object.keys(e).forEach((a) => {
367
367
  n[a] = (...r) => {
368
368
  const o = e[a], w = o.type;
369
369
  let y = `/api/${o.url}`;
370
- o.hasBody ? y = y.replacePlaceholders(...r.splice(1)) : y = y.replacePlaceholders(...r);
370
+ o.hasBody ? y = ne(y, ...r.splice(1)) : y = ne(y, ...r);
371
371
  const O = {
372
372
  Accept: "application/json",
373
373
  "Content-Type": "application/json",
374
- ...de(o.headers)
375
- }, b = Ae(
374
+ ...pe(o.headers)
375
+ }, b = Be(
376
376
  y,
377
377
  {
378
378
  method: w
@@ -393,24 +393,24 @@ function Le(e, t) {
393
393
  }
394
394
  );
395
395
  return {
396
- ...Qe(O) === "application/json" ? b.json() : b.text()
396
+ ...Ue(O) === "application/json" ? b.json() : b.text()
397
397
  };
398
398
  };
399
399
  }), n;
400
400
  }
401
- function Qe(e) {
402
- const t = de(e);
401
+ function Ue(e) {
402
+ const t = pe(e);
403
403
  return (t == null ? void 0 : t.accept) ?? "";
404
404
  }
405
- function de(e) {
405
+ function pe(e) {
406
406
  let t = {};
407
407
  return X(e) ? t = e.value : t = e, t;
408
408
  }
409
- function Me(e) {
409
+ function We(e) {
410
410
  return JSON.parse(JSON.stringify(e));
411
411
  }
412
- function We(e = 500) {
413
- const t = Oe({
412
+ function Ve(e = 500) {
413
+ const t = ve({
414
414
  debouncer: null,
415
415
  timeout: e
416
416
  });
@@ -418,14 +418,14 @@ function We(e = 500) {
418
418
  t.debouncer !== null && window.clearTimeout(t.debouncer), t.debouncer = window.setTimeout(() => s(...a), t.timeout);
419
419
  }
420
420
  return {
421
- ...ve(t),
421
+ ...ge(t),
422
422
  debounce: n
423
423
  };
424
424
  }
425
425
  export {
426
- Me as copy,
427
- Ke as createEndpoint,
428
- Je as requestTypes,
429
- Le as useApi,
430
- We as useDebouncer
426
+ We as copy,
427
+ Le as createEndpoint,
428
+ Ke as requestTypes,
429
+ Me as useApi,
430
+ Ve as useDebouncer
431
431
  };
@@ -1 +1 @@
1
- (function(h,$){typeof exports=="object"&&typeof module<"u"?$(exports,require("@citruslime/utils"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@citruslime/utils","vue"],$):(h=typeof globalThis<"u"?globalThis:h||self,$(h.CitrusLimeVueUtils={},h.CLUtils,h.Vue))})(this,function(h,$,u){"use strict";const fe=["GET","POST","PUT","DELETE"];function de(e,t,n=null,l=null){return{url:e,type:t,headers:n??pe(),hasBody:ye(t,l)}}function pe(){return{Accept:"application/json","Content-Type":"application/json"}}function ye(e,t){return!!(t===null&&(e==="PUT"||e==="POST")||t)}var Y;const R=typeof window<"u";R&&((Y=window==null?void 0:window.navigator)!=null&&Y.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent);function P(e){return typeof e=="function"?e():u.unref(e)}function Z(e,t=!1,n="Timeout"){return new Promise((l,a)=>{setTimeout(t?()=>a(n):l,e)})}function he(e){return e}function me(e,...t){return t.some(n=>n in e)}function ee(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}function q(){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 ee(r),{off:r}},off:t,trigger:a=>{e.forEach(r=>r(a))}}}function J(e){return typeof e=="function"?u.computed(e):u.ref(e)}function M(e,t=!1){function n(i,{flush:s="sync",deep:O=!1,timeout:p,throwOnTimeout:I}={}){let y=null;const A=[new Promise(C=>{y=u.watch(e,S=>{i(S)!==t&&(y==null||y(),C(S))},{flush:s,deep:O,immediate:!0})})];return p!=null&&A.push(Z(p,I).then(()=>P(e)).finally(()=>y==null?void 0:y())),Promise.race(A)}function l(i,s){if(!u.isRef(i))return n(S=>S===i,s);const{flush:O="sync",deep:p=!1,timeout:I,throwOnTimeout:y}=s??{};let g=null;const C=[new Promise(S=>{g=u.watch([e,i],([E,D])=>{t!==(E===D)&&(g==null||g(),S(E))},{flush:O,deep:p,immediate:!0})})];return I!=null&&C.push(Z(I,y).then(()=>P(e)).finally(()=>(g==null||g(),P(e)))),Promise.race(C)}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 p=Array.from(O);return p.includes(i)||p.includes(P(i))},s)}function T(i){return v(1,i)}function v(i=1,s){let O=-1;return n(()=>(O+=1,O>=i),s)}return Array.isArray(P(e))?{toMatch:n,toContains:m,changed:T,changedTimes:v,get not(){return M(e,!t)}}:{toMatch:n,toBe:l,toBeTruthy:a,toBeNull:r,toBeNaN:_,toBeUndefined:o,changed:T,changedTimes:v,get not(){return M(e,!t)}}}function Oe(e){return M(e)}function we(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(...T){o(),a.value=!0,r=setTimeout(()=>{a.value=!1,r=null,e(...T)},P(t))}return l&&(a.value=!0,R&&m()),ee(_),{isPending:u.readonly(a),start:m,stop:_}}const Te=R?window:void 0,V=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},K="__vueuse_ssr_handlers__";V[K]=V[K]||{},V[K];var ge=Object.defineProperty,be=Object.defineProperties,Pe=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,ne=(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={}))_e.call(t,n)&&ne(e,n,t[n]);if(te)for(var n of te(t))ve.call(t,n)&&ne(e,n,t[n]);return e},H=(e,t)=>be(e,Pe(t));const Ee={json:"application/json",text:"text/plain"};function re(e){return e&&me(e,"immediate","refetch","initialData","timeout","beforeFetch","afterFetch","onFetchError","fetch")}function W(e){return typeof Headers<"u"&&e instanceof Headers?Object.fromEntries([...e.entries()]):e}function Fe(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&&(re(t[0])?r=c(c({},r),t[0]):a=t[0]),t.length>1&&re(t[1])&&(r=c(c({},r),t[1]));const{fetch:_=(n=Te)==null?void 0:n.fetch,initialData:m,timeout:T}=r,v=q(),i=q(),s=q(),O=u.ref(!1),p=u.ref(!1),I=u.ref(!1),y=u.ref(null),g=u.shallowRef(null),A=u.shallowRef(null),C=u.shallowRef(m),S=u.computed(()=>l&&p.value);let E,D;const k=()=>{l&&E&&(E.abort(),E=void 0)},z=f=>{p.value=f,O.value=!f};T&&(D=we(k,T,{immediate:!1}));const Q=async(f=!1)=>{var b;z(!0),A.value=null,y.value=null,I.value=!1,l&&(k(),E=new AbortController,E.signal.onabort=()=>I.value=!0,a=H(c({},a),{signal:E.signal}));const w={method:o.method,headers:{}};if(o.payload){const G=W(w.headers);o.payloadType&&(G["Content-Type"]=(b=Ee[o.payloadType])!=null?b:o.payloadType);const L=P(o.payload);w.body=o.payloadType==="json"?JSON.stringify(L):L}let B=!1;const F={url:P(e),options:c(c({},w),a),cancel:()=>{B=!0}};if(r.beforeFetch&&Object.assign(F,await r.beforeFetch(F)),B||!_)return z(!1),Promise.resolve(null);let j=null;return D&&D.start(),new Promise((G,L)=>{var le;_(F.url,H(c(c({},w),F.options),{headers:c(c({},W(w.headers)),W((le=F.options)==null?void 0:le.headers))})).then(async d=>{if(g.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})),C.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:g.value})),C.value=j,A.value=ce,i.trigger(d),f?L(d):G(null)}).finally(()=>{z(!1),D&&D.stop(),s.trigger(null)})})},ue=J(r.refetch);u.watch([ue,J(e)],([f])=>f&&Q(),{deep:!0});const x={isFinished:O,statusCode:y,response:g,error:A,data:C,isFetching:p,canAbort:S,aborted:I,abort:k,execute:Q,onFetchResponse:v.on,onFetchError:i.on,onFetchFinally:s.on,get:N("GET"),put:N("PUT"),post:N("POST"),delete:N("DELETE"),patch:N("PATCH"),head:N("HEAD"),options:N("OPTIONS"),json:U("json"),text:U("text"),blob:U("blob"),arrayBuffer:U("arrayBuffer"),formData:U("formData")};function N(f){return(b,w)=>{if(!p.value){o.method=f,o.payload=b,o.payloadType=w,u.isRef(o.payload)&&u.watch([ue,J(o.payload)],([F])=>F&&Q(),{deep:!0});const B=P(o.payload);return!w&&B&&Object.getPrototypeOf(B)===Object.prototype&&!(B instanceof FormData)&&(o.payloadType="json"),H(c({},x),{then(F,j){return X().then(F,j)}})}}}function X(){return new Promise((f,b)=>{Oe(O).toBe(!0).then(()=>f(x)).catch(w=>b(w))})}function U(f){return()=>{if(!p.value)return o.type=f,H(c({},x),{then(b,w){return X().then(b,w)}})}}return r.immediate&&setTimeout(Q,0),H(c({},x),{then(f,b){return X().then(f,b)}})}var oe;(function(e){e.UP="UP",e.RIGHT="RIGHT",e.DOWN="DOWN",e.LEFT="LEFT",e.NONE="NONE"})(oe||(oe={}));var je=Object.defineProperty,ae=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable,ie=(e,t,n)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))Ie.call(t,n)&&ie(e,n,t[n]);if(ae)for(var n of ae(t))Ce.call(t,n)&&ie(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 Ae(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=m.replacePlaceholders(...r.splice(1)):m=m.replacePlaceholders(...r);const T={Accept:"application/json","Content-Type":"application/json",...se(o.headers)},v=Fe(m,{method:_},{immediate:!1,beforeFetch({options:s}){return s.headers={...s.headers,...T},o.hasBody&&r.length&&(s.body=JSON.stringify(r[0])),{options:s}},onFetchError(s){return s!=null&&s.response&&t(s),s}});return{...De(T)==="application/json"?v.json():v.text()}}}),n}function De(e){const t=se(e);return(t==null?void 0:t.accept)??""}function se(e){let t={};return u.isRef(e)?t=e.value:t=e,t}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}}h.copy=Ne,h.createEndpoint=de,h.requestTypes=fe,h.useApi=Ae,h.useDebouncer=Be,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,B){typeof exports=="object"&&typeof module<"u"?B(exports,require("@citruslime/utils"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@citruslime/utils","vue"],B):(h=typeof globalThis<"u"?globalThis:h||self,B(h.CitrusLimeVueUtils={},h.CLUtils,h.Vue))})(this,function(h,B,u){"use strict";const fe=["GET","POST","PUT","DELETE"];function de(e,t,n=null,l=null){return{url:e,type:t,headers:n??pe(),hasBody:ye(t,l)}}function pe(){return{Accept:"application/json","Content-Type":"application/json"}}function ye(e,t){return!!(t===null&&(e==="PUT"||e==="POST")||t)}var Y;const R=typeof window<"u";R&&((Y=window==null?void 0:window.navigator)!=null&&Y.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent);function P(e){return typeof e=="function"?e():u.unref(e)}function Z(e,t=!1,n="Timeout"){return new Promise((l,a)=>{setTimeout(t?()=>a(n):l,e)})}function he(e){return e}function me(e,...t){return t.some(n=>n in e)}function ee(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}function q(){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 ee(r),{off:r}},off:t,trigger:a=>{e.forEach(r=>r(a))}}}function J(e){return typeof e=="function"?u.computed(e):u.ref(e)}function M(e,t=!1){function n(i,{flush:s="sync",deep:O=!1,timeout:p,throwOnTimeout:I}={}){let y=null;const A=[new Promise(C=>{y=u.watch(e,S=>{i(S)!==t&&(y==null||y(),C(S))},{flush:s,deep:O,immediate:!0})})];return p!=null&&A.push(Z(p,I).then(()=>P(e)).finally(()=>y==null?void 0:y())),Promise.race(A)}function l(i,s){if(!u.isRef(i))return n(S=>S===i,s);const{flush:O="sync",deep:p=!1,timeout:I,throwOnTimeout:y}=s??{};let g=null;const C=[new Promise(S=>{g=u.watch([e,i],([E,D])=>{t!==(E===D)&&(g==null||g(),S(E))},{flush:O,deep:p,immediate:!0})})];return I!=null&&C.push(Z(I,y).then(()=>P(e)).finally(()=>(g==null||g(),P(e)))),Promise.race(C)}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 p=Array.from(O);return p.includes(i)||p.includes(P(i))},s)}function T(i){return v(1,i)}function v(i=1,s){let O=-1;return n(()=>(O+=1,O>=i),s)}return Array.isArray(P(e))?{toMatch:n,toContains:m,changed:T,changedTimes:v,get not(){return M(e,!t)}}:{toMatch:n,toBe:l,toBeTruthy:a,toBeNull:r,toBeNaN:_,toBeUndefined:o,changed:T,changedTimes:v,get not(){return M(e,!t)}}}function Oe(e){return M(e)}function we(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(...T){o(),a.value=!0,r=setTimeout(()=>{a.value=!1,r=null,e(...T)},P(t))}return l&&(a.value=!0,R&&m()),ee(_),{isPending:u.readonly(a),start:m,stop:_}}const Te=R?window:void 0,V=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},K="__vueuse_ssr_handlers__";V[K]=V[K]||{},V[K];var ge=Object.defineProperty,be=Object.defineProperties,Pe=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,ne=(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={}))_e.call(t,n)&&ne(e,n,t[n]);if(te)for(var n of te(t))ve.call(t,n)&&ne(e,n,t[n]);return e},U=(e,t)=>be(e,Pe(t));const Ee={json:"application/json",text:"text/plain"};function re(e){return e&&me(e,"immediate","refetch","initialData","timeout","beforeFetch","afterFetch","onFetchError","fetch")}function W(e){return typeof Headers<"u"&&e instanceof Headers?Object.fromEntries([...e.entries()]):e}function Fe(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&&(re(t[0])?r=c(c({},r),t[0]):a=t[0]),t.length>1&&re(t[1])&&(r=c(c({},r),t[1]));const{fetch:_=(n=Te)==null?void 0:n.fetch,initialData:m,timeout:T}=r,v=q(),i=q(),s=q(),O=u.ref(!1),p=u.ref(!1),I=u.ref(!1),y=u.ref(null),g=u.shallowRef(null),A=u.shallowRef(null),C=u.shallowRef(m),S=u.computed(()=>l&&p.value);let E,D;const k=()=>{l&&E&&(E.abort(),E=void 0)},z=f=>{p.value=f,O.value=!f};T&&(D=we(k,T,{immediate:!1}));const Q=async(f=!1)=>{var b;z(!0),A.value=null,y.value=null,I.value=!1,l&&(k(),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=W(w.headers);o.payloadType&&(G["Content-Type"]=(b=Ee[o.payloadType])!=null?b:o.payloadType);const L=P(o.payload);w.body=o.payloadType==="json"?JSON.stringify(L):L}let H=!1;const F={url:P(e),options:c(c({},w),a),cancel:()=>{H=!0}};if(r.beforeFetch&&Object.assign(F,await r.beforeFetch(F)),H||!_)return z(!1),Promise.resolve(null);let j=null;return D&&D.start(),new Promise((G,L)=>{var le;_(F.url,U(c(c({},w),F.options),{headers:c(c({},W(w.headers)),W((le=F.options)==null?void 0:le.headers))})).then(async d=>{if(g.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})),C.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:g.value})),C.value=j,A.value=ce,i.trigger(d),f?L(d):G(null)}).finally(()=>{z(!1),D&&D.stop(),s.trigger(null)})})},ue=J(r.refetch);u.watch([ue,J(e)],([f])=>f&&Q(),{deep:!0});const x={isFinished:O,statusCode:y,response:g,error:A,data:C,isFetching:p,canAbort:S,aborted:I,abort:k,execute:Q,onFetchResponse:v.on,onFetchError:i.on,onFetchFinally:s.on,get:N("GET"),put:N("PUT"),post:N("POST"),delete:N("DELETE"),patch:N("PATCH"),head:N("HEAD"),options:N("OPTIONS"),json:$("json"),text:$("text"),blob:$("blob"),arrayBuffer:$("arrayBuffer"),formData:$("formData")};function N(f){return(b,w)=>{if(!p.value){o.method=f,o.payload=b,o.payloadType=w,u.isRef(o.payload)&&u.watch([ue,J(o.payload)],([F])=>F&&Q(),{deep:!0});const H=P(o.payload);return!w&&H&&Object.getPrototypeOf(H)===Object.prototype&&!(H instanceof FormData)&&(o.payloadType="json"),U(c({},x),{then(F,j){return X().then(F,j)}})}}}function X(){return new Promise((f,b)=>{Oe(O).toBe(!0).then(()=>f(x)).catch(w=>b(w))})}function $(f){return()=>{if(!p.value)return o.type=f,U(c({},x),{then(b,w){return X().then(b,w)}})}}return r.immediate&&setTimeout(Q,0),U(c({},x),{then(f,b){return X().then(f,b)}})}var oe;(function(e){e.UP="UP",e.RIGHT="RIGHT",e.DOWN="DOWN",e.LEFT="LEFT",e.NONE="NONE"})(oe||(oe={}));var je=Object.defineProperty,ae=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable,ie=(e,t,n)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))Ie.call(t,n)&&ie(e,n,t[n]);if(ae)for(var n of ae(t))Ce.call(t,n)&&ie(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 Ae(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=B.replacePlaceholders(m,...r.splice(1)):m=B.replacePlaceholders(m,...r);const T={Accept:"application/json","Content-Type":"application/json",...se(o.headers)},v=Fe(m,{method:_},{immediate:!1,beforeFetch({options:s}){return s.headers={...s.headers,...T},o.hasBody&&r.length&&(s.body=JSON.stringify(r[0])),{options:s}},onFetchError(s){return s!=null&&s.response&&t(s),s}});return{...De(T)==="application/json"?v.json():v.text()}}}),n}function De(e){const t=se(e);return(t==null?void 0:t.accept)??""}function se(e){let t={};return u.isRef(e)?t=e.value:t=e,t}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}}h.copy=Ne,h.createEndpoint=de,h.requestTypes=fe,h.useApi=Ae,h.useDebouncer=Be,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/vue-utils",
3
- "version": "1.2.0-beta.0",
3
+ "version": "1.2.0-beta.2",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Citrus-Lime Ltd",
@@ -30,7 +30,7 @@
30
30
  "build": "vite build && copyfiles -u 2 \"dist/src/**/*\" dist && del-cli dist/src"
31
31
  },
32
32
  "dependencies": {
33
- "@citruslime/utils": "~0.0.0"
33
+ "@citruslime/utils": "^1.1.1-beta.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@vueuse/core": "^9.13.0",