@stonecrop/stonecrop 0.6.1 → 0.6.3
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/composable.js +348 -0
- package/dist/composables/operation-log.js +221 -0
- package/dist/doctype.js +73 -0
- package/dist/exceptions.js +16 -0
- package/dist/field-triggers.js +564 -0
- package/dist/index.js +18 -0
- package/dist/operation-log-DB-dGNT9.js +593 -0
- package/dist/operation-log-DB-dGNT9.js.map +1 -0
- package/dist/plugins/index.js +90 -0
- package/dist/registry.js +72 -0
- package/dist/src/stores/data.d.ts +11 -0
- package/dist/src/stores/data.d.ts.map +1 -0
- package/dist/src/stores/xstate.d.ts +31 -0
- package/dist/src/stores/xstate.d.ts.map +1 -0
- package/dist/src/tsdoc-metadata.json +1 -1
- package/dist/stonecrop.d.ts +47 -58
- package/dist/stonecrop.js +851 -859
- package/dist/stonecrop.js.map +1 -1
- package/dist/stonecrop.umd.cjs +3 -7
- package/dist/stonecrop.umd.cjs.map +1 -1
- package/dist/stores/data.js +7 -0
- package/dist/stores/hst.js +483 -0
- package/dist/stores/index.js +12 -0
- package/dist/stores/operation-log.js +571 -0
- package/dist/stores/xstate.js +29 -0
- package/dist/types/field-triggers.js +4 -0
- package/dist/types/index.js +4 -0
- package/dist/types/operation-log.js +0 -0
- package/dist/types/registry.js +0 -0
- package/package.json +4 -4
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import { hasInjectionContext as ye, inject as me, getCurrentInstance as be, ref as D, reactive as ge, markRaw as M, effectScope as Ee, isRef as J, isReactive as oe, toRef as G, toRaw as _e, nextTick as se, computed as x, getCurrentScope as Oe, onScopeDispose as Ne, watch as fe, toRefs as ae } from "vue";
|
|
2
|
+
/*!
|
|
3
|
+
* pinia v3.0.3
|
|
4
|
+
* (c) 2025 Eduardo San Martin Morote
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
let A;
|
|
8
|
+
const z = (e) => A = e, we = process.env.NODE_ENV !== "production" ? Symbol("pinia") : (
|
|
9
|
+
/* istanbul ignore next */
|
|
10
|
+
Symbol()
|
|
11
|
+
);
|
|
12
|
+
function R(e) {
|
|
13
|
+
return e && typeof e == "object" && Object.prototype.toString.call(e) === "[object Object]" && typeof e.toJSON != "function";
|
|
14
|
+
}
|
|
15
|
+
var W;
|
|
16
|
+
(function(e) {
|
|
17
|
+
e.direct = "direct", e.patchObject = "patch object", e.patchFunction = "patch function";
|
|
18
|
+
})(W || (W = {}));
|
|
19
|
+
const L = typeof window < "u";
|
|
20
|
+
function pe(e, o) {
|
|
21
|
+
for (const r in o) {
|
|
22
|
+
const s = o[r];
|
|
23
|
+
if (!(r in e))
|
|
24
|
+
continue;
|
|
25
|
+
const f = e[r];
|
|
26
|
+
R(f) && R(s) && !J(s) && !oe(s) ? e[r] = pe(f, s) : e[r] = s;
|
|
27
|
+
}
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
const de = () => {
|
|
31
|
+
};
|
|
32
|
+
function ce(e, o, r, s = de) {
|
|
33
|
+
e.push(o);
|
|
34
|
+
const f = () => {
|
|
35
|
+
const d = e.indexOf(o);
|
|
36
|
+
d > -1 && (e.splice(d, 1), s());
|
|
37
|
+
};
|
|
38
|
+
return !r && Oe() && Ne(f), f;
|
|
39
|
+
}
|
|
40
|
+
function $(e, ...o) {
|
|
41
|
+
e.slice().forEach((r) => {
|
|
42
|
+
r(...o);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const Se = (e) => e(), ie = Symbol(), K = Symbol();
|
|
46
|
+
function te(e, o) {
|
|
47
|
+
e instanceof Map && o instanceof Map ? o.forEach((r, s) => e.set(s, r)) : e instanceof Set && o instanceof Set && o.forEach(e.add, e);
|
|
48
|
+
for (const r in o) {
|
|
49
|
+
if (!o.hasOwnProperty(r))
|
|
50
|
+
continue;
|
|
51
|
+
const s = o[r], f = e[r];
|
|
52
|
+
R(f) && R(s) && e.hasOwnProperty(r) && !J(s) && !oe(s) ? e[r] = te(f, s) : e[r] = s;
|
|
53
|
+
}
|
|
54
|
+
return e;
|
|
55
|
+
}
|
|
56
|
+
const De = process.env.NODE_ENV !== "production" ? Symbol("pinia:skipHydration") : (
|
|
57
|
+
/* istanbul ignore next */
|
|
58
|
+
Symbol()
|
|
59
|
+
);
|
|
60
|
+
function Ie(e) {
|
|
61
|
+
return !R(e) || !Object.prototype.hasOwnProperty.call(e, De);
|
|
62
|
+
}
|
|
63
|
+
const { assign: N } = Object;
|
|
64
|
+
function ue(e) {
|
|
65
|
+
return !!(J(e) && e.effect);
|
|
66
|
+
}
|
|
67
|
+
function le(e, o, r, s) {
|
|
68
|
+
const { state: f, actions: d, getters: l } = o, m = r.state.value[e];
|
|
69
|
+
let w;
|
|
70
|
+
function h() {
|
|
71
|
+
!m && (process.env.NODE_ENV === "production" || !s) && (r.state.value[e] = f ? f() : {});
|
|
72
|
+
const v = process.env.NODE_ENV !== "production" && s ? (
|
|
73
|
+
// use ref() to unwrap refs inside state TODO: check if this is still necessary
|
|
74
|
+
ae(D(f ? f() : {}).value)
|
|
75
|
+
) : ae(r.state.value[e]);
|
|
76
|
+
return N(v, d, Object.keys(l || {}).reduce((b, _) => (process.env.NODE_ENV !== "production" && _ in v && console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${_}" in store "${e}".`), b[_] = M(x(() => {
|
|
77
|
+
z(r);
|
|
78
|
+
const O = r._s.get(e);
|
|
79
|
+
return l[_].call(O, O);
|
|
80
|
+
})), b), {}));
|
|
81
|
+
}
|
|
82
|
+
return w = ne(e, h, o, r, s, !0), w;
|
|
83
|
+
}
|
|
84
|
+
function ne(e, o, r = {}, s, f, d) {
|
|
85
|
+
let l;
|
|
86
|
+
const m = N({ actions: {} }, r);
|
|
87
|
+
if (process.env.NODE_ENV !== "production" && !s._e.active)
|
|
88
|
+
throw new Error("Pinia destroyed");
|
|
89
|
+
const w = { deep: !0 };
|
|
90
|
+
process.env.NODE_ENV !== "production" && (w.onTrigger = (c) => {
|
|
91
|
+
h ? O = c : h == !1 && !u._hotUpdating && (Array.isArray(O) ? O.push(c) : console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."));
|
|
92
|
+
});
|
|
93
|
+
let h, v, b = [], _ = [], O;
|
|
94
|
+
const I = s.state.value[e];
|
|
95
|
+
!d && !I && (process.env.NODE_ENV === "production" || !f) && (s.state.value[e] = {});
|
|
96
|
+
const B = D({});
|
|
97
|
+
let H;
|
|
98
|
+
function q(c) {
|
|
99
|
+
let n;
|
|
100
|
+
h = v = !1, process.env.NODE_ENV !== "production" && (O = []), typeof c == "function" ? (c(s.state.value[e]), n = {
|
|
101
|
+
type: W.patchFunction,
|
|
102
|
+
storeId: e,
|
|
103
|
+
events: O
|
|
104
|
+
}) : (te(s.state.value[e], c), n = {
|
|
105
|
+
type: W.patchObject,
|
|
106
|
+
payload: c,
|
|
107
|
+
storeId: e,
|
|
108
|
+
events: O
|
|
109
|
+
});
|
|
110
|
+
const p = H = Symbol();
|
|
111
|
+
se().then(() => {
|
|
112
|
+
H === p && (h = !0);
|
|
113
|
+
}), v = !0, $(b, n, s.state.value[e]);
|
|
114
|
+
}
|
|
115
|
+
const Q = d ? function() {
|
|
116
|
+
const { state: n } = r, p = n ? n() : {};
|
|
117
|
+
this.$patch((g) => {
|
|
118
|
+
N(g, p);
|
|
119
|
+
});
|
|
120
|
+
} : (
|
|
121
|
+
/* istanbul ignore next */
|
|
122
|
+
process.env.NODE_ENV !== "production" ? () => {
|
|
123
|
+
throw new Error(`🍍: Store "${e}" is built using the setup syntax and does not implement $reset().`);
|
|
124
|
+
} : de
|
|
125
|
+
);
|
|
126
|
+
function X() {
|
|
127
|
+
l.stop(), b = [], _ = [], s._s.delete(e);
|
|
128
|
+
}
|
|
129
|
+
const T = (c, n = "") => {
|
|
130
|
+
if (ie in c)
|
|
131
|
+
return c[K] = n, c;
|
|
132
|
+
const p = function() {
|
|
133
|
+
z(s);
|
|
134
|
+
const g = Array.from(arguments), C = [], F = [];
|
|
135
|
+
function Y(E) {
|
|
136
|
+
C.push(E);
|
|
137
|
+
}
|
|
138
|
+
function Z(E) {
|
|
139
|
+
F.push(E);
|
|
140
|
+
}
|
|
141
|
+
$(_, {
|
|
142
|
+
args: g,
|
|
143
|
+
name: p[K],
|
|
144
|
+
store: u,
|
|
145
|
+
after: Y,
|
|
146
|
+
onError: Z
|
|
147
|
+
});
|
|
148
|
+
let V;
|
|
149
|
+
try {
|
|
150
|
+
V = c.apply(this && this.$id === e ? this : u, g);
|
|
151
|
+
} catch (E) {
|
|
152
|
+
throw $(F, E), E;
|
|
153
|
+
}
|
|
154
|
+
return V instanceof Promise ? V.then((E) => ($(C, E), E)).catch((E) => ($(F, E), Promise.reject(E))) : ($(C, V), V);
|
|
155
|
+
};
|
|
156
|
+
return p[ie] = !0, p[K] = n, p;
|
|
157
|
+
}, P = /* @__PURE__ */ M({
|
|
158
|
+
actions: {},
|
|
159
|
+
getters: {},
|
|
160
|
+
state: [],
|
|
161
|
+
hotState: B
|
|
162
|
+
}), U = {
|
|
163
|
+
_p: s,
|
|
164
|
+
// _s: scope,
|
|
165
|
+
$id: e,
|
|
166
|
+
$onAction: ce.bind(null, _),
|
|
167
|
+
$patch: q,
|
|
168
|
+
$reset: Q,
|
|
169
|
+
$subscribe(c, n = {}) {
|
|
170
|
+
const p = ce(b, c, n.detached, () => g()), g = l.run(() => fe(() => s.state.value[e], (C) => {
|
|
171
|
+
(n.flush === "sync" ? v : h) && c({
|
|
172
|
+
storeId: e,
|
|
173
|
+
type: W.direct,
|
|
174
|
+
events: O
|
|
175
|
+
}, C);
|
|
176
|
+
}, N({}, w, n)));
|
|
177
|
+
return p;
|
|
178
|
+
},
|
|
179
|
+
$dispose: X
|
|
180
|
+
}, u = ge(process.env.NODE_ENV !== "production" || process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && L ? N(
|
|
181
|
+
{
|
|
182
|
+
_hmrPayload: P,
|
|
183
|
+
_customProperties: M(/* @__PURE__ */ new Set())
|
|
184
|
+
// devtools custom properties
|
|
185
|
+
},
|
|
186
|
+
U
|
|
187
|
+
// must be added later
|
|
188
|
+
// setupStore
|
|
189
|
+
) : U);
|
|
190
|
+
s._s.set(e, u);
|
|
191
|
+
const S = (s._a && s._a.runWithContext || Se)(() => s._e.run(() => (l = Ee()).run(() => o({ action: T }))));
|
|
192
|
+
for (const c in S) {
|
|
193
|
+
const n = S[c];
|
|
194
|
+
if (J(n) && !ue(n) || oe(n))
|
|
195
|
+
process.env.NODE_ENV !== "production" && f ? B.value[c] = G(S, c) : d || (I && Ie(n) && (J(n) ? n.value = I[c] : te(n, I[c])), s.state.value[e][c] = n), process.env.NODE_ENV !== "production" && P.state.push(c);
|
|
196
|
+
else if (typeof n == "function") {
|
|
197
|
+
const p = process.env.NODE_ENV !== "production" && f ? n : T(n, c);
|
|
198
|
+
S[c] = p, process.env.NODE_ENV !== "production" && (P.actions[c] = n), m.actions[c] = n;
|
|
199
|
+
} else process.env.NODE_ENV !== "production" && ue(n) && (P.getters[c] = d ? (
|
|
200
|
+
// @ts-expect-error
|
|
201
|
+
r.getters[c]
|
|
202
|
+
) : n, L && (S._getters || // @ts-expect-error: same
|
|
203
|
+
(S._getters = M([]))).push(c));
|
|
204
|
+
}
|
|
205
|
+
if (N(u, S), N(_e(u), S), Object.defineProperty(u, "$state", {
|
|
206
|
+
get: () => process.env.NODE_ENV !== "production" && f ? B.value : s.state.value[e],
|
|
207
|
+
set: (c) => {
|
|
208
|
+
if (process.env.NODE_ENV !== "production" && f)
|
|
209
|
+
throw new Error("cannot set hotState");
|
|
210
|
+
q((n) => {
|
|
211
|
+
N(n, c);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}), process.env.NODE_ENV !== "production" && (u._hotUpdate = M((c) => {
|
|
215
|
+
u._hotUpdating = !0, c._hmrPayload.state.forEach((n) => {
|
|
216
|
+
if (n in u.$state) {
|
|
217
|
+
const p = c.$state[n], g = u.$state[n];
|
|
218
|
+
typeof p == "object" && R(p) && R(g) ? pe(p, g) : c.$state[n] = g;
|
|
219
|
+
}
|
|
220
|
+
u[n] = G(c.$state, n);
|
|
221
|
+
}), Object.keys(u.$state).forEach((n) => {
|
|
222
|
+
n in c.$state || delete u[n];
|
|
223
|
+
}), h = !1, v = !1, s.state.value[e] = G(c._hmrPayload, "hotState"), v = !0, se().then(() => {
|
|
224
|
+
h = !0;
|
|
225
|
+
});
|
|
226
|
+
for (const n in c._hmrPayload.actions) {
|
|
227
|
+
const p = c[n];
|
|
228
|
+
u[n] = //
|
|
229
|
+
T(p, n);
|
|
230
|
+
}
|
|
231
|
+
for (const n in c._hmrPayload.getters) {
|
|
232
|
+
const p = c._hmrPayload.getters[n], g = d ? (
|
|
233
|
+
// special handling of options api
|
|
234
|
+
x(() => (z(s), p.call(u, u)))
|
|
235
|
+
) : p;
|
|
236
|
+
u[n] = //
|
|
237
|
+
g;
|
|
238
|
+
}
|
|
239
|
+
Object.keys(u._hmrPayload.getters).forEach((n) => {
|
|
240
|
+
n in c._hmrPayload.getters || delete u[n];
|
|
241
|
+
}), Object.keys(u._hmrPayload.actions).forEach((n) => {
|
|
242
|
+
n in c._hmrPayload.actions || delete u[n];
|
|
243
|
+
}), u._hmrPayload = c._hmrPayload, u._getters = c._getters, u._hotUpdating = !1;
|
|
244
|
+
})), process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && L) {
|
|
245
|
+
const c = {
|
|
246
|
+
writable: !0,
|
|
247
|
+
configurable: !0,
|
|
248
|
+
// avoid warning on devtools trying to display this property
|
|
249
|
+
enumerable: !1
|
|
250
|
+
};
|
|
251
|
+
["_p", "_hmrPayload", "_getters", "_customProperties"].forEach((n) => {
|
|
252
|
+
Object.defineProperty(u, n, N({ value: u[n] }, c));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return s._p.forEach((c) => {
|
|
256
|
+
if (process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && L) {
|
|
257
|
+
const n = l.run(() => c({
|
|
258
|
+
store: u,
|
|
259
|
+
app: s._a,
|
|
260
|
+
pinia: s,
|
|
261
|
+
options: m
|
|
262
|
+
}));
|
|
263
|
+
Object.keys(n || {}).forEach((p) => u._customProperties.add(p)), N(u, n);
|
|
264
|
+
} else
|
|
265
|
+
N(u, l.run(() => c({
|
|
266
|
+
store: u,
|
|
267
|
+
app: s._a,
|
|
268
|
+
pinia: s,
|
|
269
|
+
options: m
|
|
270
|
+
})));
|
|
271
|
+
}), process.env.NODE_ENV !== "production" && u.$state && typeof u.$state == "object" && typeof u.$state.constructor == "function" && !u.$state.constructor.toString().includes("[native code]") && console.warn(`[🍍]: The "state" must be a plain object. It cannot be
|
|
272
|
+
state: () => new MyClass()
|
|
273
|
+
Found in store "${u.$id}".`), I && d && r.hydrate && r.hydrate(u.$state, I), h = !0, v = !0, u;
|
|
274
|
+
}
|
|
275
|
+
/*! #__NO_SIDE_EFFECTS__ */
|
|
276
|
+
// @__NO_SIDE_EFFECTS__
|
|
277
|
+
function Pe(e, o, r) {
|
|
278
|
+
let s;
|
|
279
|
+
const f = typeof o == "function";
|
|
280
|
+
s = f ? r : o;
|
|
281
|
+
function d(l, m) {
|
|
282
|
+
const w = ye();
|
|
283
|
+
if (l = // in test mode, ignore the argument provided as we can always retrieve a
|
|
284
|
+
// pinia instance with getActivePinia()
|
|
285
|
+
(process.env.NODE_ENV === "test" && A && A._testing ? null : l) || (w ? me(we, null) : null), l && z(l), process.env.NODE_ENV !== "production" && !A)
|
|
286
|
+
throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?
|
|
287
|
+
See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.
|
|
288
|
+
This will fail in production.`);
|
|
289
|
+
l = A, l._s.has(e) || (f ? ne(e, o, s, l) : le(e, s, l), process.env.NODE_ENV !== "production" && (d._pinia = l));
|
|
290
|
+
const h = l._s.get(e);
|
|
291
|
+
if (process.env.NODE_ENV !== "production" && m) {
|
|
292
|
+
const v = "__hot:" + e, b = f ? ne(v, o, s, l, !0) : le(v, N({}, s), l, !0);
|
|
293
|
+
m._hotUpdate(b), delete l.state.value[v], l._s.delete(v);
|
|
294
|
+
}
|
|
295
|
+
if (process.env.NODE_ENV !== "production" && L) {
|
|
296
|
+
const v = be();
|
|
297
|
+
if (v && v.proxy && // avoid adding stores that are just built for hot module replacement
|
|
298
|
+
!m) {
|
|
299
|
+
const b = v.proxy, _ = "_pStores" in b ? b._pStores : b._pStores = {};
|
|
300
|
+
_[e] = h;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return h;
|
|
304
|
+
}
|
|
305
|
+
return d.$id = e, d;
|
|
306
|
+
}
|
|
307
|
+
function ee() {
|
|
308
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
309
|
+
}
|
|
310
|
+
const Ve = /* @__PURE__ */ Pe("hst-operation-log", () => {
|
|
311
|
+
const e = D({
|
|
312
|
+
maxOperations: 100,
|
|
313
|
+
enableCrossTabSync: !0,
|
|
314
|
+
enableServerSync: !1,
|
|
315
|
+
autoSyncInterval: 3e4,
|
|
316
|
+
enablePersistence: !1,
|
|
317
|
+
persistenceKeyPrefix: "stonecrop-ops"
|
|
318
|
+
}), o = D([]), r = D(-1), s = D(ee()), f = D(/* @__PURE__ */ new Date()), d = D(!1), l = D([]), m = D(null), w = x(() => r.value < 0 ? !1 : o.value[r.value]?.reversible ?? !1), h = x(() => r.value < o.value.length - 1), v = x(() => {
|
|
319
|
+
let a = 0;
|
|
320
|
+
for (let t = r.value; t >= 0 && o.value[t]?.reversible; t--)
|
|
321
|
+
a++;
|
|
322
|
+
return a;
|
|
323
|
+
}), b = x(() => o.value.length - 1 - r.value), _ = x(() => ({
|
|
324
|
+
canUndo: w.value,
|
|
325
|
+
canRedo: h.value,
|
|
326
|
+
undoCount: v.value,
|
|
327
|
+
redoCount: b.value,
|
|
328
|
+
currentIndex: r.value
|
|
329
|
+
}));
|
|
330
|
+
function O(a) {
|
|
331
|
+
e.value = { ...e.value, ...a }, e.value.enablePersistence && (V(), ve()), e.value.enableCrossTabSync && g(), e.value.enableServerSync && e.value.autoSyncInterval && he();
|
|
332
|
+
}
|
|
333
|
+
function I(a, t = "user") {
|
|
334
|
+
const i = {
|
|
335
|
+
...a,
|
|
336
|
+
id: ee(),
|
|
337
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
338
|
+
source: t,
|
|
339
|
+
userId: e.value.userId
|
|
340
|
+
};
|
|
341
|
+
if (e.value.operationFilter && !e.value.operationFilter(i))
|
|
342
|
+
return i.id;
|
|
343
|
+
if (d.value)
|
|
344
|
+
return l.value.push(i), i.id;
|
|
345
|
+
if (r.value < o.value.length - 1 && (o.value = o.value.slice(0, r.value + 1)), o.value.push(i), r.value++, e.value.maxOperations && o.value.length > e.value.maxOperations) {
|
|
346
|
+
const y = o.value.length - e.value.maxOperations;
|
|
347
|
+
o.value = o.value.slice(y), r.value -= y;
|
|
348
|
+
}
|
|
349
|
+
return e.value.enableCrossTabSync && C(i), i.id;
|
|
350
|
+
}
|
|
351
|
+
function B() {
|
|
352
|
+
d.value = !0, l.value = [], m.value = ee();
|
|
353
|
+
}
|
|
354
|
+
function H(a) {
|
|
355
|
+
if (!d.value || l.value.length === 0)
|
|
356
|
+
return d.value = !1, l.value = [], m.value = null, null;
|
|
357
|
+
const t = m.value, i = l.value.every((j) => j.reversible), y = {
|
|
358
|
+
id: t,
|
|
359
|
+
type: "batch",
|
|
360
|
+
path: "",
|
|
361
|
+
// Batch doesn't have a single path
|
|
362
|
+
fieldname: "",
|
|
363
|
+
beforeValue: null,
|
|
364
|
+
afterValue: null,
|
|
365
|
+
doctype: l.value[0]?.doctype || "",
|
|
366
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
367
|
+
source: "user",
|
|
368
|
+
reversible: i,
|
|
369
|
+
irreversibleReason: i ? void 0 : "Contains irreversible operations",
|
|
370
|
+
childOperationIds: l.value.map((j) => j.id),
|
|
371
|
+
metadata: { description: a }
|
|
372
|
+
};
|
|
373
|
+
l.value.forEach((j) => {
|
|
374
|
+
j.parentOperationId = t;
|
|
375
|
+
}), o.value.push(...l.value, y), r.value = o.value.length - 1, e.value.enableCrossTabSync && F(l.value, y);
|
|
376
|
+
const k = t;
|
|
377
|
+
return d.value = !1, l.value = [], m.value = null, k;
|
|
378
|
+
}
|
|
379
|
+
function q() {
|
|
380
|
+
d.value = !1, l.value = [], m.value = null;
|
|
381
|
+
}
|
|
382
|
+
function Q(a) {
|
|
383
|
+
if (!w.value) return !1;
|
|
384
|
+
const t = o.value[r.value];
|
|
385
|
+
if (!t.reversible)
|
|
386
|
+
return typeof console < "u" && t.irreversibleReason && console.warn("Cannot undo irreversible operation:", t.irreversibleReason), !1;
|
|
387
|
+
try {
|
|
388
|
+
if (t.type === "batch" && t.childOperationIds)
|
|
389
|
+
for (let i = t.childOperationIds.length - 1; i >= 0; i--) {
|
|
390
|
+
const y = t.childOperationIds[i], k = o.value.find((j) => j.id === y);
|
|
391
|
+
k && T(k, a);
|
|
392
|
+
}
|
|
393
|
+
else
|
|
394
|
+
T(t, a);
|
|
395
|
+
return r.value--, e.value.enableCrossTabSync && Y(t), !0;
|
|
396
|
+
} catch (i) {
|
|
397
|
+
return typeof console < "u" && console.error("Undo failed:", i), !1;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function X(a) {
|
|
401
|
+
if (!h.value) return !1;
|
|
402
|
+
const t = o.value[r.value + 1];
|
|
403
|
+
try {
|
|
404
|
+
if (t.type === "batch" && t.childOperationIds)
|
|
405
|
+
for (const i of t.childOperationIds) {
|
|
406
|
+
const y = o.value.find((k) => k.id === i);
|
|
407
|
+
y && P(y, a);
|
|
408
|
+
}
|
|
409
|
+
else
|
|
410
|
+
P(t, a);
|
|
411
|
+
return r.value++, e.value.enableCrossTabSync && Z(t), !0;
|
|
412
|
+
} catch (i) {
|
|
413
|
+
return typeof console < "u" && console.error("Redo failed:", i), !1;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function T(a, t) {
|
|
417
|
+
a.type === "set" && t && typeof t.set == "function" && t.set(a.path, a.beforeValue);
|
|
418
|
+
}
|
|
419
|
+
function P(a, t) {
|
|
420
|
+
a.type === "set" && t && typeof t.set == "function" && t.set(a.path, a.afterValue);
|
|
421
|
+
}
|
|
422
|
+
function U(a) {
|
|
423
|
+
return o.value.filter((t) => t.timestamp > a && t.source !== "sync");
|
|
424
|
+
}
|
|
425
|
+
function u() {
|
|
426
|
+
return {
|
|
427
|
+
operations: U(f.value),
|
|
428
|
+
lastSyncTimestamp: f.value,
|
|
429
|
+
currentTimestamp: /* @__PURE__ */ new Date(),
|
|
430
|
+
clientId: s.value
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function re(a) {
|
|
434
|
+
a.operations.forEach((t) => {
|
|
435
|
+
const i = { ...t, source: "sync" };
|
|
436
|
+
o.value.push(i);
|
|
437
|
+
}), f.value = a.currentTimestamp, r.value = o.value.length - 1;
|
|
438
|
+
}
|
|
439
|
+
function S() {
|
|
440
|
+
const a = o.value.filter((i) => i.reversible).length, t = o.value.map((i) => i.timestamp);
|
|
441
|
+
return {
|
|
442
|
+
operations: [...o.value],
|
|
443
|
+
currentIndex: r.value,
|
|
444
|
+
totalOperations: o.value.length,
|
|
445
|
+
reversibleOperations: a,
|
|
446
|
+
irreversibleOperations: o.value.length - a,
|
|
447
|
+
oldestOperation: t.length > 0 ? new Date(Math.min(...t.map((i) => i.getTime()))) : void 0,
|
|
448
|
+
newestOperation: t.length > 0 ? new Date(Math.max(...t.map((i) => i.getTime()))) : void 0
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function c() {
|
|
452
|
+
o.value = [], r.value = -1, f.value = /* @__PURE__ */ new Date();
|
|
453
|
+
}
|
|
454
|
+
function n(a, t) {
|
|
455
|
+
return o.value.filter(
|
|
456
|
+
(i) => i.doctype === a && (t === void 0 || i.recordId === t)
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
function p(a, t) {
|
|
460
|
+
const i = o.value.find((y) => y.id === a);
|
|
461
|
+
i && (i.reversible = !1, i.irreversibleReason = t);
|
|
462
|
+
}
|
|
463
|
+
function g() {
|
|
464
|
+
if (typeof window > "u" || !window.BroadcastChannel) return;
|
|
465
|
+
new BroadcastChannel("stonecrop-operation-log").addEventListener("message", (t) => {
|
|
466
|
+
const i = t.data;
|
|
467
|
+
i.clientId !== s.value && i.type === "operation" && i.operation && (o.value.push({ ...i.operation, source: "sync" }), r.value = o.value.length - 1);
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
function C(a) {
|
|
471
|
+
if (typeof window > "u" || !window.BroadcastChannel) return;
|
|
472
|
+
const t = new BroadcastChannel("stonecrop-operation-log"), i = {
|
|
473
|
+
type: "operation",
|
|
474
|
+
operation: a,
|
|
475
|
+
clientId: s.value,
|
|
476
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
477
|
+
};
|
|
478
|
+
t.postMessage(i);
|
|
479
|
+
}
|
|
480
|
+
function F(a, t) {
|
|
481
|
+
if (typeof window > "u" || !window.BroadcastChannel) return;
|
|
482
|
+
const i = new BroadcastChannel("stonecrop-operation-log"), y = {
|
|
483
|
+
type: "operation",
|
|
484
|
+
operations: [...a, t],
|
|
485
|
+
clientId: s.value,
|
|
486
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
487
|
+
};
|
|
488
|
+
i.postMessage(y);
|
|
489
|
+
}
|
|
490
|
+
function Y(a) {
|
|
491
|
+
if (typeof window > "u" || !window.BroadcastChannel) return;
|
|
492
|
+
const t = new BroadcastChannel("stonecrop-operation-log"), i = {
|
|
493
|
+
type: "undo",
|
|
494
|
+
operation: a,
|
|
495
|
+
clientId: s.value,
|
|
496
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
497
|
+
};
|
|
498
|
+
t.postMessage(i);
|
|
499
|
+
}
|
|
500
|
+
function Z(a) {
|
|
501
|
+
if (typeof window > "u" || !window.BroadcastChannel) return;
|
|
502
|
+
const t = new BroadcastChannel("stonecrop-operation-log"), i = {
|
|
503
|
+
type: "redo",
|
|
504
|
+
operation: a,
|
|
505
|
+
clientId: s.value,
|
|
506
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
507
|
+
};
|
|
508
|
+
t.postMessage(i);
|
|
509
|
+
}
|
|
510
|
+
function V() {
|
|
511
|
+
if (!(typeof window > "u"))
|
|
512
|
+
try {
|
|
513
|
+
const a = `${e.value.persistenceKeyPrefix}-operations`, t = localStorage.getItem(a);
|
|
514
|
+
if (t) {
|
|
515
|
+
const i = JSON.parse(t);
|
|
516
|
+
i && Array.isArray(i.operations) && (o.value = i.operations.map((y) => ({
|
|
517
|
+
...y,
|
|
518
|
+
timestamp: new Date(y.timestamp)
|
|
519
|
+
})), r.value = i.currentIndex ?? -1);
|
|
520
|
+
}
|
|
521
|
+
} catch (a) {
|
|
522
|
+
typeof console < "u" && console.error("Failed to load operations from persistence:", a);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function E() {
|
|
526
|
+
if (!(typeof window > "u"))
|
|
527
|
+
try {
|
|
528
|
+
const a = `${e.value.persistenceKeyPrefix}-operations`, t = {
|
|
529
|
+
operations: o.value,
|
|
530
|
+
currentIndex: r.value
|
|
531
|
+
};
|
|
532
|
+
localStorage.setItem(a, JSON.stringify(t));
|
|
533
|
+
} catch (a) {
|
|
534
|
+
typeof console < "u" && console.error("Failed to save operations to persistence:", a);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function ve() {
|
|
538
|
+
fe(
|
|
539
|
+
[o, r],
|
|
540
|
+
() => {
|
|
541
|
+
e.value.enablePersistence && E();
|
|
542
|
+
},
|
|
543
|
+
{ deep: !0 }
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
function he() {
|
|
547
|
+
!e.value.serverSyncEndpoint || !e.value.autoSyncInterval || setInterval(async () => {
|
|
548
|
+
try {
|
|
549
|
+
const a = u();
|
|
550
|
+
if (a.operations.length === 0) return;
|
|
551
|
+
(await fetch(e.value.serverSyncEndpoint, {
|
|
552
|
+
method: "POST",
|
|
553
|
+
headers: { "Content-Type": "application/json" },
|
|
554
|
+
body: JSON.stringify(a)
|
|
555
|
+
})).ok && (f.value = /* @__PURE__ */ new Date());
|
|
556
|
+
} catch (a) {
|
|
557
|
+
typeof console < "u" && console.error("Server sync failed:", a);
|
|
558
|
+
}
|
|
559
|
+
}, e.value.autoSyncInterval);
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
// State
|
|
563
|
+
operations: o,
|
|
564
|
+
currentIndex: r,
|
|
565
|
+
config: e,
|
|
566
|
+
clientId: s,
|
|
567
|
+
undoRedoState: _,
|
|
568
|
+
// Computed
|
|
569
|
+
canUndo: w,
|
|
570
|
+
canRedo: h,
|
|
571
|
+
undoCount: v,
|
|
572
|
+
redoCount: b,
|
|
573
|
+
// Methods
|
|
574
|
+
configure: O,
|
|
575
|
+
addOperation: I,
|
|
576
|
+
startBatch: B,
|
|
577
|
+
commitBatch: H,
|
|
578
|
+
cancelBatch: q,
|
|
579
|
+
undo: Q,
|
|
580
|
+
redo: X,
|
|
581
|
+
clear: c,
|
|
582
|
+
getOperationsFor: n,
|
|
583
|
+
getOperationsSince: U,
|
|
584
|
+
createSyncDelta: u,
|
|
585
|
+
applySyncDelta: re,
|
|
586
|
+
getSnapshot: S,
|
|
587
|
+
markIrreversible: p
|
|
588
|
+
};
|
|
589
|
+
});
|
|
590
|
+
export {
|
|
591
|
+
Ve as useOperationLogStore
|
|
592
|
+
};
|
|
593
|
+
//# sourceMappingURL=operation-log-DB-dGNT9.js.map
|