@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.
- package/dist/useAutoSaveForm.cjs +1 -1
- package/dist/useAutoSaveForm.mjs +43 -43
- package/package.json +1 -1
package/dist/useAutoSaveForm.cjs
CHANGED
|
@@ -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(
|
|
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;
|
package/dist/useAutoSaveForm.mjs
CHANGED
|
@@ -21,69 +21,69 @@ const R = [
|
|
|
21
21
|
"setError",
|
|
22
22
|
"setData"
|
|
23
23
|
];
|
|
24
|
-
function C(
|
|
24
|
+
function C(c, h) {
|
|
25
25
|
const {
|
|
26
|
-
debounce:
|
|
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:
|
|
33
|
-
saveOnInit:
|
|
32
|
+
compare: o,
|
|
33
|
+
saveOnInit: b = !1,
|
|
34
34
|
onSave: W,
|
|
35
|
-
onBeforeSave:
|
|
36
|
-
onAfterSave:
|
|
37
|
-
onError:
|
|
38
|
-
} =
|
|
39
|
-
let
|
|
40
|
-
},
|
|
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,
|
|
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,
|
|
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(
|
|
51
|
-
|
|
50
|
+
const e = A(p, t);
|
|
51
|
+
i = e.cancel, e.call();
|
|
52
52
|
}
|
|
53
|
-
},
|
|
54
|
-
const t = N(
|
|
55
|
-
for (const
|
|
56
|
-
T && R.includes(
|
|
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
|
|
60
|
-
const
|
|
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 =
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
65
|
-
|
|
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 (
|
|
69
|
-
|
|
68
|
+
if (d !== null && e === d) return;
|
|
69
|
+
d = e;
|
|
70
70
|
}
|
|
71
|
-
n && console.log("[AutoSave] Detected changes. Saving..."),
|
|
71
|
+
n && console.log("[AutoSave] Detected changes. Saving..."), u.value = !0;
|
|
72
72
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
m == null || m(), Promise.resolve(W()).then(() => {
|
|
74
|
+
g == null || g(), n && console.log("[AutoSave] Save successful.");
|
|
75
75
|
}).catch((e) => {
|
|
76
|
-
|
|
76
|
+
l == null || l(e), n && console.error("[AutoSave] Save failed:", e);
|
|
77
77
|
}).finally(() => {
|
|
78
|
-
|
|
78
|
+
u.value = !1;
|
|
79
79
|
});
|
|
80
80
|
} catch (e) {
|
|
81
|
-
|
|
81
|
+
l == null || l(e), n && console.error("[AutoSave] Immediate error:", e), u.value = !1;
|
|
82
82
|
}
|
|
83
|
-
}, D = A(
|
|
84
|
-
|
|
83
|
+
}, D = A(p, s), w = D.call;
|
|
84
|
+
r = D.cancel;
|
|
85
85
|
const k = x(
|
|
86
|
-
|
|
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(),
|
|
95
|
-
}),
|
|
96
|
-
isAutoSaving:
|
|
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(
|
|
103
|
-
let
|
|
102
|
+
function A(c, h) {
|
|
103
|
+
let s;
|
|
104
104
|
return {
|
|
105
105
|
call: () => {
|
|
106
|
-
clearTimeout(
|
|
106
|
+
clearTimeout(s), s = setTimeout(() => c(), h);
|
|
107
107
|
},
|
|
108
108
|
cancel: () => {
|
|
109
|
-
clearTimeout(
|
|
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.
|
|
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",
|