@stonecrop/stonecrop 0.10.2 → 0.10.4
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 +43 -10
- package/dist/{composable.js → composables/stonecrop.js} +3 -4
- package/dist/doctype.js +8 -0
- package/dist/index.js +1 -1
- package/dist/plugins/index.js +8 -2
- package/dist/src/{composable.d.ts → composables/stonecrop.d.ts} +6 -6
- package/dist/src/composables/stonecrop.d.ts.map +1 -0
- package/dist/src/doctype.d.ts +6 -0
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugins/index.d.ts +6 -1
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/stonecrop.d.ts +58 -4
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stores/operation-log.d.ts +1 -1
- package/dist/src/types/index.d.ts +17 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +88 -6
- package/dist/stonecrop.js +315 -255
- package/dist/stonecrop.js.map +1 -1
- package/package.json +6 -5
- package/src/{composable.ts → composables/stonecrop.ts} +8 -9
- package/src/doctype.ts +9 -0
- package/src/index.ts +4 -3
- package/src/plugins/index.ts +8 -2
- package/src/stonecrop.ts +98 -10
- package/src/types/index.ts +17 -0
- package/dist/src/composable.d.ts.map +0 -1
package/dist/stonecrop.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { watch as U, onMounted as
|
|
1
|
+
import { watch as U, onMounted as ve, nextTick as de, readonly as ye, getCurrentInstance as Se, toRef as Pe, customRef as Ie, ref as L, reactive as ue, computed as _, toValue as H, shallowRef as we, unref as Ee, inject as fe, provide as he } from "vue";
|
|
2
2
|
import { defineStore as ke, storeToRefs as be } from "pinia";
|
|
3
3
|
const De = typeof window < "u" && typeof document < "u";
|
|
4
4
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
5
5
|
const Le = Object.prototype.toString, Me = (o) => Le.call(o) === "[object Object]", Re = () => {
|
|
6
6
|
};
|
|
7
7
|
function Fe(...o) {
|
|
8
|
-
if (o.length !== 1) return
|
|
8
|
+
if (o.length !== 1) return Pe(...o);
|
|
9
9
|
const e = o[0];
|
|
10
|
-
return typeof e == "function" ? ye(
|
|
10
|
+
return typeof e == "function" ? ye(Ie(() => ({
|
|
11
11
|
get: e,
|
|
12
12
|
set: Re
|
|
13
13
|
}))) : L(e);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function Ne(o, e) {
|
|
16
16
|
function t(...r) {
|
|
17
17
|
return new Promise((n, i) => {
|
|
18
18
|
Promise.resolve(o(() => e.apply(this, r), {
|
|
@@ -25,7 +25,7 @@ function xe(o, e) {
|
|
|
25
25
|
return t;
|
|
26
26
|
}
|
|
27
27
|
const Ae = (o) => o();
|
|
28
|
-
function
|
|
28
|
+
function xe(o = Ae, e = {}) {
|
|
29
29
|
const { initialState: t = "active" } = e, r = Fe(t === "active");
|
|
30
30
|
function n() {
|
|
31
31
|
r.value = !1;
|
|
@@ -46,17 +46,17 @@ function Ne(o = Ae, e = {}) {
|
|
|
46
46
|
function ce(o) {
|
|
47
47
|
return Array.isArray(o) ? o : [o];
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function _e(o) {
|
|
50
50
|
return Se();
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function Be(o, e, t = {}) {
|
|
53
53
|
const { eventFilter: r = Ae, ...n } = t;
|
|
54
|
-
return U(o,
|
|
54
|
+
return U(o, Ne(r, e), n);
|
|
55
55
|
}
|
|
56
56
|
function Ve(o, e, t = {}) {
|
|
57
|
-
const { eventFilter: r, initialState: n = "active", ...i } = t, { eventFilter: s, pause: a, resume: c, isActive: d } =
|
|
57
|
+
const { eventFilter: r, initialState: n = "active", ...i } = t, { eventFilter: s, pause: a, resume: c, isActive: d } = xe(r, { initialState: n });
|
|
58
58
|
return {
|
|
59
|
-
stop:
|
|
59
|
+
stop: Be(o, e, {
|
|
60
60
|
...i,
|
|
61
61
|
eventFilter: s
|
|
62
62
|
}),
|
|
@@ -66,7 +66,7 @@ function Ve(o, e, t = {}) {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
function We(o, e = !0, t) {
|
|
69
|
-
|
|
69
|
+
_e() ? ve(o, t) : e ? o() : de(o);
|
|
70
70
|
}
|
|
71
71
|
function ze(o, e, t) {
|
|
72
72
|
return U(o, e, {
|
|
@@ -89,7 +89,7 @@ function He(o) {
|
|
|
89
89
|
return (e = t?.$el) !== null && e !== void 0 ? e : t;
|
|
90
90
|
}
|
|
91
91
|
function Q(...o) {
|
|
92
|
-
const e = (r, n, i, s) => (r.addEventListener(n, i, s), () => r.removeEventListener(n, i, s)), t =
|
|
92
|
+
const e = (r, n, i, s) => (r.addEventListener(n, i, s), () => r.removeEventListener(n, i, s)), t = _(() => {
|
|
93
93
|
const r = ce(H(o[0])).filter((n) => n != null);
|
|
94
94
|
return r.every((n) => typeof n != "string") ? r : void 0;
|
|
95
95
|
});
|
|
@@ -98,22 +98,22 @@ function Q(...o) {
|
|
|
98
98
|
return [
|
|
99
99
|
(r = (n = t.value) === null || n === void 0 ? void 0 : n.map((i) => He(i))) !== null && r !== void 0 ? r : [j].filter((i) => i != null),
|
|
100
100
|
ce(H(t.value ? o[1] : o[0])),
|
|
101
|
-
ce(
|
|
101
|
+
ce(Ee(t.value ? o[2] : o[1])),
|
|
102
102
|
H(t.value ? o[3] : o[2])
|
|
103
103
|
];
|
|
104
104
|
}, ([r, n, i, s], a, c) => {
|
|
105
105
|
if (!r?.length || !n?.length || !i?.length) return;
|
|
106
|
-
const d = Me(s) ? { ...s } : s,
|
|
106
|
+
const d = Me(s) ? { ...s } : s, p = r.flatMap((S) => n.flatMap(($) => i.map((D) => e(S, $, D, d))));
|
|
107
107
|
c(() => {
|
|
108
|
-
|
|
108
|
+
p.forEach((S) => S());
|
|
109
109
|
});
|
|
110
110
|
}, { flush: "post" });
|
|
111
111
|
}
|
|
112
|
-
const ne = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, oe = "__vueuse_ssr_handlers__", Ue = /* @__PURE__ */
|
|
113
|
-
function
|
|
112
|
+
const ne = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, oe = "__vueuse_ssr_handlers__", Ue = /* @__PURE__ */ qe();
|
|
113
|
+
function qe() {
|
|
114
114
|
return oe in ne || (ne[oe] = ne[oe] || {}), ne[oe];
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function Je(o, e) {
|
|
117
117
|
return Ue[o] || e;
|
|
118
118
|
}
|
|
119
119
|
function Ke(o) {
|
|
@@ -155,87 +155,87 @@ const je = {
|
|
|
155
155
|
}, ge = "vueuse-storage";
|
|
156
156
|
function Ge(o, e, t, r = {}) {
|
|
157
157
|
var n;
|
|
158
|
-
const { flush: i = "pre", deep: s = !0, listenToStorageChanges: a = !0, writeDefaults: c = !0, mergeDefaults: d = !1, shallow:
|
|
159
|
-
console.error(
|
|
160
|
-
}, initOnMounted:
|
|
158
|
+
const { flush: i = "pre", deep: s = !0, listenToStorageChanges: a = !0, writeDefaults: c = !0, mergeDefaults: d = !1, shallow: p, window: S = j, eventFilter: $, onError: D = (m) => {
|
|
159
|
+
console.error(m);
|
|
160
|
+
}, initOnMounted: N } = r, F = (p ? we : L)(e), R = _(() => H(o));
|
|
161
161
|
if (!t) try {
|
|
162
|
-
t =
|
|
163
|
-
} catch (
|
|
164
|
-
D(
|
|
162
|
+
t = Je("getDefaultStorage", () => j?.localStorage)();
|
|
163
|
+
} catch (m) {
|
|
164
|
+
D(m);
|
|
165
165
|
}
|
|
166
166
|
if (!t) return F;
|
|
167
|
-
const O = H(e), b = Ke(O), g = (n = r.serializer) !== null && n !== void 0 ? n : je[b], { pause:
|
|
167
|
+
const O = H(e), b = Ke(O), g = (n = r.serializer) !== null && n !== void 0 ? n : je[b], { pause: I, resume: w } = Ve(F, (m) => x(m), {
|
|
168
168
|
flush: i,
|
|
169
169
|
deep: s,
|
|
170
170
|
eventFilter: $
|
|
171
171
|
});
|
|
172
|
-
U(R, () =>
|
|
172
|
+
U(R, () => B(), { flush: i });
|
|
173
173
|
let A = !1;
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
}, M = (
|
|
177
|
-
|
|
174
|
+
const E = (m) => {
|
|
175
|
+
N && !A || B(m);
|
|
176
|
+
}, M = (m) => {
|
|
177
|
+
N && !A || G(m);
|
|
178
178
|
};
|
|
179
|
-
S && a && (t instanceof Storage ? Q(S, "storage",
|
|
180
|
-
A = !0,
|
|
181
|
-
}) :
|
|
182
|
-
function W(
|
|
179
|
+
S && a && (t instanceof Storage ? Q(S, "storage", E, { passive: !0 }) : Q(S, ge, M)), N ? We(() => {
|
|
180
|
+
A = !0, B();
|
|
181
|
+
}) : B();
|
|
182
|
+
function W(m, C) {
|
|
183
183
|
if (S) {
|
|
184
184
|
const k = {
|
|
185
185
|
key: R.value,
|
|
186
|
-
oldValue:
|
|
187
|
-
newValue:
|
|
186
|
+
oldValue: m,
|
|
187
|
+
newValue: C,
|
|
188
188
|
storageArea: t
|
|
189
189
|
};
|
|
190
190
|
S.dispatchEvent(t instanceof Storage ? new StorageEvent("storage", k) : new CustomEvent(ge, { detail: k }));
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function x(m) {
|
|
194
194
|
try {
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
197
|
-
W(
|
|
195
|
+
const C = t.getItem(R.value);
|
|
196
|
+
if (m == null)
|
|
197
|
+
W(C, null), t.removeItem(R.value);
|
|
198
198
|
else {
|
|
199
|
-
const k = g.write(
|
|
200
|
-
|
|
199
|
+
const k = g.write(m);
|
|
200
|
+
C !== k && (t.setItem(R.value, k), W(C, k));
|
|
201
201
|
}
|
|
202
|
-
} catch (
|
|
203
|
-
D(
|
|
202
|
+
} catch (C) {
|
|
203
|
+
D(C);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
function
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
206
|
+
function J(m) {
|
|
207
|
+
const C = m ? m.newValue : t.getItem(R.value);
|
|
208
|
+
if (C == null)
|
|
209
209
|
return c && O != null && t.setItem(R.value, g.write(O)), O;
|
|
210
|
-
if (!
|
|
211
|
-
const k = g.read(
|
|
210
|
+
if (!m && d) {
|
|
211
|
+
const k = g.read(C);
|
|
212
212
|
return typeof d == "function" ? d(k, O) : b === "object" && !Array.isArray(k) ? {
|
|
213
213
|
...O,
|
|
214
214
|
...k
|
|
215
215
|
} : k;
|
|
216
|
-
} else return typeof
|
|
216
|
+
} else return typeof C != "string" ? C : g.read(C);
|
|
217
217
|
}
|
|
218
|
-
function
|
|
219
|
-
if (!(
|
|
220
|
-
if (
|
|
218
|
+
function B(m) {
|
|
219
|
+
if (!(m && m.storageArea !== t)) {
|
|
220
|
+
if (m && m.key == null) {
|
|
221
221
|
F.value = O;
|
|
222
222
|
return;
|
|
223
223
|
}
|
|
224
|
-
if (!(
|
|
225
|
-
|
|
224
|
+
if (!(m && m.key !== R.value)) {
|
|
225
|
+
I();
|
|
226
226
|
try {
|
|
227
|
-
const
|
|
228
|
-
(
|
|
229
|
-
} catch (
|
|
230
|
-
D(
|
|
227
|
+
const C = g.write(F.value);
|
|
228
|
+
(m === void 0 || m?.newValue !== C) && (F.value = J(m));
|
|
229
|
+
} catch (C) {
|
|
230
|
+
D(C);
|
|
231
231
|
} finally {
|
|
232
|
-
|
|
232
|
+
m ? de(w) : w();
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
function G(
|
|
238
|
-
|
|
237
|
+
function G(m) {
|
|
238
|
+
B(m.detail);
|
|
239
239
|
}
|
|
240
240
|
return F;
|
|
241
241
|
}
|
|
@@ -259,7 +259,7 @@ function Ye(o = {}) {
|
|
|
259
259
|
return {};
|
|
260
260
|
},
|
|
261
261
|
current: s
|
|
262
|
-
}, c = e ? ue(a) : a, d = /* @__PURE__ */ new Set(),
|
|
262
|
+
}, c = e ? ue(a) : a, d = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map([
|
|
263
263
|
["Meta", d],
|
|
264
264
|
["Shift", /* @__PURE__ */ new Set()],
|
|
265
265
|
["Alt", /* @__PURE__ */ new Set()]
|
|
@@ -271,43 +271,43 @@ function Ye(o = {}) {
|
|
|
271
271
|
s.clear();
|
|
272
272
|
for (const b of S) $(b, !1);
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function N(b, g, I) {
|
|
275
275
|
if (!(!b || typeof g.getModifierState != "function")) {
|
|
276
|
-
for (const [w, A] of
|
|
277
|
-
|
|
276
|
+
for (const [w, A] of p) if (g.getModifierState(w)) {
|
|
277
|
+
I.forEach((E) => A.add(E));
|
|
278
278
|
break;
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
function F(b, g) {
|
|
283
283
|
if (b) return;
|
|
284
|
-
const
|
|
284
|
+
const I = `${g[0].toUpperCase()}${g.slice(1)}`, w = p.get(I);
|
|
285
285
|
if (!["shift", "alt"].includes(g) || !w) return;
|
|
286
|
-
const A = Array.from(w),
|
|
286
|
+
const A = Array.from(w), E = A.indexOf(g);
|
|
287
287
|
A.forEach((M, W) => {
|
|
288
|
-
W >=
|
|
288
|
+
W >= E && (s.delete(M), $(M, !1));
|
|
289
289
|
}), w.clear();
|
|
290
290
|
}
|
|
291
291
|
function R(b, g) {
|
|
292
|
-
var
|
|
293
|
-
const A = (
|
|
292
|
+
var I, w;
|
|
293
|
+
const A = (I = b.key) === null || I === void 0 ? void 0 : I.toLowerCase(), E = [(w = b.code) === null || w === void 0 ? void 0 : w.toLowerCase(), A].filter(Boolean);
|
|
294
294
|
if (A) {
|
|
295
295
|
A && (g ? s.add(A) : s.delete(A));
|
|
296
|
-
for (const M of
|
|
296
|
+
for (const M of E)
|
|
297
297
|
S.add(M), $(M, g);
|
|
298
|
-
|
|
298
|
+
N(g, b, [...s, ...E]), F(g, A), A === "meta" && !g && (d.forEach((M) => {
|
|
299
299
|
s.delete(M), $(M, !1);
|
|
300
300
|
}), d.clear());
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
Q(t, "keydown", (b) => (R(b, !0), i(b)), { passive: n }), Q(t, "keyup", (b) => (R(b, !1), i(b)), { passive: n }), Q("blur", D, { passive: n }), Q("focus", D, { passive: n });
|
|
304
|
-
const O = new Proxy(c, { get(b, g,
|
|
305
|
-
if (typeof g != "string") return Reflect.get(b, g,
|
|
304
|
+
const O = new Proxy(c, { get(b, g, I) {
|
|
305
|
+
if (typeof g != "string") return Reflect.get(b, g, I);
|
|
306
306
|
if (g = g.toLowerCase(), g in r && (g = r[g]), !(g in c)) if (/[+_-]/.test(g)) {
|
|
307
|
-
const A = g.split(/[+_-]/g).map((
|
|
308
|
-
c[g] =
|
|
307
|
+
const A = g.split(/[+_-]/g).map((E) => E.trim());
|
|
308
|
+
c[g] = _(() => A.map((E) => H(O[E])).every(Boolean));
|
|
309
309
|
} else c[g] = we(!1);
|
|
310
|
-
const w = Reflect.get(b, g,
|
|
310
|
+
const w = Reflect.get(b, g, I);
|
|
311
311
|
return e ? H(w) : w;
|
|
312
312
|
} });
|
|
313
313
|
return O;
|
|
@@ -350,20 +350,20 @@ const re = ke("hst-operation-log", () => {
|
|
|
350
350
|
autoSyncInterval: 3e4,
|
|
351
351
|
enablePersistence: !1,
|
|
352
352
|
persistenceKeyPrefix: "stonecrop-ops"
|
|
353
|
-
}), e = L([]), t = L(-1), r = L(le()), n = L(!1), i = L([]), s = L(null), a =
|
|
353
|
+
}), e = L([]), t = L(-1), r = L(le()), n = L(!1), i = L([]), s = L(null), a = _(() => t.value < 0 ? !1 : e.value[t.value]?.reversible ?? !1), c = _(() => t.value < e.value.length - 1), d = _(() => {
|
|
354
354
|
let u = 0;
|
|
355
355
|
for (let l = t.value; l >= 0 && e.value[l]?.reversible; l--)
|
|
356
356
|
u++;
|
|
357
357
|
return u;
|
|
358
|
-
}),
|
|
358
|
+
}), p = _(() => e.value.length - 1 - t.value), S = _(() => ({
|
|
359
359
|
canUndo: a.value,
|
|
360
360
|
canRedo: c.value,
|
|
361
361
|
undoCount: d.value,
|
|
362
|
-
redoCount:
|
|
362
|
+
redoCount: p.value,
|
|
363
363
|
currentIndex: t.value
|
|
364
364
|
}));
|
|
365
365
|
function $(u) {
|
|
366
|
-
o.value = { ...o.value, ...u }, o.value.enablePersistence && (
|
|
366
|
+
o.value = { ...o.value, ...u }, o.value.enablePersistence && (h(), y()), o.value.enableCrossTabSync && J();
|
|
367
367
|
}
|
|
368
368
|
function D(u, l = "user") {
|
|
369
369
|
const f = {
|
|
@@ -381,15 +381,15 @@ const re = ke("hst-operation-log", () => {
|
|
|
381
381
|
const T = e.value.length - o.value.maxOperations;
|
|
382
382
|
e.value = e.value.slice(T), t.value -= T;
|
|
383
383
|
}
|
|
384
|
-
return o.value.enableCrossTabSync &&
|
|
384
|
+
return o.value.enableCrossTabSync && B(f), f.id;
|
|
385
385
|
}
|
|
386
|
-
function
|
|
386
|
+
function N() {
|
|
387
387
|
n.value = !0, i.value = [], s.value = le();
|
|
388
388
|
}
|
|
389
389
|
function F(u) {
|
|
390
390
|
if (!n.value || i.value.length === 0)
|
|
391
391
|
return n.value = !1, i.value = [], s.value = null, null;
|
|
392
|
-
const l = s.value, f = i.value.every((
|
|
392
|
+
const l = s.value, f = i.value.every((P) => P.reversible), T = {
|
|
393
393
|
id: l,
|
|
394
394
|
type: "batch",
|
|
395
395
|
path: "",
|
|
@@ -402,11 +402,11 @@ const re = ke("hst-operation-log", () => {
|
|
|
402
402
|
source: "user",
|
|
403
403
|
reversible: f,
|
|
404
404
|
irreversibleReason: f ? void 0 : "Contains irreversible operations",
|
|
405
|
-
childOperationIds: i.value.map((
|
|
405
|
+
childOperationIds: i.value.map((P) => P.id),
|
|
406
406
|
metadata: { description: u }
|
|
407
407
|
};
|
|
408
|
-
i.value.forEach((
|
|
409
|
-
|
|
408
|
+
i.value.forEach((P) => {
|
|
409
|
+
P.parentOperationId = l;
|
|
410
410
|
}), e.value.push(...i.value, T), t.value = e.value.length - 1, o.value.enableCrossTabSync && G(i.value, T);
|
|
411
411
|
const V = l;
|
|
412
412
|
return n.value = !1, i.value = [], s.value = null, V;
|
|
@@ -422,12 +422,12 @@ const re = ke("hst-operation-log", () => {
|
|
|
422
422
|
try {
|
|
423
423
|
if (l.type === "batch" && l.childOperationIds)
|
|
424
424
|
for (let f = l.childOperationIds.length - 1; f >= 0; f--) {
|
|
425
|
-
const T = l.childOperationIds[f], V = e.value.find((
|
|
425
|
+
const T = l.childOperationIds[f], V = e.value.find((P) => P.id === T);
|
|
426
426
|
V && g(V, u);
|
|
427
427
|
}
|
|
428
428
|
else
|
|
429
429
|
g(l, u);
|
|
430
|
-
return t.value--, o.value.enableCrossTabSync &&
|
|
430
|
+
return t.value--, o.value.enableCrossTabSync && m(l), !0;
|
|
431
431
|
} catch (f) {
|
|
432
432
|
return typeof console < "u" && console.error("Undo failed:", f), !1;
|
|
433
433
|
}
|
|
@@ -439,11 +439,11 @@ const re = ke("hst-operation-log", () => {
|
|
|
439
439
|
if (l.type === "batch" && l.childOperationIds)
|
|
440
440
|
for (const f of l.childOperationIds) {
|
|
441
441
|
const T = e.value.find((V) => V.id === f);
|
|
442
|
-
T &&
|
|
442
|
+
T && I(T, u);
|
|
443
443
|
}
|
|
444
444
|
else
|
|
445
|
-
|
|
446
|
-
return t.value++, o.value.enableCrossTabSync &&
|
|
445
|
+
I(l, u);
|
|
446
|
+
return t.value++, o.value.enableCrossTabSync && C(l), !0;
|
|
447
447
|
} catch (f) {
|
|
448
448
|
return typeof console < "u" && console.error("Redo failed:", f), !1;
|
|
449
449
|
}
|
|
@@ -451,7 +451,7 @@ const re = ke("hst-operation-log", () => {
|
|
|
451
451
|
function g(u, l) {
|
|
452
452
|
(u.type === "set" || u.type === "delete") && l && typeof l.set == "function" && l.set(u.path, u.beforeValue, "undo");
|
|
453
453
|
}
|
|
454
|
-
function
|
|
454
|
+
function I(u, l) {
|
|
455
455
|
(u.type === "set" || u.type === "delete") && l && typeof l.set == "function" && l.set(u.path, u.afterValue, "redo");
|
|
456
456
|
}
|
|
457
457
|
function w() {
|
|
@@ -469,7 +469,7 @@ const re = ke("hst-operation-log", () => {
|
|
|
469
469
|
function A() {
|
|
470
470
|
e.value = [], t.value = -1;
|
|
471
471
|
}
|
|
472
|
-
function
|
|
472
|
+
function E(u, l) {
|
|
473
473
|
return e.value.filter((f) => f.doctype === u && (l === void 0 || f.recordId === l));
|
|
474
474
|
}
|
|
475
475
|
function M(u, l) {
|
|
@@ -477,7 +477,7 @@ const re = ke("hst-operation-log", () => {
|
|
|
477
477
|
f && (f.reversible = !1, f.irreversibleReason = l);
|
|
478
478
|
}
|
|
479
479
|
function W(u, l, f, T = "success", V) {
|
|
480
|
-
const
|
|
480
|
+
const P = {
|
|
481
481
|
type: "action",
|
|
482
482
|
path: f && f.length > 0 ? `${u}.${f[0]}` : u,
|
|
483
483
|
fieldname: "",
|
|
@@ -492,56 +492,56 @@ const re = ke("hst-operation-log", () => {
|
|
|
492
492
|
actionResult: T,
|
|
493
493
|
actionError: V
|
|
494
494
|
};
|
|
495
|
-
return D(
|
|
495
|
+
return D(P);
|
|
496
496
|
}
|
|
497
|
-
let
|
|
498
|
-
function
|
|
499
|
-
typeof window > "u" || !window.BroadcastChannel || (
|
|
497
|
+
let x = null;
|
|
498
|
+
function J() {
|
|
499
|
+
typeof window > "u" || !window.BroadcastChannel || (x = new BroadcastChannel("stonecrop-operation-log"), x.addEventListener("message", (u) => {
|
|
500
500
|
const l = u.data;
|
|
501
501
|
if (!l || typeof l != "object") return;
|
|
502
502
|
const f = Xe(l);
|
|
503
503
|
f.clientId !== r.value && (f.type === "operation" && f.operation ? (e.value.push({ ...f.operation, source: "sync" }), t.value = e.value.length - 1) : f.type === "operation" && f.operations && (e.value.push(...f.operations.map((T) => ({ ...T, source: "sync" }))), t.value = e.value.length - 1));
|
|
504
504
|
}));
|
|
505
505
|
}
|
|
506
|
-
function
|
|
507
|
-
if (!
|
|
506
|
+
function B(u) {
|
|
507
|
+
if (!x) return;
|
|
508
508
|
const l = {
|
|
509
509
|
type: "operation",
|
|
510
510
|
operation: u,
|
|
511
511
|
clientId: r.value,
|
|
512
512
|
timestamp: /* @__PURE__ */ new Date()
|
|
513
513
|
};
|
|
514
|
-
|
|
514
|
+
x.postMessage(ie(l));
|
|
515
515
|
}
|
|
516
516
|
function G(u, l) {
|
|
517
|
-
if (!
|
|
517
|
+
if (!x) return;
|
|
518
518
|
const f = {
|
|
519
519
|
type: "operation",
|
|
520
520
|
operations: [...u, l],
|
|
521
521
|
clientId: r.value,
|
|
522
522
|
timestamp: /* @__PURE__ */ new Date()
|
|
523
523
|
};
|
|
524
|
-
|
|
524
|
+
x.postMessage(ie(f));
|
|
525
525
|
}
|
|
526
|
-
function
|
|
527
|
-
if (!
|
|
526
|
+
function m(u) {
|
|
527
|
+
if (!x) return;
|
|
528
528
|
const l = {
|
|
529
529
|
type: "undo",
|
|
530
530
|
operation: u,
|
|
531
531
|
clientId: r.value,
|
|
532
532
|
timestamp: /* @__PURE__ */ new Date()
|
|
533
533
|
};
|
|
534
|
-
|
|
534
|
+
x.postMessage(ie(l));
|
|
535
535
|
}
|
|
536
|
-
function
|
|
537
|
-
if (!
|
|
536
|
+
function C(u) {
|
|
537
|
+
if (!x) return;
|
|
538
538
|
const l = {
|
|
539
539
|
type: "redo",
|
|
540
540
|
operation: u,
|
|
541
541
|
clientId: r.value,
|
|
542
542
|
timestamp: /* @__PURE__ */ new Date()
|
|
543
543
|
};
|
|
544
|
-
|
|
544
|
+
x.postMessage(ie(l));
|
|
545
545
|
}
|
|
546
546
|
const k = Ze("stonecrop-ops-operations", null, {
|
|
547
547
|
serializer: {
|
|
@@ -555,7 +555,7 @@ const re = ke("hst-operation-log", () => {
|
|
|
555
555
|
write: (u) => u ? JSON.stringify(u) : ""
|
|
556
556
|
}
|
|
557
557
|
});
|
|
558
|
-
function
|
|
558
|
+
function h() {
|
|
559
559
|
if (!(typeof window > "u"))
|
|
560
560
|
try {
|
|
561
561
|
const u = k.value;
|
|
@@ -567,7 +567,7 @@ const re = ke("hst-operation-log", () => {
|
|
|
567
567
|
typeof console < "u" && console.error("Failed to load operations from persistence:", u);
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
|
-
function
|
|
570
|
+
function v() {
|
|
571
571
|
if (!(typeof window > "u"))
|
|
572
572
|
try {
|
|
573
573
|
k.value = {
|
|
@@ -585,7 +585,7 @@ const re = ke("hst-operation-log", () => {
|
|
|
585
585
|
U(
|
|
586
586
|
[e, t],
|
|
587
587
|
() => {
|
|
588
|
-
o.value.enablePersistence &&
|
|
588
|
+
o.value.enablePersistence && v();
|
|
589
589
|
},
|
|
590
590
|
{ deep: !0 }
|
|
591
591
|
);
|
|
@@ -601,17 +601,17 @@ const re = ke("hst-operation-log", () => {
|
|
|
601
601
|
canUndo: a,
|
|
602
602
|
canRedo: c,
|
|
603
603
|
undoCount: d,
|
|
604
|
-
redoCount:
|
|
604
|
+
redoCount: p,
|
|
605
605
|
// Methods
|
|
606
606
|
configure: $,
|
|
607
607
|
addOperation: D,
|
|
608
|
-
startBatch:
|
|
608
|
+
startBatch: N,
|
|
609
609
|
commitBatch: F,
|
|
610
610
|
cancelBatch: R,
|
|
611
611
|
undo: O,
|
|
612
612
|
redo: b,
|
|
613
613
|
clear: A,
|
|
614
|
-
getOperationsFor:
|
|
614
|
+
getOperationsFor: E,
|
|
615
615
|
getSnapshot: w,
|
|
616
616
|
markIrreversible: M,
|
|
617
617
|
logAction: W
|
|
@@ -730,9 +730,9 @@ class ee {
|
|
|
730
730
|
rolledBack: !1
|
|
731
731
|
};
|
|
732
732
|
const s = performance.now(), a = [];
|
|
733
|
-
let c = !1, d = !1,
|
|
733
|
+
let c = !1, d = !1, p;
|
|
734
734
|
const S = this.getFieldRollback(r, n), $ = t.enableRollback ?? S ?? this.options.enableRollback;
|
|
735
|
-
$ && e.store && (
|
|
735
|
+
$ && e.store && (p = this.captureSnapshot(e));
|
|
736
736
|
for (const R of i)
|
|
737
737
|
try {
|
|
738
738
|
const O = await this.executeAction(R, e, t.timeout);
|
|
@@ -750,15 +750,15 @@ class ee {
|
|
|
750
750
|
a.push(g), c = !0;
|
|
751
751
|
break;
|
|
752
752
|
}
|
|
753
|
-
if ($ && c &&
|
|
753
|
+
if ($ && c && p && e.store)
|
|
754
754
|
try {
|
|
755
|
-
this.restoreSnapshot(e,
|
|
755
|
+
this.restoreSnapshot(e, p), d = !0;
|
|
756
756
|
} catch (R) {
|
|
757
757
|
console.error("[FieldTriggers] Rollback failed:", R);
|
|
758
758
|
}
|
|
759
|
-
const D = performance.now() - s,
|
|
760
|
-
if (
|
|
761
|
-
for (const R of
|
|
759
|
+
const D = performance.now() - s, N = a.filter((R) => !R.success);
|
|
760
|
+
if (N.length > 0 && this.options.errorHandler)
|
|
761
|
+
for (const R of N)
|
|
762
762
|
try {
|
|
763
763
|
this.options.errorHandler(R.error, e, R.action);
|
|
764
764
|
} catch (O) {
|
|
@@ -771,7 +771,7 @@ class ee {
|
|
|
771
771
|
allSucceeded: a.every((R) => R.success),
|
|
772
772
|
stoppedOnError: c,
|
|
773
773
|
rolledBack: d,
|
|
774
|
-
snapshot: this.options.debug && $ ?
|
|
774
|
+
snapshot: this.options.debug && $ ? p : void 0
|
|
775
775
|
// Only include snapshot in debug mode if rollback is enabled
|
|
776
776
|
};
|
|
777
777
|
}
|
|
@@ -953,20 +953,20 @@ class ee {
|
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
955
|
}
|
|
956
|
-
function
|
|
956
|
+
function q(o) {
|
|
957
957
|
return new ee(o);
|
|
958
958
|
}
|
|
959
959
|
function ct(o, e) {
|
|
960
|
-
|
|
960
|
+
q().registerAction(o, e);
|
|
961
961
|
}
|
|
962
962
|
function lt(o, e) {
|
|
963
|
-
|
|
963
|
+
q().registerTransitionAction(o, e);
|
|
964
964
|
}
|
|
965
965
|
function ut(o, e, t) {
|
|
966
|
-
|
|
966
|
+
q().setFieldRollback(o, e, t);
|
|
967
967
|
}
|
|
968
968
|
async function ft(o, e, t) {
|
|
969
|
-
const r =
|
|
969
|
+
const r = q(), n = {
|
|
970
970
|
path: t?.path || (t?.recordId ? `${o}.${t.recordId}` : o),
|
|
971
971
|
fieldname: "",
|
|
972
972
|
beforeValue: void 0,
|
|
@@ -989,7 +989,7 @@ function dt(o, e) {
|
|
|
989
989
|
} catch {
|
|
990
990
|
}
|
|
991
991
|
}
|
|
992
|
-
function
|
|
992
|
+
function pe() {
|
|
993
993
|
try {
|
|
994
994
|
return re();
|
|
995
995
|
} catch {
|
|
@@ -1069,14 +1069,14 @@ class se {
|
|
|
1069
1069
|
set(e, t, r = "user") {
|
|
1070
1070
|
const n = this.resolvePath(e), i = this.has(e) ? this.get(e) : void 0;
|
|
1071
1071
|
if (r !== "undo" && r !== "redo") {
|
|
1072
|
-
const s =
|
|
1072
|
+
const s = pe();
|
|
1073
1073
|
if (s && typeof s.addOperation == "function") {
|
|
1074
|
-
const a = n.split("."), c = this.doctype === "StonecropStore" && a.length >= 1 ? a[0] : this.doctype, d = a.length >= 2 ? a[1] : void 0,
|
|
1074
|
+
const a = n.split("."), c = this.doctype === "StonecropStore" && a.length >= 1 ? a[0] : this.doctype, d = a.length >= 2 ? a[1] : void 0, p = a.slice(2).join(".") || a[a.length - 1], $ = t === void 0 && i !== void 0 ? "delete" : "set";
|
|
1075
1075
|
s.addOperation(
|
|
1076
1076
|
{
|
|
1077
1077
|
type: $,
|
|
1078
1078
|
path: n,
|
|
1079
|
-
fieldname:
|
|
1079
|
+
fieldname: p,
|
|
1080
1080
|
beforeValue: i,
|
|
1081
1081
|
afterValue: t,
|
|
1082
1082
|
doctype: c,
|
|
@@ -1131,7 +1131,7 @@ class se {
|
|
|
1131
1131
|
* Trigger an XState transition with optional context data
|
|
1132
1132
|
*/
|
|
1133
1133
|
async triggerTransition(e, t) {
|
|
1134
|
-
const r =
|
|
1134
|
+
const r = q(), n = this.parentPath.split(".");
|
|
1135
1135
|
let i = this.doctype, s;
|
|
1136
1136
|
this.doctype === "StonecropStore" && n.length >= 1 && (i = n[0]), n.length >= 2 && (s = n[1]);
|
|
1137
1137
|
const a = {
|
|
@@ -1149,7 +1149,7 @@ class se {
|
|
|
1149
1149
|
currentState: t?.currentState,
|
|
1150
1150
|
targetState: t?.targetState,
|
|
1151
1151
|
fsmContext: t?.fsmContext
|
|
1152
|
-
}, c =
|
|
1152
|
+
}, c = pe();
|
|
1153
1153
|
return c && typeof c.addOperation == "function" && c.addOperation(
|
|
1154
1154
|
{
|
|
1155
1155
|
type: "transition",
|
|
@@ -1216,7 +1216,7 @@ class se {
|
|
|
1216
1216
|
const n = e.split(".");
|
|
1217
1217
|
if (n.length < 3)
|
|
1218
1218
|
return;
|
|
1219
|
-
const i =
|
|
1219
|
+
const i = q(), s = n.slice(2).join(".") || n[n.length - 1];
|
|
1220
1220
|
let a = this.doctype;
|
|
1221
1221
|
this.doctype === "StonecropStore" && n.length >= 1 && (a = n[0]);
|
|
1222
1222
|
let c;
|
|
@@ -1280,15 +1280,40 @@ class Oe {
|
|
|
1280
1280
|
hstStore;
|
|
1281
1281
|
_operationLogStore;
|
|
1282
1282
|
_operationLogConfig;
|
|
1283
|
+
_client;
|
|
1283
1284
|
/** The registry instance containing all doctype definitions */
|
|
1284
1285
|
registry;
|
|
1285
1286
|
/**
|
|
1286
1287
|
* Creates a new Stonecrop instance with HST integration
|
|
1287
1288
|
* @param registry - The Registry instance containing doctype definitions
|
|
1288
1289
|
* @param operationLogConfig - Optional configuration for the operation log
|
|
1290
|
+
* @param options - Options including the data client (can be set later via setClient)
|
|
1289
1291
|
*/
|
|
1290
|
-
constructor(e, t) {
|
|
1291
|
-
this.registry = e, this._operationLogConfig = t, this.initializeHSTStore(), this.setupRegistrySync();
|
|
1292
|
+
constructor(e, t, r) {
|
|
1293
|
+
this.registry = e, this._operationLogConfig = t, this._client = r?.client, this.initializeHSTStore(), this.setupRegistrySync();
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Set the data client for fetching doctype metadata and records.
|
|
1297
|
+
* Use this for deferred configuration in Nuxt/Vue plugin setups.
|
|
1298
|
+
*
|
|
1299
|
+
* @param client - DataClient implementation (e.g., StonecropClient from \@stonecrop/graphql-client)
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* ```ts
|
|
1303
|
+
* const { setClient } = useStonecropRegistry()
|
|
1304
|
+
* const client = new StonecropClient({ endpoint: '/graphql' })
|
|
1305
|
+
* setClient(client)
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
setClient(e) {
|
|
1309
|
+
this._client = e;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Get the current data client
|
|
1313
|
+
* @returns The DataClient instance or undefined if not set
|
|
1314
|
+
*/
|
|
1315
|
+
getClient() {
|
|
1316
|
+
return this._client;
|
|
1292
1317
|
}
|
|
1293
1318
|
/**
|
|
1294
1319
|
* Get the operation log store (lazy initialization)
|
|
@@ -1390,12 +1415,12 @@ class Oe {
|
|
|
1390
1415
|
* @param args - Action arguments (typically record IDs)
|
|
1391
1416
|
*/
|
|
1392
1417
|
runAction(e, t, r) {
|
|
1393
|
-
const i = this.registry.registry[e.slug]?.actions?.get(t), s = Array.isArray(r) ? r.filter((
|
|
1418
|
+
const i = this.registry.registry[e.slug]?.actions?.get(t), s = Array.isArray(r) ? r.filter((p) => typeof p == "string") : void 0, a = this.getOperationLogStore();
|
|
1394
1419
|
let c = "success", d;
|
|
1395
1420
|
try {
|
|
1396
|
-
i && i.length > 0 && i.forEach((
|
|
1421
|
+
i && i.length > 0 && i.forEach((p) => {
|
|
1397
1422
|
try {
|
|
1398
|
-
new Function("args",
|
|
1423
|
+
new Function("args", p)(r);
|
|
1399
1424
|
} catch (S) {
|
|
1400
1425
|
throw c = "failure", d = S instanceof Error ? S.message : "Unknown error", S;
|
|
1401
1426
|
}
|
|
@@ -1406,22 +1431,49 @@ class Oe {
|
|
|
1406
1431
|
}
|
|
1407
1432
|
}
|
|
1408
1433
|
/**
|
|
1409
|
-
* Get records from server
|
|
1434
|
+
* Get records from server using the configured data client.
|
|
1410
1435
|
* @param doctype - The doctype
|
|
1436
|
+
* @throws Error if no data client has been configured
|
|
1411
1437
|
*/
|
|
1412
1438
|
async getRecords(e) {
|
|
1413
|
-
|
|
1414
|
-
|
|
1439
|
+
if (!this._client)
|
|
1440
|
+
throw new Error(
|
|
1441
|
+
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records."
|
|
1442
|
+
);
|
|
1443
|
+
(await this._client.getRecords(e)).forEach((r) => {
|
|
1444
|
+
r.id && this.addRecord(e, r.id, r);
|
|
1415
1445
|
});
|
|
1416
1446
|
}
|
|
1417
1447
|
/**
|
|
1418
|
-
* Get single record from server
|
|
1448
|
+
* Get single record from server using the configured data client.
|
|
1419
1449
|
* @param doctype - The doctype
|
|
1420
1450
|
* @param recordId - The record ID
|
|
1451
|
+
* @throws Error if no data client has been configured
|
|
1421
1452
|
*/
|
|
1422
1453
|
async getRecord(e, t) {
|
|
1423
|
-
|
|
1424
|
-
|
|
1454
|
+
if (!this._client)
|
|
1455
|
+
throw new Error(
|
|
1456
|
+
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records."
|
|
1457
|
+
);
|
|
1458
|
+
const r = await this._client.getRecord(e, t);
|
|
1459
|
+
r && this.addRecord(e, t, r);
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Dispatch an action to the server via the configured data client.
|
|
1463
|
+
* All state changes flow through this single mutation endpoint.
|
|
1464
|
+
*
|
|
1465
|
+
* @param doctype - The doctype
|
|
1466
|
+
* @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
|
|
1467
|
+
* @param args - Action arguments (typically record ID and/or form data)
|
|
1468
|
+
* @returns Action result with success status, response data, and any error
|
|
1469
|
+
* @throws Error if no data client has been configured
|
|
1470
|
+
*/
|
|
1471
|
+
async dispatchAction(e, t, r) {
|
|
1472
|
+
if (!this._client)
|
|
1473
|
+
throw new Error(
|
|
1474
|
+
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before dispatching actions."
|
|
1475
|
+
);
|
|
1476
|
+
return this._client.runAction(e, t, r);
|
|
1425
1477
|
}
|
|
1426
1478
|
/**
|
|
1427
1479
|
* Ensure doctype section exists in HST store
|
|
@@ -1467,14 +1519,14 @@ class Oe {
|
|
|
1467
1519
|
return s || a;
|
|
1468
1520
|
}
|
|
1469
1521
|
}
|
|
1470
|
-
function
|
|
1522
|
+
function ht(o) {
|
|
1471
1523
|
o || (o = {});
|
|
1472
1524
|
const e = o.registry || fe("$registry"), t = fe("$stonecrop"), r = L(), n = L(), i = L({}), s = L(), a = L(), c = L([]);
|
|
1473
1525
|
if (o.doctype && e) {
|
|
1474
|
-
const
|
|
1475
|
-
c.value = e.resolveSchema(
|
|
1526
|
+
const h = o.doctype.schema ? Array.isArray(o.doctype.schema) ? o.doctype.schema : Array.from(o.doctype.schema) : [];
|
|
1527
|
+
c.value = e.resolveSchema(h);
|
|
1476
1528
|
}
|
|
1477
|
-
const d = L([]),
|
|
1529
|
+
const d = L([]), p = L(-1), S = _(() => r.value?.getOperationLogStore().canUndo ?? !1), $ = _(() => r.value?.getOperationLogStore().canRedo ?? !1), D = _(() => r.value?.getOperationLogStore().undoCount ?? 0), N = _(() => r.value?.getOperationLogStore().redoCount ?? 0), F = _(
|
|
1478
1530
|
() => r.value?.getOperationLogStore().undoRedoState ?? {
|
|
1479
1531
|
canUndo: !1,
|
|
1480
1532
|
canRedo: !1,
|
|
@@ -1482,49 +1534,49 @@ function pt(o) {
|
|
|
1482
1534
|
redoCount: 0,
|
|
1483
1535
|
currentIndex: -1
|
|
1484
1536
|
}
|
|
1485
|
-
), R = (
|
|
1537
|
+
), R = (h) => r.value?.getOperationLogStore().undo(h) ?? !1, O = (h) => r.value?.getOperationLogStore().redo(h) ?? !1, b = () => {
|
|
1486
1538
|
r.value?.getOperationLogStore().startBatch();
|
|
1487
|
-
}, g = (
|
|
1539
|
+
}, g = (h) => r.value?.getOperationLogStore().commitBatch(h) ?? null, I = () => {
|
|
1488
1540
|
r.value?.getOperationLogStore().cancelBatch();
|
|
1489
1541
|
}, w = () => {
|
|
1490
1542
|
r.value?.getOperationLogStore().clear();
|
|
1491
|
-
}, A = (
|
|
1543
|
+
}, A = (h, v) => r.value?.getOperationLogStore().getOperationsFor(h, v) ?? [], E = () => r.value?.getOperationLogStore().getSnapshot() ?? {
|
|
1492
1544
|
operations: [],
|
|
1493
1545
|
currentIndex: -1,
|
|
1494
1546
|
totalOperations: 0,
|
|
1495
1547
|
reversibleOperations: 0,
|
|
1496
1548
|
irreversibleOperations: 0
|
|
1497
|
-
}, M = (
|
|
1498
|
-
r.value?.getOperationLogStore().markIrreversible(
|
|
1499
|
-
}, W = (
|
|
1500
|
-
r.value?.getOperationLogStore().configure(
|
|
1549
|
+
}, M = (h, v) => {
|
|
1550
|
+
r.value?.getOperationLogStore().markIrreversible(h, v);
|
|
1551
|
+
}, W = (h, v, y, u = "success", l) => r.value?.getOperationLogStore().logAction(h, v, y, u, l) ?? "", x = (h) => {
|
|
1552
|
+
r.value?.getOperationLogStore().configure(h);
|
|
1501
1553
|
};
|
|
1502
|
-
|
|
1554
|
+
ve(async () => {
|
|
1503
1555
|
if (e) {
|
|
1504
1556
|
r.value = t || new Oe(e);
|
|
1505
1557
|
try {
|
|
1506
|
-
const
|
|
1507
|
-
d.value =
|
|
1508
|
-
() =>
|
|
1558
|
+
const h = r.value.getOperationLogStore(), v = be(h);
|
|
1559
|
+
d.value = v.operations.value, p.value = v.currentIndex.value, U(
|
|
1560
|
+
() => v.operations.value,
|
|
1509
1561
|
(y) => {
|
|
1510
1562
|
d.value = y;
|
|
1511
1563
|
}
|
|
1512
1564
|
), U(
|
|
1513
|
-
() =>
|
|
1565
|
+
() => v.currentIndex.value,
|
|
1514
1566
|
(y) => {
|
|
1515
|
-
|
|
1567
|
+
p.value = y;
|
|
1516
1568
|
}
|
|
1517
1569
|
);
|
|
1518
1570
|
} catch {
|
|
1519
1571
|
}
|
|
1520
1572
|
if (!o.doctype && e.router) {
|
|
1521
|
-
const
|
|
1522
|
-
if (!
|
|
1523
|
-
const
|
|
1524
|
-
if (
|
|
1573
|
+
const h = e.router.currentRoute.value;
|
|
1574
|
+
if (!h.path) return;
|
|
1575
|
+
const v = h.path.split("/").filter((u) => u.length > 0), y = v[1]?.toLowerCase();
|
|
1576
|
+
if (v.length > 0) {
|
|
1525
1577
|
const u = {
|
|
1526
|
-
path:
|
|
1527
|
-
segments:
|
|
1578
|
+
path: h.path,
|
|
1579
|
+
segments: v
|
|
1528
1580
|
}, l = await e.getMeta?.(u);
|
|
1529
1581
|
if (l) {
|
|
1530
1582
|
if (e.addDoctype(l), r.value.setup(l), s.value = l, a.value = y, n.value = r.value.getStore(), e) {
|
|
@@ -1545,133 +1597,133 @@ function pt(o) {
|
|
|
1545
1597
|
}
|
|
1546
1598
|
} else
|
|
1547
1599
|
i.value = z(l);
|
|
1548
|
-
n.value &&
|
|
1600
|
+
n.value && me(l, y || "new", i, n.value), r.value.runAction(l, "load", y ? [y] : void 0);
|
|
1549
1601
|
}
|
|
1550
1602
|
}
|
|
1551
1603
|
}
|
|
1552
1604
|
if (o.doctype) {
|
|
1553
1605
|
n.value = r.value.getStore();
|
|
1554
|
-
const
|
|
1555
|
-
if (
|
|
1556
|
-
const y = r.value.getRecordById(
|
|
1606
|
+
const h = o.doctype, v = o.recordId;
|
|
1607
|
+
if (v && v !== "new") {
|
|
1608
|
+
const y = r.value.getRecordById(h, v);
|
|
1557
1609
|
if (y)
|
|
1558
1610
|
i.value = y.get("") || {};
|
|
1559
1611
|
else
|
|
1560
1612
|
try {
|
|
1561
|
-
await r.value.getRecord(
|
|
1562
|
-
const u = r.value.getRecordById(
|
|
1613
|
+
await r.value.getRecord(h, v);
|
|
1614
|
+
const u = r.value.getRecordById(h, v);
|
|
1563
1615
|
u && (i.value = u.get("") || {});
|
|
1564
1616
|
} catch {
|
|
1565
|
-
i.value = z(
|
|
1617
|
+
i.value = z(h);
|
|
1566
1618
|
}
|
|
1567
1619
|
} else
|
|
1568
|
-
i.value = z(
|
|
1569
|
-
n.value &&
|
|
1620
|
+
i.value = z(h);
|
|
1621
|
+
n.value && me(h, v || "new", i, n.value);
|
|
1570
1622
|
}
|
|
1571
1623
|
}
|
|
1572
1624
|
});
|
|
1573
|
-
const
|
|
1625
|
+
const J = (h, v) => {
|
|
1574
1626
|
const y = o.doctype || s.value;
|
|
1575
1627
|
if (!y) return "";
|
|
1576
|
-
const u =
|
|
1577
|
-
return `${y.slug}.${u}.${
|
|
1578
|
-
},
|
|
1579
|
-
const
|
|
1580
|
-
if (!(!n.value || !r.value || !
|
|
1628
|
+
const u = v || o.recordId || a.value || "new";
|
|
1629
|
+
return `${y.slug}.${u}.${h}`;
|
|
1630
|
+
}, B = (h) => {
|
|
1631
|
+
const v = o.doctype || s.value;
|
|
1632
|
+
if (!(!n.value || !r.value || !v))
|
|
1581
1633
|
try {
|
|
1582
|
-
const y =
|
|
1634
|
+
const y = h.path.split(".");
|
|
1583
1635
|
if (y.length >= 2) {
|
|
1584
1636
|
const f = y[0], T = y[1];
|
|
1585
|
-
if (n.value.has(`${f}.${T}`) || r.value.addRecord(
|
|
1586
|
-
const V = `${f}.${T}`,
|
|
1637
|
+
if (n.value.has(`${f}.${T}`) || r.value.addRecord(v, T, { ...i.value }), y.length > 3) {
|
|
1638
|
+
const V = `${f}.${T}`, P = y.slice(2);
|
|
1587
1639
|
let K = V;
|
|
1588
|
-
for (let Z = 0; Z <
|
|
1589
|
-
if (K += `.${
|
|
1590
|
-
const ae =
|
|
1591
|
-
n.value.set(K,
|
|
1640
|
+
for (let Z = 0; Z < P.length - 1; Z++)
|
|
1641
|
+
if (K += `.${P[Z]}`, !n.value.has(K)) {
|
|
1642
|
+
const ae = P[Z + 1], Ce = !isNaN(Number(ae));
|
|
1643
|
+
n.value.set(K, Ce ? [] : {});
|
|
1592
1644
|
}
|
|
1593
1645
|
}
|
|
1594
1646
|
}
|
|
1595
|
-
n.value.set(
|
|
1596
|
-
const u =
|
|
1597
|
-
u.length === 1 ? l[u[0]] =
|
|
1647
|
+
n.value.set(h.path, h.value);
|
|
1648
|
+
const u = h.fieldname.split("."), l = { ...i.value };
|
|
1649
|
+
u.length === 1 ? l[u[0]] = h.value : tt(l, u, h.value), i.value = l;
|
|
1598
1650
|
} catch {
|
|
1599
1651
|
}
|
|
1600
1652
|
};
|
|
1601
|
-
(o.doctype || e?.router) && (
|
|
1602
|
-
const G = (
|
|
1653
|
+
(o.doctype || e?.router) && (he("hstPathProvider", J), he("hstChangeHandler", B));
|
|
1654
|
+
const G = (h, v, y) => {
|
|
1603
1655
|
if (!r.value)
|
|
1604
|
-
return z(
|
|
1656
|
+
return z(v);
|
|
1605
1657
|
if (y)
|
|
1606
1658
|
try {
|
|
1607
|
-
const u = n.value?.get(
|
|
1608
|
-
return u && typeof u == "object" ? u : z(
|
|
1659
|
+
const u = n.value?.get(h);
|
|
1660
|
+
return u && typeof u == "object" ? u : z(v);
|
|
1609
1661
|
} catch {
|
|
1610
|
-
return z(
|
|
1662
|
+
return z(v);
|
|
1611
1663
|
}
|
|
1612
|
-
return z(
|
|
1613
|
-
},
|
|
1664
|
+
return z(v);
|
|
1665
|
+
}, m = (h, v) => {
|
|
1614
1666
|
if (!n.value || !r.value)
|
|
1615
1667
|
throw new Error("HST store not initialized");
|
|
1616
|
-
const y = `${
|
|
1617
|
-
(
|
|
1668
|
+
const y = `${h.slug}.${v}`, l = { ...n.value.get(y) || {} }, f = h.schema ? Array.isArray(h.schema) ? h.schema : Array.from(h.schema) : [], V = (e ? e.resolveSchema(f) : f).filter(
|
|
1669
|
+
(P) => "fieldtype" in P && P.fieldtype === "Doctype" && "schema" in P && Array.isArray(P.schema)
|
|
1618
1670
|
);
|
|
1619
|
-
for (const
|
|
1620
|
-
const K =
|
|
1671
|
+
for (const P of V) {
|
|
1672
|
+
const K = P, Z = `${y}.${K.fieldname}`, ae = Te(K.schema, Z, n.value);
|
|
1621
1673
|
l[K.fieldname] = ae;
|
|
1622
1674
|
}
|
|
1623
1675
|
return l;
|
|
1624
|
-
},
|
|
1625
|
-
provideHSTPath: (l) => `${
|
|
1676
|
+
}, C = (h, v) => ({
|
|
1677
|
+
provideHSTPath: (l) => `${h}.${l}`,
|
|
1626
1678
|
handleHSTChange: (l) => {
|
|
1627
|
-
const f = l.path.startsWith(
|
|
1628
|
-
|
|
1679
|
+
const f = l.path.startsWith(h) ? l.path : `${h}.${l.fieldname}`;
|
|
1680
|
+
B({
|
|
1629
1681
|
...l,
|
|
1630
1682
|
path: f
|
|
1631
1683
|
});
|
|
1632
1684
|
}
|
|
1633
1685
|
}), k = {
|
|
1634
1686
|
operations: d,
|
|
1635
|
-
currentIndex:
|
|
1687
|
+
currentIndex: p,
|
|
1636
1688
|
undoRedoState: F,
|
|
1637
1689
|
canUndo: S,
|
|
1638
1690
|
canRedo: $,
|
|
1639
1691
|
undoCount: D,
|
|
1640
|
-
redoCount:
|
|
1692
|
+
redoCount: N,
|
|
1641
1693
|
undo: R,
|
|
1642
1694
|
redo: O,
|
|
1643
1695
|
startBatch: b,
|
|
1644
1696
|
commitBatch: g,
|
|
1645
|
-
cancelBatch:
|
|
1697
|
+
cancelBatch: I,
|
|
1646
1698
|
clear: w,
|
|
1647
1699
|
getOperationsFor: A,
|
|
1648
|
-
getSnapshot:
|
|
1700
|
+
getSnapshot: E,
|
|
1649
1701
|
markIrreversible: M,
|
|
1650
1702
|
logAction: W,
|
|
1651
|
-
configure:
|
|
1703
|
+
configure: x
|
|
1652
1704
|
};
|
|
1653
1705
|
return o.doctype ? {
|
|
1654
1706
|
stonecrop: r,
|
|
1655
1707
|
operationLog: k,
|
|
1656
|
-
provideHSTPath:
|
|
1657
|
-
handleHSTChange:
|
|
1708
|
+
provideHSTPath: J,
|
|
1709
|
+
handleHSTChange: B,
|
|
1658
1710
|
hstStore: n,
|
|
1659
1711
|
formData: i,
|
|
1660
1712
|
resolvedSchema: c,
|
|
1661
1713
|
loadNestedData: G,
|
|
1662
|
-
saveRecursive:
|
|
1663
|
-
createNestedContext:
|
|
1714
|
+
saveRecursive: m,
|
|
1715
|
+
createNestedContext: C
|
|
1664
1716
|
} : !o.doctype && e?.router ? {
|
|
1665
1717
|
stonecrop: r,
|
|
1666
1718
|
operationLog: k,
|
|
1667
|
-
provideHSTPath:
|
|
1668
|
-
handleHSTChange:
|
|
1719
|
+
provideHSTPath: J,
|
|
1720
|
+
handleHSTChange: B,
|
|
1669
1721
|
hstStore: n,
|
|
1670
1722
|
formData: i,
|
|
1671
1723
|
resolvedSchema: c,
|
|
1672
1724
|
loadNestedData: G,
|
|
1673
|
-
saveRecursive:
|
|
1674
|
-
createNestedContext:
|
|
1725
|
+
saveRecursive: m,
|
|
1726
|
+
createNestedContext: C
|
|
1675
1727
|
} : {
|
|
1676
1728
|
stonecrop: r,
|
|
1677
1729
|
operationLog: k
|
|
@@ -1703,7 +1755,7 @@ function z(o) {
|
|
|
1703
1755
|
}
|
|
1704
1756
|
}), e;
|
|
1705
1757
|
}
|
|
1706
|
-
function
|
|
1758
|
+
function me(o, e, t, r) {
|
|
1707
1759
|
U(
|
|
1708
1760
|
t,
|
|
1709
1761
|
(n) => {
|
|
@@ -1742,7 +1794,7 @@ function $e(o) {
|
|
|
1742
1794
|
const t = (Se() ? fe("$operationLogStore", void 0) : void 0) || re();
|
|
1743
1795
|
o && t.configure(o);
|
|
1744
1796
|
const { operations: r, currentIndex: n, undoRedoState: i, canUndo: s, canRedo: a, undoCount: c, redoCount: d } = be(t);
|
|
1745
|
-
function
|
|
1797
|
+
function p(w) {
|
|
1746
1798
|
return t.undo(w);
|
|
1747
1799
|
}
|
|
1748
1800
|
function S(w) {
|
|
@@ -1754,7 +1806,7 @@ function $e(o) {
|
|
|
1754
1806
|
function D(w) {
|
|
1755
1807
|
return t.commitBatch(w);
|
|
1756
1808
|
}
|
|
1757
|
-
function
|
|
1809
|
+
function N() {
|
|
1758
1810
|
t.cancelBatch();
|
|
1759
1811
|
}
|
|
1760
1812
|
function F() {
|
|
@@ -1769,10 +1821,10 @@ function $e(o) {
|
|
|
1769
1821
|
function b(w, A) {
|
|
1770
1822
|
t.markIrreversible(w, A);
|
|
1771
1823
|
}
|
|
1772
|
-
function g(w, A,
|
|
1773
|
-
return t.logAction(w, A,
|
|
1824
|
+
function g(w, A, E, M = "success", W) {
|
|
1825
|
+
return t.logAction(w, A, E, M, W);
|
|
1774
1826
|
}
|
|
1775
|
-
function
|
|
1827
|
+
function I(w) {
|
|
1776
1828
|
t.configure(w);
|
|
1777
1829
|
}
|
|
1778
1830
|
return {
|
|
@@ -1785,17 +1837,17 @@ function $e(o) {
|
|
|
1785
1837
|
undoCount: c,
|
|
1786
1838
|
redoCount: d,
|
|
1787
1839
|
// Methods
|
|
1788
|
-
undo:
|
|
1840
|
+
undo: p,
|
|
1789
1841
|
redo: S,
|
|
1790
1842
|
startBatch: $,
|
|
1791
1843
|
commitBatch: D,
|
|
1792
|
-
cancelBatch:
|
|
1844
|
+
cancelBatch: N,
|
|
1793
1845
|
clear: F,
|
|
1794
1846
|
getOperationsFor: R,
|
|
1795
1847
|
getSnapshot: O,
|
|
1796
1848
|
markIrreversible: b,
|
|
1797
1849
|
logAction: g,
|
|
1798
|
-
configure:
|
|
1850
|
+
configure: I
|
|
1799
1851
|
};
|
|
1800
1852
|
}
|
|
1801
1853
|
function gt(o, e = !0) {
|
|
@@ -1813,7 +1865,7 @@ function gt(o, e = !0) {
|
|
|
1813
1865
|
i.value && r(o);
|
|
1814
1866
|
});
|
|
1815
1867
|
}
|
|
1816
|
-
async function
|
|
1868
|
+
async function pt(o, e) {
|
|
1817
1869
|
const { startBatch: t, commitBatch: r, cancelBatch: n } = $e();
|
|
1818
1870
|
t();
|
|
1819
1871
|
try {
|
|
@@ -1822,13 +1874,21 @@ async function ht(o, e) {
|
|
|
1822
1874
|
throw n(), i;
|
|
1823
1875
|
}
|
|
1824
1876
|
}
|
|
1825
|
-
class
|
|
1877
|
+
class mt {
|
|
1826
1878
|
/**
|
|
1827
1879
|
* The doctype name
|
|
1828
1880
|
* @public
|
|
1829
1881
|
* @readonly
|
|
1830
1882
|
*/
|
|
1831
1883
|
doctype;
|
|
1884
|
+
/**
|
|
1885
|
+
* Alias for doctype (for DoctypeLike interface compatibility)
|
|
1886
|
+
* @public
|
|
1887
|
+
* @readonly
|
|
1888
|
+
*/
|
|
1889
|
+
get name() {
|
|
1890
|
+
return this.doctype;
|
|
1891
|
+
}
|
|
1832
1892
|
/**
|
|
1833
1893
|
* The doctype schema
|
|
1834
1894
|
* @public
|
|
@@ -1952,7 +2012,7 @@ class te {
|
|
|
1952
2012
|
*/
|
|
1953
2013
|
addDoctype(e) {
|
|
1954
2014
|
e.slug in this.registry || (this.registry[e.slug] = e);
|
|
1955
|
-
const t =
|
|
2015
|
+
const t = q();
|
|
1956
2016
|
t.registerDoctypeActions(e.doctype, e.actions), e.slug !== e.doctype && t.registerDoctypeActions(e.slug, e.actions), e.component && this.router && !this.router.hasRoute(e.doctype) && this.router.addRoute({
|
|
1957
2017
|
path: `/${e.slug}`,
|
|
1958
2018
|
name: e.slug,
|
|
@@ -2113,13 +2173,13 @@ async function rt(o, e, t) {
|
|
|
2113
2173
|
} catch {
|
|
2114
2174
|
}
|
|
2115
2175
|
}
|
|
2116
|
-
const
|
|
2176
|
+
const vt = {
|
|
2117
2177
|
install: (o, e) => {
|
|
2118
2178
|
const t = o.config.globalProperties.$router, r = e?.router, n = t || r;
|
|
2119
2179
|
!t && r && o.use(r);
|
|
2120
2180
|
const i = new te(n, e?.getMeta);
|
|
2121
2181
|
o.provide("$registry", i), o.config.globalProperties.$registry = i;
|
|
2122
|
-
const s = new Oe(i);
|
|
2182
|
+
const s = new Oe(i, void 0, e?.client ? { client: e.client } : void 0);
|
|
2123
2183
|
o.provide("$stonecrop", s), o.config.globalProperties.$stonecrop = s;
|
|
2124
2184
|
try {
|
|
2125
2185
|
const a = o.config.globalProperties.$pinia;
|
|
@@ -2163,17 +2223,17 @@ class ot {
|
|
|
2163
2223
|
validate(e, t, r, n) {
|
|
2164
2224
|
const i = [], s = t ? Array.isArray(t) ? t : t.toArray() : [];
|
|
2165
2225
|
if (this.options.validateRequiredProperties && i.push(...this.validateRequiredProperties(e, s)), this.options.validateLinkTargets && this.options.registry && i.push(...this.validateLinkFields(e, s, this.options.registry)), this.options.validateWorkflows && r && i.push(...this.validateWorkflow(e, r)), this.options.validateActions && n) {
|
|
2166
|
-
const
|
|
2167
|
-
i.push(...this.validateActionRegistration(e,
|
|
2226
|
+
const p = n instanceof Map ? n : n.toObject();
|
|
2227
|
+
i.push(...this.validateActionRegistration(e, p));
|
|
2168
2228
|
}
|
|
2169
2229
|
const a = i.filter(
|
|
2170
|
-
(
|
|
2230
|
+
(p) => p.severity === "error"
|
|
2171
2231
|
/* ERROR */
|
|
2172
2232
|
).length, c = i.filter(
|
|
2173
|
-
(
|
|
2233
|
+
(p) => p.severity === "warning"
|
|
2174
2234
|
/* WARNING */
|
|
2175
2235
|
).length, d = i.filter(
|
|
2176
|
-
(
|
|
2236
|
+
(p) => p.severity === "info"
|
|
2177
2237
|
/* INFO */
|
|
2178
2238
|
).length;
|
|
2179
2239
|
return {
|
|
@@ -2290,11 +2350,11 @@ class ot {
|
|
|
2290
2350
|
for (const [s, a] of Object.entries(t.states)) {
|
|
2291
2351
|
const c = a;
|
|
2292
2352
|
if (c.on) {
|
|
2293
|
-
for (const [d,
|
|
2294
|
-
if (typeof
|
|
2295
|
-
i.add(
|
|
2296
|
-
else if (
|
|
2297
|
-
const S = "target" in
|
|
2353
|
+
for (const [d, p] of Object.entries(c.on))
|
|
2354
|
+
if (typeof p == "string")
|
|
2355
|
+
i.add(p);
|
|
2356
|
+
else if (p && typeof p == "object") {
|
|
2357
|
+
const S = "target" in p ? p.target : void 0;
|
|
2298
2358
|
typeof S == "string" ? i.add(S) : Array.isArray(S) && S.forEach(($) => {
|
|
2299
2359
|
typeof $ == "string" && i.add($);
|
|
2300
2360
|
});
|
|
@@ -2316,7 +2376,7 @@ class ot {
|
|
|
2316
2376
|
* @internal
|
|
2317
2377
|
*/
|
|
2318
2378
|
validateActionRegistration(e, t) {
|
|
2319
|
-
const r = [], n =
|
|
2379
|
+
const r = [], n = q();
|
|
2320
2380
|
for (const [i, s] of Object.entries(t)) {
|
|
2321
2381
|
if (!Array.isArray(s)) {
|
|
2322
2382
|
r.push({
|
|
@@ -2352,7 +2412,7 @@ function yt(o, e, t, r, n) {
|
|
|
2352
2412
|
return it(t).validate(o, e, r, n);
|
|
2353
2413
|
}
|
|
2354
2414
|
export {
|
|
2355
|
-
|
|
2415
|
+
mt as DoctypeMeta,
|
|
2356
2416
|
Y as HST,
|
|
2357
2417
|
te as Registry,
|
|
2358
2418
|
ot as SchemaValidator,
|
|
@@ -2360,8 +2420,8 @@ export {
|
|
|
2360
2420
|
nt as ValidationSeverity,
|
|
2361
2421
|
et as createHST,
|
|
2362
2422
|
it as createValidator,
|
|
2363
|
-
|
|
2364
|
-
|
|
2423
|
+
vt as default,
|
|
2424
|
+
q as getGlobalTriggerEngine,
|
|
2365
2425
|
dt as markOperationIrreversible,
|
|
2366
2426
|
ct as registerGlobalAction,
|
|
2367
2427
|
lt as registerTransitionAction,
|
|
@@ -2369,9 +2429,9 @@ export {
|
|
|
2369
2429
|
ft as triggerTransition,
|
|
2370
2430
|
$e as useOperationLog,
|
|
2371
2431
|
re as useOperationLogStore,
|
|
2372
|
-
|
|
2432
|
+
ht as useStonecrop,
|
|
2373
2433
|
gt as useUndoRedoShortcuts,
|
|
2374
2434
|
yt as validateSchema,
|
|
2375
|
-
|
|
2435
|
+
pt as withBatch
|
|
2376
2436
|
};
|
|
2377
2437
|
//# sourceMappingURL=stonecrop.js.map
|