@provydon/vue-auto-save 1.1.0 → 1.1.1

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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),P=["save","applicationId","isDirty","processing","errors","hasErrors","recentlySuccessful","wasSuccessful","data","transform","get","post","put","patch","delete","cancel","reset","clearErrors","setError","setData"];function q(l,p){const{debounce:n=3e3,skipFields:T=[],skipInertiaFields:I=!0,deep:O=!0,debug:o=!1,serialize:D=JSON.stringify,compare:S,saveOnInit:b=!1,onSave:W,onBeforeSave:h,onAfterSave:m,onError:c}=p,u=s.ref(!1),a=s.ref(!0);let r=()=>{},i=()=>{};const j=(t=1e3)=>{a.value=!1,r(),i(),setTimeout(()=>{a.value=!0},t)},z=(t=null)=>{if(a.value=!0,r(),i(),t===null)d();else{const e=A(d,t);i=e.cancel,e.call()}},f=()=>{const t=s.isRef(l)?s.unref(l):l,e={};for(const v of Object.keys(t))I&&P.includes(v)||T.includes(v)||(e[v]=t[v]);return e};let g=b?null:D(f()),y=S?b?null:f():null;const d=()=>{if(!a.value)return;const t=f();if(S){if(y&&S(y,t))return;y=t}else{const e=D(t);if(g!==null&&e===g)return;g=e}o&&console.log("[AutoSave] Detected changes. Saving..."),u.value=!0;try{h==null||h(),Promise.resolve(W()).then(()=>{m==null||m(),o&&console.log("[AutoSave] Save successful.")}).catch(e=>{c==null||c(e),o&&console.error("[AutoSave] Save failed:",e)}).finally(()=>{u.value=!1})}catch(e){c==null||c(e),o&&console.error("[AutoSave] Immediate error:",e),u.value=!1}},F=A(d,n),w=F.call;r=F.cancel;const k=s.watch(()=>f(),w,{deep:O,flush:"post"});return s.onScopeDispose(()=>{k(),r(),i()}),b&&d(),{isAutoSaving:u,blockWatcher:j,unblockWatcher:z,stop:k}}function A(l,p){let n;return{call:()=>{clearTimeout(n),n=setTimeout(()=>l(),p)},cancel:()=>{clearTimeout(n)}}}exports.useAutoSaveForm=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),P=["save","applicationId","isDirty","processing","errors","hasErrors","recentlySuccessful","wasSuccessful","data","transform","get","post","put","patch","delete","cancel","reset","clearErrors","setError","setData"];function q(c,h){const{debounce:n=3e3,skipFields:T=[],skipInertiaFields:I=!0,deep:O=!0,debug:u=!1,serialize:D=JSON.stringify,compare:o,saveOnInit:g=!1,onSave:W,onBeforeSave:m,onAfterSave:y,onError:l}=h,a=s.ref(!1),r=s.ref(!0);let i=()=>{},f=()=>{};const j=(t=1e3)=>{r.value=!1,i(),f(),setTimeout(()=>{r.value=!0},t)},z=(t=null)=>{if(r.value=!0,i(),f(),t===null)d(),o?p=null:v=null,S();else{const e=A(S,t);f=e.cancel,e.call()}},d=()=>{const t=s.isRef(c)?s.unref(c):c,e={};for(const b of Object.keys(t))I&&P.includes(b)||T.includes(b)||(e[b]=t[b]);return e};let v=g?null:D(d()),p=o?g?null:d():null;const S=()=>{if(!r.value)return;const t=d();if(o){if(p&&o(p,t))return;p=t}else{const e=D(t);if(v!==null&&e===v)return;v=e}u&&console.log("[AutoSave] Detected changes. Saving..."),a.value=!0;try{m==null||m(),Promise.resolve(W()).then(()=>{y==null||y(),u&&console.log("[AutoSave] Save successful.")}).catch(e=>{l==null||l(e),u&&console.error("[AutoSave] Save failed:",e)}).finally(()=>{a.value=!1})}catch(e){l==null||l(e),u&&console.error("[AutoSave] Immediate error:",e),a.value=!1}},F=A(S,n),w=F.call;i=F.cancel;const k=s.watch(c,w,{deep:O,flush:"post"});return s.onScopeDispose(()=>{k(),i(),f()}),g&&S(),{isAutoSaving:a,blockWatcher:j,unblockWatcher:z,stop:k}}function A(c,h){let n;return{call:()=>{clearTimeout(n),n=setTimeout(()=>c(),h)},cancel:()=>{clearTimeout(n)}}}exports.useAutoSaveForm=q;
@@ -21,69 +21,69 @@ const R = [
21
21
  "setError",
22
22
  "setData"
23
23
  ];
24
- function C(s, v) {
24
+ function C(c, h) {
25
25
  const {
26
- debounce: l = 3e3,
26
+ debounce: s = 3e3,
27
27
  skipFields: I = [],
28
28
  skipInertiaFields: T = !0,
29
29
  deep: O = !0,
30
30
  debug: n = !1,
31
31
  serialize: y = JSON.stringify,
32
- compare: p,
33
- saveOnInit: S = !1,
32
+ compare: o,
33
+ saveOnInit: b = !1,
34
34
  onSave: W,
35
- onBeforeSave: h,
36
- onAfterSave: m,
37
- onError: c
38
- } = v, o = F(!1), a = F(!0);
39
- let u = () => {
40
- }, r = () => {
35
+ onBeforeSave: m,
36
+ onAfterSave: g,
37
+ onError: l
38
+ } = h, u = F(!1), a = F(!0);
39
+ let r = () => {
40
+ }, i = () => {
41
41
  };
42
42
  const z = (t = 1e3) => {
43
- a.value = !1, u(), r(), setTimeout(() => {
43
+ a.value = !1, r(), i(), setTimeout(() => {
44
44
  a.value = !0;
45
45
  }, t);
46
46
  }, j = (t = null) => {
47
- if (a.value = !0, u(), r(), t === null)
48
- f();
47
+ if (a.value = !0, r(), i(), t === null)
48
+ f(), o ? v = null : d = null, p();
49
49
  else {
50
- const e = A(f, t);
51
- r = e.cancel, e.call();
50
+ const e = A(p, t);
51
+ i = e.cancel, e.call();
52
52
  }
53
- }, i = () => {
54
- const t = N(s) ? P(s) : s, e = {};
55
- for (const d of Object.keys(t))
56
- T && R.includes(d) || I.includes(d) || (e[d] = t[d]);
53
+ }, f = () => {
54
+ const t = N(c) ? P(c) : c, e = {};
55
+ for (const S of Object.keys(t))
56
+ T && R.includes(S) || I.includes(S) || (e[S] = t[S]);
57
57
  return e;
58
58
  };
59
- let b = S ? null : y(i()), g = p ? S ? null : i() : null;
60
- const f = () => {
59
+ let d = b ? null : y(f()), v = o ? b ? null : f() : null;
60
+ const p = () => {
61
61
  if (!a.value) return;
62
- const t = i();
63
- if (p) {
64
- if (g && p(g, t)) return;
65
- g = t;
62
+ const t = f();
63
+ if (o) {
64
+ if (v && o(v, t)) return;
65
+ v = t;
66
66
  } else {
67
67
  const e = y(t);
68
- if (b !== null && e === b) return;
69
- b = e;
68
+ if (d !== null && e === d) return;
69
+ d = e;
70
70
  }
71
- n && console.log("[AutoSave] Detected changes. Saving..."), o.value = !0;
71
+ n && console.log("[AutoSave] Detected changes. Saving..."), u.value = !0;
72
72
  try {
73
- h == null || h(), Promise.resolve(W()).then(() => {
74
- m == null || m(), n && console.log("[AutoSave] Save successful.");
73
+ m == null || m(), Promise.resolve(W()).then(() => {
74
+ g == null || g(), n && console.log("[AutoSave] Save successful.");
75
75
  }).catch((e) => {
76
- c == null || c(e), n && console.error("[AutoSave] Save failed:", e);
76
+ l == null || l(e), n && console.error("[AutoSave] Save failed:", e);
77
77
  }).finally(() => {
78
- o.value = !1;
78
+ u.value = !1;
79
79
  });
80
80
  } catch (e) {
81
- c == null || c(e), n && console.error("[AutoSave] Immediate error:", e), o.value = !1;
81
+ l == null || l(e), n && console.error("[AutoSave] Immediate error:", e), u.value = !1;
82
82
  }
83
- }, D = A(f, l), w = D.call;
84
- u = D.cancel;
83
+ }, D = A(p, s), w = D.call;
84
+ r = D.cancel;
85
85
  const k = x(
86
- () => i(),
86
+ c,
87
87
  w,
88
88
  {
89
89
  deep: O,
@@ -91,22 +91,22 @@ function C(s, v) {
91
91
  }
92
92
  );
93
93
  return J(() => {
94
- k(), u(), r();
95
- }), S && f(), {
96
- isAutoSaving: o,
94
+ k(), r(), i();
95
+ }), b && p(), {
96
+ isAutoSaving: u,
97
97
  blockWatcher: z,
98
98
  unblockWatcher: j,
99
99
  stop: k
100
100
  };
101
101
  }
102
- function A(s, v) {
103
- let l;
102
+ function A(c, h) {
103
+ let s;
104
104
  return {
105
105
  call: () => {
106
- clearTimeout(l), l = setTimeout(() => s(), v);
106
+ clearTimeout(s), s = setTimeout(() => c(), h);
107
107
  },
108
108
  cancel: () => {
109
- clearTimeout(l);
109
+ clearTimeout(s);
110
110
  }
111
111
  };
112
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provydon/vue-auto-save",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A Vue 3 composable that autosaves forms with debounce, optional field skipping, and blockable watchers.",
5
5
  "main": "./dist/useAutoSaveForm.cjs",
6
6
  "module": "./dist/useAutoSaveForm.mjs",