@stonecrop/stonecrop 0.10.1 → 0.10.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.
Files changed (39) hide show
  1. package/README.md +60 -72
  2. package/dist/composables/operation-log.js +7 -4
  3. package/dist/{composable.js → composables/stonecrop.js} +3 -4
  4. package/dist/doctype.js +35 -0
  5. package/dist/index.js +1 -1
  6. package/dist/plugins/index.js +8 -2
  7. package/dist/registry.js +9 -0
  8. package/dist/src/composables/operation-log.d.ts.map +1 -1
  9. package/dist/src/{composable.d.ts → composables/stonecrop.d.ts} +6 -6
  10. package/dist/src/composables/stonecrop.d.ts.map +1 -0
  11. package/dist/src/doctype.d.ts +25 -0
  12. package/dist/src/doctype.d.ts.map +1 -1
  13. package/dist/src/index.d.ts +4 -4
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/plugins/index.d.ts +6 -1
  16. package/dist/src/plugins/index.d.ts.map +1 -1
  17. package/dist/src/registry.d.ts +7 -0
  18. package/dist/src/registry.d.ts.map +1 -1
  19. package/dist/src/stonecrop.d.ts +72 -4
  20. package/dist/src/stonecrop.d.ts.map +1 -1
  21. package/dist/src/stores/operation-log.d.ts +1 -1
  22. package/dist/src/stores/operation-log.d.ts.map +1 -1
  23. package/dist/src/types/index.d.ts +17 -0
  24. package/dist/src/types/index.d.ts.map +1 -1
  25. package/dist/stonecrop.d.ts +128 -6
  26. package/dist/stonecrop.js +449 -337
  27. package/dist/stonecrop.js.map +1 -1
  28. package/dist/stores/operation-log.js +0 -3
  29. package/package.json +5 -4
  30. package/src/composables/operation-log.ts +7 -4
  31. package/src/{composable.ts → composables/stonecrop.ts} +8 -9
  32. package/src/doctype.ts +35 -0
  33. package/src/index.ts +4 -3
  34. package/src/plugins/index.ts +8 -2
  35. package/src/registry.ts +10 -0
  36. package/src/stonecrop.ts +127 -10
  37. package/src/stores/operation-log.ts +0 -3
  38. package/src/types/index.ts +17 -0
  39. 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 me, nextTick as de, readonly as ye, getCurrentInstance as Pe, toRef as Ie, customRef as Ee, ref as L, reactive as ue, computed as B, toValue as H, shallowRef as Se, unref as Ce, inject as fe, provide as pe } from "vue";
2
- import { defineStore as De, storeToRefs as be } from "pinia";
3
- const ke = typeof window < "u" && typeof document < "u";
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
+ import { defineStore as ke, storeToRefs as be } from "pinia";
3
+ const De = typeof window < "u" && typeof document < "u";
4
4
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
5
- const Le = Object.prototype.toString, Me = (o) => Le.call(o) === "[object Object]", we = () => {
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 Ie(...o);
8
+ if (o.length !== 1) return Pe(...o);
9
9
  const e = o[0];
10
- return typeof e == "function" ? ye(Ee(() => ({
10
+ return typeof e == "function" ? ye(Ie(() => ({
11
11
  get: e,
12
- set: we
12
+ set: Re
13
13
  }))) : L(e);
14
14
  }
15
- function xe(o, e) {
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), {
@@ -24,8 +24,8 @@ function xe(o, e) {
24
24
  }
25
25
  return t;
26
26
  }
27
- const Re = (o) => o();
28
- function Ne(o = Re, e = {}) {
27
+ const Ae = (o) => o();
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 = Re, e = {}) {
46
46
  function ce(o) {
47
47
  return Array.isArray(o) ? o : [o];
48
48
  }
49
- function Be(o) {
50
- return Pe();
49
+ function _e(o) {
50
+ return Se();
51
51
  }
52
- function _e(o, e, t = {}) {
53
- const { eventFilter: r = Re, ...n } = t;
54
- return U(o, xe(r, e), n);
52
+ function Be(o, e, t = {}) {
53
+ const { eventFilter: r = Ae, ...n } = t;
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 } = Ne(r, { initialState: n });
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: _e(o, e, {
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
- Be() ? me(o, t) : e ? o() : de(o);
69
+ _e() ? ve(o, t) : e ? o() : de(o);
70
70
  }
71
71
  function ze(o, e, t) {
72
72
  return U(o, e, {
@@ -82,14 +82,14 @@ function X(o, e, t) {
82
82
  once: !1
83
83
  });
84
84
  }
85
- const j = ke ? window : void 0;
85
+ const j = De ? window : void 0;
86
86
  function He(o) {
87
87
  var e;
88
88
  const t = H(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 = B(() => {
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(Ce(t.value ? o[2] : o[1])),
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, g = r.flatMap((S) => n.flatMap(($) => i.map((k) => e(S, $, k, d))));
106
+ const d = Me(s) ? { ...s } : s, p = r.flatMap((S) => n.flatMap(($) => i.map((D) => e(S, $, D, d))));
107
107
  c(() => {
108
- g.forEach((S) => S());
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__ */ Je();
113
- function Je() {
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 qe(o, e) {
116
+ function Je(o, e) {
117
117
  return Ue[o] || e;
118
118
  }
119
119
  function Ke(o) {
@@ -152,90 +152,90 @@ const je = {
152
152
  read: (o) => new Date(o),
153
153
  write: (o) => o.toISOString()
154
154
  }
155
- }, he = "vueuse-storage";
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: g, window: S = j, eventFilter: $, onError: k = (v) => {
159
- console.error(v);
160
- }, initOnMounted: x } = r, F = (g ? Se : L)(e), R = B(() => H(o));
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 = qe("getDefaultStorage", () => j?.localStorage)();
163
- } catch (v) {
164
- k(v);
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), w = Ke(O), h = (n = r.serializer) !== null && n !== void 0 ? n : je[w], { pause: E, resume: b } = Ve(F, (v) => N(v), {
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, () => _(), { flush: i });
172
+ U(R, () => B(), { flush: i });
173
173
  let A = !1;
174
- const C = (v) => {
175
- x && !A || _(v);
176
- }, M = (v) => {
177
- x && !A || G(v);
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", C, { passive: !0 }) : Q(S, he, M)), x ? We(() => {
180
- A = !0, _();
181
- }) : _();
182
- function W(v, P) {
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
- const D = {
184
+ const k = {
185
185
  key: R.value,
186
- oldValue: v,
187
- newValue: P,
186
+ oldValue: m,
187
+ newValue: C,
188
188
  storageArea: t
189
189
  };
190
- S.dispatchEvent(t instanceof Storage ? new StorageEvent("storage", D) : new CustomEvent(he, { detail: D }));
190
+ S.dispatchEvent(t instanceof Storage ? new StorageEvent("storage", k) : new CustomEvent(ge, { detail: k }));
191
191
  }
192
192
  }
193
- function N(v) {
193
+ function x(m) {
194
194
  try {
195
- const P = t.getItem(R.value);
196
- if (v == null)
197
- W(P, null), t.removeItem(R.value);
195
+ const C = t.getItem(R.value);
196
+ if (m == null)
197
+ W(C, null), t.removeItem(R.value);
198
198
  else {
199
- const D = h.write(v);
200
- P !== D && (t.setItem(R.value, D), W(P, D));
199
+ const k = g.write(m);
200
+ C !== k && (t.setItem(R.value, k), W(C, k));
201
201
  }
202
- } catch (P) {
203
- k(P);
202
+ } catch (C) {
203
+ D(C);
204
204
  }
205
205
  }
206
- function q(v) {
207
- const P = v ? v.newValue : t.getItem(R.value);
208
- if (P == null)
209
- return c && O != null && t.setItem(R.value, h.write(O)), O;
210
- if (!v && d) {
211
- const D = h.read(P);
212
- return typeof d == "function" ? d(D, O) : w === "object" && !Array.isArray(D) ? {
206
+ function J(m) {
207
+ const C = m ? m.newValue : t.getItem(R.value);
208
+ if (C == null)
209
+ return c && O != null && t.setItem(R.value, g.write(O)), O;
210
+ if (!m && d) {
211
+ const k = g.read(C);
212
+ return typeof d == "function" ? d(k, O) : b === "object" && !Array.isArray(k) ? {
213
213
  ...O,
214
- ...D
215
- } : D;
216
- } else return typeof P != "string" ? P : h.read(P);
214
+ ...k
215
+ } : k;
216
+ } else return typeof C != "string" ? C : g.read(C);
217
217
  }
218
- function _(v) {
219
- if (!(v && v.storageArea !== t)) {
220
- if (v && v.key == null) {
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 (!(v && v.key !== R.value)) {
225
- E();
224
+ if (!(m && m.key !== R.value)) {
225
+ I();
226
226
  try {
227
- const P = h.write(F.value);
228
- (v === void 0 || v?.newValue !== P) && (F.value = q(v));
229
- } catch (P) {
230
- k(P);
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
- v ? de(b) : b();
232
+ m ? de(w) : w();
233
233
  }
234
234
  }
235
235
  }
236
236
  }
237
- function G(v) {
238
- _(v.detail);
237
+ function G(m) {
238
+ B(m.detail);
239
239
  }
240
240
  return F;
241
241
  }
@@ -254,61 +254,61 @@ const Qe = {
254
254
  right: "arrowright"
255
255
  };
256
256
  function Ye(o = {}) {
257
- const { reactive: e = !1, target: t = j, aliasMap: r = Qe, passive: n = !0, onEventFired: i = we } = o, s = ue(/* @__PURE__ */ new Set()), a = {
257
+ const { reactive: e = !1, target: t = j, aliasMap: r = Qe, passive: n = !0, onEventFired: i = Re } = o, s = ue(/* @__PURE__ */ new Set()), a = {
258
258
  toJSON() {
259
259
  return {};
260
260
  },
261
261
  current: s
262
- }, c = e ? ue(a) : a, d = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map([
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()]
266
266
  ]), S = /* @__PURE__ */ new Set();
267
- function $(w, h) {
268
- w in c && (e ? c[w] = h : c[w].value = h);
267
+ function $(b, g) {
268
+ b in c && (e ? c[b] = g : c[b].value = g);
269
269
  }
270
- function k() {
270
+ function D() {
271
271
  s.clear();
272
- for (const w of S) $(w, !1);
272
+ for (const b of S) $(b, !1);
273
273
  }
274
- function x(w, h, E) {
275
- if (!(!w || typeof h.getModifierState != "function")) {
276
- for (const [b, A] of g) if (h.getModifierState(b)) {
277
- E.forEach((C) => A.add(C));
274
+ function N(b, g, I) {
275
+ if (!(!b || typeof g.getModifierState != "function")) {
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
- function F(w, h) {
283
- if (w) return;
284
- const E = `${h[0].toUpperCase()}${h.slice(1)}`, b = g.get(E);
285
- if (!["shift", "alt"].includes(h) || !b) return;
286
- const A = Array.from(b), C = A.indexOf(h);
282
+ function F(b, g) {
283
+ if (b) return;
284
+ const I = `${g[0].toUpperCase()}${g.slice(1)}`, w = p.get(I);
285
+ if (!["shift", "alt"].includes(g) || !w) return;
286
+ const A = Array.from(w), E = A.indexOf(g);
287
287
  A.forEach((M, W) => {
288
- W >= C && (s.delete(M), $(M, !1));
289
- }), b.clear();
288
+ W >= E && (s.delete(M), $(M, !1));
289
+ }), w.clear();
290
290
  }
291
- function R(w, h) {
292
- var E, b;
293
- const A = (E = w.key) === null || E === void 0 ? void 0 : E.toLowerCase(), C = [(b = w.code) === null || b === void 0 ? void 0 : b.toLowerCase(), A].filter(Boolean);
291
+ function R(b, g) {
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
- A && (h ? s.add(A) : s.delete(A));
296
- for (const M of C)
297
- S.add(M), $(M, h);
298
- x(h, w, [...s, ...C]), F(h, A), A === "meta" && !h && (d.forEach((M) => {
295
+ A && (g ? s.add(A) : s.delete(A));
296
+ for (const M of E)
297
+ S.add(M), $(M, g);
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
- Q(t, "keydown", (w) => (R(w, !0), i(w)), { passive: n }), Q(t, "keyup", (w) => (R(w, !1), i(w)), { passive: n }), Q("blur", k, { passive: n }), Q("focus", k, { passive: n });
304
- const O = new Proxy(c, { get(w, h, E) {
305
- if (typeof h != "string") return Reflect.get(w, h, E);
306
- if (h = h.toLowerCase(), h in r && (h = r[h]), !(h in c)) if (/[+_-]/.test(h)) {
307
- const A = h.split(/[+_-]/g).map((C) => C.trim());
308
- c[h] = B(() => A.map((C) => H(O[C])).every(Boolean));
309
- } else c[h] = Se(!1);
310
- const b = Reflect.get(w, h, E);
311
- return e ? H(b) : b;
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, I) {
305
+ if (typeof g != "string") return Reflect.get(b, g, I);
306
+ if (g = g.toLowerCase(), g in r && (g = r[g]), !(g in c)) if (/[+_-]/.test(g)) {
307
+ const A = g.split(/[+_-]/g).map((E) => E.trim());
308
+ c[g] = _(() => A.map((E) => H(O[E])).every(Boolean));
309
+ } else c[g] = we(!1);
310
+ const w = Reflect.get(b, g, I);
311
+ return e ? H(w) : w;
312
312
  } });
313
313
  return O;
314
314
  }
@@ -343,29 +343,29 @@ function Xe(o) {
343
343
  timestamp: new Date(t.timestamp)
344
344
  }))), e;
345
345
  }
346
- const re = De("hst-operation-log", () => {
346
+ const re = ke("hst-operation-log", () => {
347
347
  const o = L({
348
348
  maxOperations: 100,
349
349
  enableCrossTabSync: !0,
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 = B(() => t.value < 0 ? !1 : e.value[t.value]?.reversible ?? !1), c = B(() => t.value < e.value.length - 1), d = B(() => {
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
- }), g = B(() => e.value.length - 1 - t.value), S = B(() => ({
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: g.value,
362
+ redoCount: p.value,
363
363
  currentIndex: t.value
364
364
  }));
365
365
  function $(u) {
366
- o.value = { ...o.value, ...u }, o.value.enablePersistence && (p(), y()), o.value.enableCrossTabSync && q();
366
+ o.value = { ...o.value, ...u }, o.value.enablePersistence && (h(), y()), o.value.enableCrossTabSync && J();
367
367
  }
368
- function k(u, l = "user") {
368
+ function D(u, l = "user") {
369
369
  const f = {
370
370
  ...u,
371
371
  id: le(),
@@ -381,15 +381,15 @@ const re = De("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 && _(f), f.id;
384
+ return o.value.enableCrossTabSync && B(f), f.id;
385
385
  }
386
- function x() {
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((I) => I.reversible), T = {
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 = De("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((I) => I.id),
405
+ childOperationIds: i.value.map((P) => P.id),
406
406
  metadata: { description: u }
407
407
  };
408
- i.value.forEach((I) => {
409
- I.parentOperationId = l;
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,39 +422,39 @@ const re = De("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((I) => I.id === T);
426
- V && h(V, u);
425
+ const T = l.childOperationIds[f], V = e.value.find((P) => P.id === T);
426
+ V && g(V, u);
427
427
  }
428
428
  else
429
- h(l, u);
430
- return t.value--, o.value.enableCrossTabSync && v(l), !0;
429
+ g(l, u);
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
  }
434
434
  }
435
- function w(u) {
435
+ function b(u) {
436
436
  if (!c.value) return !1;
437
437
  const l = e.value[t.value + 1];
438
438
  try {
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 && E(T, u);
442
+ T && I(T, u);
443
443
  }
444
444
  else
445
- E(l, u);
446
- return t.value++, o.value.enableCrossTabSync && P(l), !0;
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
  }
450
450
  }
451
- function h(u, l) {
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 E(u, l) {
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
- function b() {
457
+ function w() {
458
458
  const u = e.value.filter((f) => f.reversible).length, l = e.value.map((f) => f.timestamp);
459
459
  return {
460
460
  operations: [...e.value],
@@ -469,7 +469,7 @@ const re = De("hst-operation-log", () => {
469
469
  function A() {
470
470
  e.value = [], t.value = -1;
471
471
  }
472
- function C(u, l) {
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 = De("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 I = {
480
+ const P = {
481
481
  type: "action",
482
482
  path: f && f.length > 0 ? `${u}.${f[0]}` : u,
483
483
  fieldname: "",
@@ -492,58 +492,58 @@ const re = De("hst-operation-log", () => {
492
492
  actionResult: T,
493
493
  actionError: V
494
494
  };
495
- return k(I);
495
+ return D(P);
496
496
  }
497
- let N = null;
498
- function q() {
499
- typeof window > "u" || !window.BroadcastChannel || (N = new BroadcastChannel("stonecrop-operation-log"), N.addEventListener("message", (u) => {
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 _(u) {
507
- if (!N) return;
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
- N.postMessage(ie(l));
514
+ x.postMessage(ie(l));
515
515
  }
516
516
  function G(u, l) {
517
- if (!N) return;
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
- N.postMessage(ie(f));
524
+ x.postMessage(ie(f));
525
525
  }
526
- function v(u) {
527
- if (!N) return;
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
- N.postMessage(ie(l));
534
+ x.postMessage(ie(l));
535
535
  }
536
- function P(u) {
537
- if (!N) return;
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
- N.postMessage(ie(l));
544
+ x.postMessage(ie(l));
545
545
  }
546
- const D = Ze("stonecrop-ops-operations", null, {
546
+ const k = Ze("stonecrop-ops-operations", null, {
547
547
  serializer: {
548
548
  read: (u) => {
549
549
  try {
@@ -555,10 +555,10 @@ const re = De("hst-operation-log", () => {
555
555
  write: (u) => u ? JSON.stringify(u) : ""
556
556
  }
557
557
  });
558
- function p() {
558
+ function h() {
559
559
  if (!(typeof window > "u"))
560
560
  try {
561
- const u = D.value;
561
+ const u = k.value;
562
562
  u && Array.isArray(u.operations) && (e.value = u.operations.map((l) => ({
563
563
  ...l,
564
564
  timestamp: new Date(l.timestamp)
@@ -567,10 +567,10 @@ const re = De("hst-operation-log", () => {
567
567
  typeof console < "u" && console.error("Failed to load operations from persistence:", u);
568
568
  }
569
569
  }
570
- function m() {
570
+ function v() {
571
571
  if (!(typeof window > "u"))
572
572
  try {
573
- D.value = {
573
+ k.value = {
574
574
  operations: e.value.map((u) => ({
575
575
  ...u,
576
576
  timestamp: u.timestamp.toISOString()
@@ -585,7 +585,7 @@ const re = De("hst-operation-log", () => {
585
585
  U(
586
586
  [e, t],
587
587
  () => {
588
- o.value.enablePersistence && m();
588
+ o.value.enablePersistence && v();
589
589
  },
590
590
  { deep: !0 }
591
591
  );
@@ -601,18 +601,18 @@ const re = De("hst-operation-log", () => {
601
601
  canUndo: a,
602
602
  canRedo: c,
603
603
  undoCount: d,
604
- redoCount: g,
604
+ redoCount: p,
605
605
  // Methods
606
606
  configure: $,
607
- addOperation: k,
608
- startBatch: x,
607
+ addOperation: D,
608
+ startBatch: N,
609
609
  commitBatch: F,
610
610
  cancelBatch: R,
611
611
  undo: O,
612
- redo: w,
612
+ redo: b,
613
613
  clear: A,
614
- getOperationsFor: C,
615
- getSnapshot: b,
614
+ getOperationsFor: E,
615
+ getSnapshot: w,
616
616
  markIrreversible: M,
617
617
  logAction: W
618
618
  };
@@ -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, g;
733
+ let c = !1, d = !1, p;
734
734
  const S = this.getFieldRollback(r, n), $ = t.enableRollback ?? S ?? this.options.enableRollback;
735
- $ && e.store && (g = this.captureSnapshot(e));
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);
@@ -741,24 +741,24 @@ class ee {
741
741
  break;
742
742
  }
743
743
  } catch (O) {
744
- const h = {
744
+ const g = {
745
745
  success: !1,
746
746
  error: O instanceof Error ? O : new Error(String(O)),
747
747
  executionTime: 0,
748
748
  action: R
749
749
  };
750
- a.push(h), c = !0;
750
+ a.push(g), c = !0;
751
751
  break;
752
752
  }
753
- if ($ && c && g && e.store)
753
+ if ($ && c && p && e.store)
754
754
  try {
755
- this.restoreSnapshot(e, g), d = !0;
755
+ this.restoreSnapshot(e, p), d = !0;
756
756
  } catch (R) {
757
757
  console.error("[FieldTriggers] Rollback failed:", R);
758
758
  }
759
- const k = performance.now() - s, x = a.filter((R) => !R.success);
760
- if (x.length > 0 && this.options.errorHandler)
761
- for (const R of x)
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) {
@@ -767,11 +767,11 @@ class ee {
767
767
  return {
768
768
  path: e.path,
769
769
  actionResults: a,
770
- totalExecutionTime: k,
770
+ totalExecutionTime: D,
771
771
  allSucceeded: a.every((R) => R.success),
772
772
  stoppedOnError: c,
773
773
  rolledBack: d,
774
- snapshot: this.options.debug && $ ? g : void 0
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 J(o) {
956
+ function q(o) {
957
957
  return new ee(o);
958
958
  }
959
959
  function ct(o, e) {
960
- J().registerAction(o, e);
960
+ q().registerAction(o, e);
961
961
  }
962
962
  function lt(o, e) {
963
- J().registerTransitionAction(o, e);
963
+ q().registerTransitionAction(o, e);
964
964
  }
965
965
  function ut(o, e, t) {
966
- J().setFieldRollback(o, e, t);
966
+ q().setFieldRollback(o, e, t);
967
967
  }
968
968
  async function ft(o, e, t) {
969
- const r = J(), n = {
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 ge() {
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 = ge();
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, g = a.slice(2).join(".") || a[a.length - 1], $ = t === void 0 && i !== void 0 ? "delete" : "set";
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: g,
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 = J(), n = this.parentPath.split(".");
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 = ge();
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 = J(), s = n.slice(2).join(".") || n[n.length - 1];
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;
@@ -1276,19 +1276,44 @@ class se {
1276
1276
  function et(o, e, t) {
1277
1277
  return new se(o, e, "", null, t);
1278
1278
  }
1279
- class Ae {
1279
+ 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 Ae {
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((g) => typeof g == "string") : void 0, a = this.getOperationLogStore();
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((g) => {
1421
+ i && i.length > 0 && i.forEach((p) => {
1397
1422
  try {
1398
- new Function("args", g)(r);
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 Ae {
1406
1431
  }
1407
1432
  }
1408
1433
  /**
1409
- * Get records from server (maintains compatibility)
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
- (await (await fetch(`/${e.slug}`)).json()).forEach((n) => {
1414
- n.id && this.addRecord(e, n.id, n);
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 (maintains compatibility)
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
- const n = await (await fetch(`/${e.slug}/${t}`)).json();
1424
- this.addRecord(e, t, n);
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
@@ -1447,15 +1499,34 @@ class Ae {
1447
1499
  getStore() {
1448
1500
  return this.hstStore;
1449
1501
  }
1502
+ /**
1503
+ * Determine the current workflow state for a record.
1504
+ *
1505
+ * Reads the record's `status` field from the HST store. If the field is absent or
1506
+ * empty the doctype's declared `workflow.initial` state is used as the fallback,
1507
+ * giving callers a reliable state name without having to duplicate that logic.
1508
+ *
1509
+ * @param doctype - The doctype slug or DoctypeMeta instance
1510
+ * @param recordId - The record identifier
1511
+ * @returns The current state name, or an empty string if the doctype has no workflow
1512
+ *
1513
+ * @public
1514
+ */
1515
+ getRecordState(e, t) {
1516
+ const r = typeof e == "string" ? e : e.slug, n = this.registry.getDoctype(r);
1517
+ if (!n?.workflow) return "";
1518
+ const s = this.getRecordById(r, t)?.get("status"), a = typeof n.workflow.initial == "string" ? n.workflow.initial : Object.keys(n.workflow.states ?? {})[0] ?? "";
1519
+ return s || a;
1520
+ }
1450
1521
  }
1451
- function pt(o) {
1522
+ function ht(o) {
1452
1523
  o || (o = {});
1453
1524
  const e = o.registry || fe("$registry"), t = fe("$stonecrop"), r = L(), n = L(), i = L({}), s = L(), a = L(), c = L([]);
1454
1525
  if (o.doctype && e) {
1455
- const p = o.doctype.schema ? Array.isArray(o.doctype.schema) ? o.doctype.schema : Array.from(o.doctype.schema) : [];
1456
- c.value = e.resolveSchema(p);
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);
1457
1528
  }
1458
- const d = L([]), g = L(-1), S = B(() => r.value?.getOperationLogStore().canUndo ?? !1), $ = B(() => r.value?.getOperationLogStore().canRedo ?? !1), k = B(() => r.value?.getOperationLogStore().undoCount ?? 0), x = B(() => r.value?.getOperationLogStore().redoCount ?? 0), F = B(
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 = _(
1459
1530
  () => r.value?.getOperationLogStore().undoRedoState ?? {
1460
1531
  canUndo: !1,
1461
1532
  canRedo: !1,
@@ -1463,49 +1534,49 @@ function pt(o) {
1463
1534
  redoCount: 0,
1464
1535
  currentIndex: -1
1465
1536
  }
1466
- ), R = (p) => r.value?.getOperationLogStore().undo(p) ?? !1, O = (p) => r.value?.getOperationLogStore().redo(p) ?? !1, w = () => {
1537
+ ), R = (h) => r.value?.getOperationLogStore().undo(h) ?? !1, O = (h) => r.value?.getOperationLogStore().redo(h) ?? !1, b = () => {
1467
1538
  r.value?.getOperationLogStore().startBatch();
1468
- }, h = (p) => r.value?.getOperationLogStore().commitBatch(p) ?? null, E = () => {
1539
+ }, g = (h) => r.value?.getOperationLogStore().commitBatch(h) ?? null, I = () => {
1469
1540
  r.value?.getOperationLogStore().cancelBatch();
1470
- }, b = () => {
1541
+ }, w = () => {
1471
1542
  r.value?.getOperationLogStore().clear();
1472
- }, A = (p, m) => r.value?.getOperationLogStore().getOperationsFor(p, m) ?? [], C = () => r.value?.getOperationLogStore().getSnapshot() ?? {
1543
+ }, A = (h, v) => r.value?.getOperationLogStore().getOperationsFor(h, v) ?? [], E = () => r.value?.getOperationLogStore().getSnapshot() ?? {
1473
1544
  operations: [],
1474
1545
  currentIndex: -1,
1475
1546
  totalOperations: 0,
1476
1547
  reversibleOperations: 0,
1477
1548
  irreversibleOperations: 0
1478
- }, M = (p, m) => {
1479
- r.value?.getOperationLogStore().markIrreversible(p, m);
1480
- }, W = (p, m, y, u = "success", l) => r.value?.getOperationLogStore().logAction(p, m, y, u, l) ?? "", N = (p) => {
1481
- r.value?.getOperationLogStore().configure(p);
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);
1482
1553
  };
1483
- me(async () => {
1554
+ ve(async () => {
1484
1555
  if (e) {
1485
- r.value = t || new Ae(e);
1556
+ r.value = t || new Oe(e);
1486
1557
  try {
1487
- const p = r.value.getOperationLogStore(), m = be(p);
1488
- d.value = m.operations.value, g.value = m.currentIndex.value, U(
1489
- () => m.operations.value,
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,
1490
1561
  (y) => {
1491
1562
  d.value = y;
1492
1563
  }
1493
1564
  ), U(
1494
- () => m.currentIndex.value,
1565
+ () => v.currentIndex.value,
1495
1566
  (y) => {
1496
- g.value = y;
1567
+ p.value = y;
1497
1568
  }
1498
1569
  );
1499
1570
  } catch {
1500
1571
  }
1501
1572
  if (!o.doctype && e.router) {
1502
- const p = e.router.currentRoute.value;
1503
- if (!p.path) return;
1504
- const m = p.path.split("/").filter((u) => u.length > 0), y = m[1]?.toLowerCase();
1505
- if (m.length > 0) {
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) {
1506
1577
  const u = {
1507
- path: p.path,
1508
- segments: m
1578
+ path: h.path,
1579
+ segments: v
1509
1580
  }, l = await e.getMeta?.(u);
1510
1581
  if (l) {
1511
1582
  if (e.addDoctype(l), r.value.setup(l), s.value = l, a.value = y, n.value = r.value.getStore(), e) {
@@ -1526,136 +1597,136 @@ function pt(o) {
1526
1597
  }
1527
1598
  } else
1528
1599
  i.value = z(l);
1529
- n.value && ve(l, y || "new", i, n.value), r.value.runAction(l, "load", y ? [y] : void 0);
1600
+ n.value && me(l, y || "new", i, n.value), r.value.runAction(l, "load", y ? [y] : void 0);
1530
1601
  }
1531
1602
  }
1532
1603
  }
1533
1604
  if (o.doctype) {
1534
1605
  n.value = r.value.getStore();
1535
- const p = o.doctype, m = o.recordId;
1536
- if (m && m !== "new") {
1537
- const y = r.value.getRecordById(p, m);
1606
+ const h = o.doctype, v = o.recordId;
1607
+ if (v && v !== "new") {
1608
+ const y = r.value.getRecordById(h, v);
1538
1609
  if (y)
1539
1610
  i.value = y.get("") || {};
1540
1611
  else
1541
1612
  try {
1542
- await r.value.getRecord(p, m);
1543
- const u = r.value.getRecordById(p, m);
1613
+ await r.value.getRecord(h, v);
1614
+ const u = r.value.getRecordById(h, v);
1544
1615
  u && (i.value = u.get("") || {});
1545
1616
  } catch {
1546
- i.value = z(p);
1617
+ i.value = z(h);
1547
1618
  }
1548
1619
  } else
1549
- i.value = z(p);
1550
- n.value && ve(p, m || "new", i, n.value);
1620
+ i.value = z(h);
1621
+ n.value && me(h, v || "new", i, n.value);
1551
1622
  }
1552
1623
  }
1553
1624
  });
1554
- const q = (p, m) => {
1625
+ const J = (h, v) => {
1555
1626
  const y = o.doctype || s.value;
1556
1627
  if (!y) return "";
1557
- const u = m || o.recordId || a.value || "new";
1558
- return `${y.slug}.${u}.${p}`;
1559
- }, _ = (p) => {
1560
- const m = o.doctype || s.value;
1561
- if (!(!n.value || !r.value || !m))
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))
1562
1633
  try {
1563
- const y = p.path.split(".");
1634
+ const y = h.path.split(".");
1564
1635
  if (y.length >= 2) {
1565
1636
  const f = y[0], T = y[1];
1566
- if (n.value.has(`${f}.${T}`) || r.value.addRecord(m, T, { ...i.value }), y.length > 3) {
1567
- const V = `${f}.${T}`, I = y.slice(2);
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);
1568
1639
  let K = V;
1569
- for (let Z = 0; Z < I.length - 1; Z++)
1570
- if (K += `.${I[Z]}`, !n.value.has(K)) {
1571
- const ae = I[Z + 1], $e = !isNaN(Number(ae));
1572
- n.value.set(K, $e ? [] : {});
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 ? [] : {});
1573
1644
  }
1574
1645
  }
1575
1646
  }
1576
- n.value.set(p.path, p.value);
1577
- const u = p.fieldname.split("."), l = { ...i.value };
1578
- u.length === 1 ? l[u[0]] = p.value : tt(l, u, p.value), i.value = l;
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;
1579
1650
  } catch {
1580
1651
  }
1581
1652
  };
1582
- (o.doctype || e?.router) && (pe("hstPathProvider", q), pe("hstChangeHandler", _));
1583
- const G = (p, m, y) => {
1653
+ (o.doctype || e?.router) && (he("hstPathProvider", J), he("hstChangeHandler", B));
1654
+ const G = (h, v, y) => {
1584
1655
  if (!r.value)
1585
- return z(m);
1656
+ return z(v);
1586
1657
  if (y)
1587
1658
  try {
1588
- const u = n.value?.get(p);
1589
- return u && typeof u == "object" ? u : z(m);
1659
+ const u = n.value?.get(h);
1660
+ return u && typeof u == "object" ? u : z(v);
1590
1661
  } catch {
1591
- return z(m);
1662
+ return z(v);
1592
1663
  }
1593
- return z(m);
1594
- }, v = async (p, m) => {
1664
+ return z(v);
1665
+ }, m = (h, v) => {
1595
1666
  if (!n.value || !r.value)
1596
1667
  throw new Error("HST store not initialized");
1597
- const y = `${p.slug}.${m}`, l = { ...n.value.get(y) || {} }, f = p.schema ? Array.isArray(p.schema) ? p.schema : Array.from(p.schema) : [], V = (e ? e.resolveSchema(f) : f).filter(
1598
- (I) => "fieldtype" in I && I.fieldtype === "Doctype" && "schema" in I && Array.isArray(I.schema)
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)
1599
1670
  );
1600
- for (const I of V) {
1601
- const K = I, Z = `${y}.${K.fieldname}`, ae = Oe(K.schema, Z, n.value);
1671
+ for (const P of V) {
1672
+ const K = P, Z = `${y}.${K.fieldname}`, ae = Te(K.schema, Z, n.value);
1602
1673
  l[K.fieldname] = ae;
1603
1674
  }
1604
1675
  return l;
1605
- }, P = (p, m) => ({
1606
- provideHSTPath: (l) => `${p}.${l}`,
1676
+ }, C = (h, v) => ({
1677
+ provideHSTPath: (l) => `${h}.${l}`,
1607
1678
  handleHSTChange: (l) => {
1608
- const f = l.path.startsWith(p) ? l.path : `${p}.${l.fieldname}`;
1609
- _({
1679
+ const f = l.path.startsWith(h) ? l.path : `${h}.${l.fieldname}`;
1680
+ B({
1610
1681
  ...l,
1611
1682
  path: f
1612
1683
  });
1613
1684
  }
1614
- }), D = {
1685
+ }), k = {
1615
1686
  operations: d,
1616
- currentIndex: g,
1687
+ currentIndex: p,
1617
1688
  undoRedoState: F,
1618
1689
  canUndo: S,
1619
1690
  canRedo: $,
1620
- undoCount: k,
1621
- redoCount: x,
1691
+ undoCount: D,
1692
+ redoCount: N,
1622
1693
  undo: R,
1623
1694
  redo: O,
1624
- startBatch: w,
1625
- commitBatch: h,
1626
- cancelBatch: E,
1627
- clear: b,
1695
+ startBatch: b,
1696
+ commitBatch: g,
1697
+ cancelBatch: I,
1698
+ clear: w,
1628
1699
  getOperationsFor: A,
1629
- getSnapshot: C,
1700
+ getSnapshot: E,
1630
1701
  markIrreversible: M,
1631
1702
  logAction: W,
1632
- configure: N
1703
+ configure: x
1633
1704
  };
1634
1705
  return o.doctype ? {
1635
1706
  stonecrop: r,
1636
- operationLog: D,
1637
- provideHSTPath: q,
1638
- handleHSTChange: _,
1707
+ operationLog: k,
1708
+ provideHSTPath: J,
1709
+ handleHSTChange: B,
1639
1710
  hstStore: n,
1640
1711
  formData: i,
1641
1712
  resolvedSchema: c,
1642
1713
  loadNestedData: G,
1643
- saveRecursive: v,
1644
- createNestedContext: P
1714
+ saveRecursive: m,
1715
+ createNestedContext: C
1645
1716
  } : !o.doctype && e?.router ? {
1646
1717
  stonecrop: r,
1647
- operationLog: D,
1648
- provideHSTPath: q,
1649
- handleHSTChange: _,
1718
+ operationLog: k,
1719
+ provideHSTPath: J,
1720
+ handleHSTChange: B,
1650
1721
  hstStore: n,
1651
1722
  formData: i,
1652
1723
  resolvedSchema: c,
1653
1724
  loadNestedData: G,
1654
- saveRecursive: v,
1655
- createNestedContext: P
1725
+ saveRecursive: m,
1726
+ createNestedContext: C
1656
1727
  } : {
1657
1728
  stonecrop: r,
1658
- operationLog: D
1729
+ operationLog: k
1659
1730
  };
1660
1731
  }
1661
1732
  function z(o) {
@@ -1684,7 +1755,7 @@ function z(o) {
1684
1755
  }
1685
1756
  }), e;
1686
1757
  }
1687
- function ve(o, e, t, r) {
1758
+ function me(o, e, t, r) {
1688
1759
  U(
1689
1760
  t,
1690
1761
  (n) => {
@@ -1709,52 +1780,52 @@ function tt(o, e, t) {
1709
1780
  const n = e[e.length - 1];
1710
1781
  r[n] = t;
1711
1782
  }
1712
- function Oe(o, e, t) {
1783
+ function Te(o, e, t) {
1713
1784
  const n = { ...t.get(e) || {} }, i = o.filter(
1714
1785
  (s) => "fieldtype" in s && s.fieldtype === "Doctype" && "schema" in s && Array.isArray(s.schema)
1715
1786
  );
1716
1787
  for (const s of i) {
1717
- const a = s, c = `${e}.${a.fieldname}`, d = Oe(a.schema, c, t);
1788
+ const a = s, c = `${e}.${a.fieldname}`, d = Te(a.schema, c, t);
1718
1789
  n[a.fieldname] = d;
1719
1790
  }
1720
1791
  return n;
1721
1792
  }
1722
- function Te(o) {
1723
- const t = fe("$operationLogStore", void 0) || re();
1793
+ function $e(o) {
1794
+ const t = (Se() ? fe("$operationLogStore", void 0) : void 0) || re();
1724
1795
  o && t.configure(o);
1725
1796
  const { operations: r, currentIndex: n, undoRedoState: i, canUndo: s, canRedo: a, undoCount: c, redoCount: d } = be(t);
1726
- function g(b) {
1727
- return t.undo(b);
1797
+ function p(w) {
1798
+ return t.undo(w);
1728
1799
  }
1729
- function S(b) {
1730
- return t.redo(b);
1800
+ function S(w) {
1801
+ return t.redo(w);
1731
1802
  }
1732
1803
  function $() {
1733
1804
  t.startBatch();
1734
1805
  }
1735
- function k(b) {
1736
- return t.commitBatch(b);
1806
+ function D(w) {
1807
+ return t.commitBatch(w);
1737
1808
  }
1738
- function x() {
1809
+ function N() {
1739
1810
  t.cancelBatch();
1740
1811
  }
1741
1812
  function F() {
1742
1813
  t.clear();
1743
1814
  }
1744
- function R(b, A) {
1745
- return t.getOperationsFor(b, A);
1815
+ function R(w, A) {
1816
+ return t.getOperationsFor(w, A);
1746
1817
  }
1747
1818
  function O() {
1748
1819
  return t.getSnapshot();
1749
1820
  }
1750
- function w(b, A) {
1751
- t.markIrreversible(b, A);
1821
+ function b(w, A) {
1822
+ t.markIrreversible(w, A);
1752
1823
  }
1753
- function h(b, A, C, M = "success", W) {
1754
- return t.logAction(b, A, C, M, W);
1824
+ function g(w, A, E, M = "success", W) {
1825
+ return t.logAction(w, A, E, M, W);
1755
1826
  }
1756
- function E(b) {
1757
- t.configure(b);
1827
+ function I(w) {
1828
+ t.configure(w);
1758
1829
  }
1759
1830
  return {
1760
1831
  // State
@@ -1766,22 +1837,22 @@ function Te(o) {
1766
1837
  undoCount: c,
1767
1838
  redoCount: d,
1768
1839
  // Methods
1769
- undo: g,
1840
+ undo: p,
1770
1841
  redo: S,
1771
1842
  startBatch: $,
1772
- commitBatch: k,
1773
- cancelBatch: x,
1843
+ commitBatch: D,
1844
+ cancelBatch: N,
1774
1845
  clear: F,
1775
1846
  getOperationsFor: R,
1776
1847
  getSnapshot: O,
1777
- markIrreversible: w,
1778
- logAction: h,
1779
- configure: E
1848
+ markIrreversible: b,
1849
+ logAction: g,
1850
+ configure: I
1780
1851
  };
1781
1852
  }
1782
- function ht(o, e = !0) {
1853
+ function gt(o, e = !0) {
1783
1854
  if (!e) return;
1784
- const { undo: t, redo: r, canUndo: n, canRedo: i } = Te(), s = Ye();
1855
+ const { undo: t, redo: r, canUndo: n, canRedo: i } = $e(), s = Ye();
1785
1856
  X(s["Ctrl+Z"], () => {
1786
1857
  n.value && t(o);
1787
1858
  }), X(s["Meta+Z"], () => {
@@ -1794,8 +1865,8 @@ function ht(o, e = !0) {
1794
1865
  i.value && r(o);
1795
1866
  });
1796
1867
  }
1797
- async function gt(o, e) {
1798
- const { startBatch: t, commitBatch: r, cancelBatch: n } = Te();
1868
+ async function pt(o, e) {
1869
+ const { startBatch: t, commitBatch: r, cancelBatch: n } = $e();
1799
1870
  t();
1800
1871
  try {
1801
1872
  return await o(), r(e);
@@ -1803,13 +1874,21 @@ async function gt(o, e) {
1803
1874
  throw n(), i;
1804
1875
  }
1805
1876
  }
1806
- class vt {
1877
+ class mt {
1807
1878
  /**
1808
1879
  * The doctype name
1809
1880
  * @public
1810
1881
  * @readonly
1811
1882
  */
1812
1883
  doctype;
1884
+ /**
1885
+ * Alias for doctype (for DoctypeLike interface compatibility)
1886
+ * @public
1887
+ * @readonly
1888
+ */
1889
+ get name() {
1890
+ return this.doctype;
1891
+ }
1813
1892
  /**
1814
1893
  * The doctype schema
1815
1894
  * @public
@@ -1845,6 +1924,30 @@ class vt {
1845
1924
  constructor(e, t, r, n, i) {
1846
1925
  this.doctype = e, this.schema = t, this.workflow = r, this.actions = n, this.component = i;
1847
1926
  }
1927
+ /**
1928
+ * Returns the transitions available from a given workflow state, derived from the
1929
+ * doctype's XState workflow configuration.
1930
+ *
1931
+ * @param currentState - The state name to read transitions from
1932
+ * @returns Array of transition descriptors with `name` and `targetState`
1933
+ *
1934
+ * @example
1935
+ * ```ts
1936
+ * const transitions = doctype.getAvailableTransitions('draft')
1937
+ * // [{ name: 'SUBMIT', targetState: 'submitted' }]
1938
+ * ```
1939
+ *
1940
+ * @public
1941
+ */
1942
+ getAvailableTransitions(e) {
1943
+ const t = this.workflow?.states;
1944
+ if (!t) return [];
1945
+ const r = t[e];
1946
+ return r?.on ? Object.entries(r.on).map(([n, i]) => ({
1947
+ name: n,
1948
+ targetState: typeof i == "string" ? i : "unknown"
1949
+ })) : [];
1950
+ }
1848
1951
  /**
1849
1952
  * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
1850
1953
  * - It replaces camelCase and PascalCase with kebab-case strings
@@ -1909,7 +2012,7 @@ class te {
1909
2012
  */
1910
2013
  addDoctype(e) {
1911
2014
  e.slug in this.registry || (this.registry[e.slug] = e);
1912
- const t = J();
2015
+ const t = q();
1913
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({
1914
2017
  path: `/${e.slug}`,
1915
2018
  name: e.slug,
@@ -2041,6 +2144,15 @@ class te {
2041
2144
  }
2042
2145
  }), t;
2043
2146
  }
2147
+ /**
2148
+ * Get a registered doctype by slug
2149
+ * @param slug - The doctype slug to look up
2150
+ * @returns The DoctypeMeta instance if found, or undefined
2151
+ * @public
2152
+ */
2153
+ getDoctype(e) {
2154
+ return this.registry[e];
2155
+ }
2044
2156
  // TODO: should we allow clearing the registry at all?
2045
2157
  // clear() {
2046
2158
  // this.registry = {}
@@ -2061,13 +2173,13 @@ async function rt(o, e, t) {
2061
2173
  } catch {
2062
2174
  }
2063
2175
  }
2064
- const mt = {
2176
+ const vt = {
2065
2177
  install: (o, e) => {
2066
2178
  const t = o.config.globalProperties.$router, r = e?.router, n = t || r;
2067
2179
  !t && r && o.use(r);
2068
2180
  const i = new te(n, e?.getMeta);
2069
2181
  o.provide("$registry", i), o.config.globalProperties.$registry = i;
2070
- const s = new Ae(i);
2182
+ const s = new Oe(i, void 0, e?.client ? { client: e.client } : void 0);
2071
2183
  o.provide("$stonecrop", s), o.config.globalProperties.$stonecrop = s;
2072
2184
  try {
2073
2185
  const a = o.config.globalProperties.$pinia;
@@ -2111,17 +2223,17 @@ class ot {
2111
2223
  validate(e, t, r, n) {
2112
2224
  const i = [], s = t ? Array.isArray(t) ? t : t.toArray() : [];
2113
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) {
2114
- const g = n instanceof Map ? n : n.toObject();
2115
- i.push(...this.validateActionRegistration(e, g));
2226
+ const p = n instanceof Map ? n : n.toObject();
2227
+ i.push(...this.validateActionRegistration(e, p));
2116
2228
  }
2117
2229
  const a = i.filter(
2118
- (g) => g.severity === "error"
2230
+ (p) => p.severity === "error"
2119
2231
  /* ERROR */
2120
2232
  ).length, c = i.filter(
2121
- (g) => g.severity === "warning"
2233
+ (p) => p.severity === "warning"
2122
2234
  /* WARNING */
2123
2235
  ).length, d = i.filter(
2124
- (g) => g.severity === "info"
2236
+ (p) => p.severity === "info"
2125
2237
  /* INFO */
2126
2238
  ).length;
2127
2239
  return {
@@ -2238,11 +2350,11 @@ class ot {
2238
2350
  for (const [s, a] of Object.entries(t.states)) {
2239
2351
  const c = a;
2240
2352
  if (c.on) {
2241
- for (const [d, g] of Object.entries(c.on))
2242
- if (typeof g == "string")
2243
- i.add(g);
2244
- else if (g && typeof g == "object") {
2245
- const S = "target" in g ? g.target : void 0;
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;
2246
2358
  typeof S == "string" ? i.add(S) : Array.isArray(S) && S.forEach(($) => {
2247
2359
  typeof $ == "string" && i.add($);
2248
2360
  });
@@ -2264,7 +2376,7 @@ class ot {
2264
2376
  * @internal
2265
2377
  */
2266
2378
  validateActionRegistration(e, t) {
2267
- const r = [], n = J();
2379
+ const r = [], n = q();
2268
2380
  for (const [i, s] of Object.entries(t)) {
2269
2381
  if (!Array.isArray(s)) {
2270
2382
  r.push({
@@ -2300,26 +2412,26 @@ function yt(o, e, t, r, n) {
2300
2412
  return it(t).validate(o, e, r, n);
2301
2413
  }
2302
2414
  export {
2303
- vt as DoctypeMeta,
2415
+ mt as DoctypeMeta,
2304
2416
  Y as HST,
2305
2417
  te as Registry,
2306
2418
  ot as SchemaValidator,
2307
- Ae as Stonecrop,
2419
+ Oe as Stonecrop,
2308
2420
  nt as ValidationSeverity,
2309
2421
  et as createHST,
2310
2422
  it as createValidator,
2311
- mt as default,
2312
- J as getGlobalTriggerEngine,
2423
+ vt as default,
2424
+ q as getGlobalTriggerEngine,
2313
2425
  dt as markOperationIrreversible,
2314
2426
  ct as registerGlobalAction,
2315
2427
  lt as registerTransitionAction,
2316
2428
  ut as setFieldRollback,
2317
2429
  ft as triggerTransition,
2318
- Te as useOperationLog,
2430
+ $e as useOperationLog,
2319
2431
  re as useOperationLogStore,
2320
- pt as useStonecrop,
2321
- ht as useUndoRedoShortcuts,
2432
+ ht as useStonecrop,
2433
+ gt as useUndoRedoShortcuts,
2322
2434
  yt as validateSchema,
2323
- gt as withBatch
2435
+ pt as withBatch
2324
2436
  };
2325
2437
  //# sourceMappingURL=stonecrop.js.map