@stonecrop/stonecrop 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/stonecrop.js CHANGED
@@ -1,15 +1,15 @@
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 me, nextTick as de, readonly as ye, getCurrentInstance as Se, toRef as Ie, customRef as Ee, ref as L, reactive as ue, computed as B, toValue as H, shallowRef as we, unref as Ce, inject as fe, provide as pe } 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
8
  if (o.length !== 1) return Ie(...o);
9
9
  const e = o[0];
10
10
  return typeof e == "function" ? ye(Ee(() => ({
11
11
  get: e,
12
- set: we
12
+ set: Re
13
13
  }))) : L(e);
14
14
  }
15
15
  function xe(o, e) {
@@ -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 Ne(o = Ae, e = {}) {
29
29
  const { initialState: t = "active" } = e, r = Fe(t === "active");
30
30
  function n() {
31
31
  r.value = !1;
@@ -47,10 +47,10 @@ function ce(o) {
47
47
  return Array.isArray(o) ? o : [o];
48
48
  }
49
49
  function Be(o) {
50
- return Pe();
50
+ return Se();
51
51
  }
52
52
  function _e(o, e, t = {}) {
53
- const { eventFilter: r = Re, ...n } = t;
53
+ const { eventFilter: r = Ae, ...n } = t;
54
54
  return U(o, xe(r, e), n);
55
55
  }
56
56
  function Ve(o, e, t = {}) {
@@ -82,7 +82,7 @@ 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);
@@ -103,9 +103,9 @@ function Q(...o) {
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, h = r.flatMap((S) => n.flatMap(($) => i.map((D) => e(S, $, D, d))));
107
107
  c(() => {
108
- g.forEach((S) => S());
108
+ h.forEach((S) => S());
109
109
  });
110
110
  }, { flush: "post" });
111
111
  }
@@ -152,19 +152,19 @@ 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) => {
158
+ const { flush: i = "pre", deep: s = !0, listenToStorageChanges: a = !0, writeDefaults: c = !0, mergeDefaults: d = !1, shallow: h, window: S = j, eventFilter: $, onError: D = (v) => {
159
159
  console.error(v);
160
- }, initOnMounted: x } = r, F = (g ? Se : L)(e), R = B(() => H(o));
160
+ }, initOnMounted: x } = r, F = (h ? we : L)(e), R = B(() => H(o));
161
161
  if (!t) try {
162
162
  t = qe("getDefaultStorage", () => j?.localStorage)();
163
163
  } catch (v) {
164
- k(v);
164
+ D(v);
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: E, resume: w } = Ve(F, (v) => N(v), {
168
168
  flush: i,
169
169
  deep: s,
170
170
  eventFilter: $
@@ -176,18 +176,18 @@ function Ge(o, e, t, r = {}) {
176
176
  }, M = (v) => {
177
177
  x && !A || G(v);
178
178
  };
179
- S && a && (t instanceof Storage ? Q(S, "storage", C, { passive: !0 }) : Q(S, he, M)), x ? We(() => {
179
+ S && a && (t instanceof Storage ? Q(S, "storage", C, { passive: !0 }) : Q(S, ge, M)), x ? We(() => {
180
180
  A = !0, _();
181
181
  }) : _();
182
182
  function W(v, P) {
183
183
  if (S) {
184
- const D = {
184
+ const k = {
185
185
  key: R.value,
186
186
  oldValue: v,
187
187
  newValue: P,
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
193
  function N(v) {
@@ -196,24 +196,24 @@ function Ge(o, e, t, r = {}) {
196
196
  if (v == null)
197
197
  W(P, 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(v);
200
+ P !== k && (t.setItem(R.value, k), W(P, k));
201
201
  }
202
202
  } catch (P) {
203
- k(P);
203
+ D(P);
204
204
  }
205
205
  }
206
206
  function q(v) {
207
207
  const P = v ? v.newValue : t.getItem(R.value);
208
208
  if (P == null)
209
- return c && O != null && t.setItem(R.value, h.write(O)), O;
209
+ return c && O != null && t.setItem(R.value, g.write(O)), O;
210
210
  if (!v && d) {
211
- const D = h.read(P);
212
- return typeof d == "function" ? d(D, O) : w === "object" && !Array.isArray(D) ? {
211
+ const k = g.read(P);
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 P != "string" ? P : g.read(P);
217
217
  }
218
218
  function _(v) {
219
219
  if (!(v && v.storageArea !== t)) {
@@ -224,12 +224,12 @@ function Ge(o, e, t, r = {}) {
224
224
  if (!(v && v.key !== R.value)) {
225
225
  E();
226
226
  try {
227
- const P = h.write(F.value);
227
+ const P = g.write(F.value);
228
228
  (v === void 0 || v?.newValue !== P) && (F.value = q(v));
229
229
  } catch (P) {
230
- k(P);
230
+ D(P);
231
231
  } finally {
232
- v ? de(b) : b();
232
+ v ? de(w) : w();
233
233
  }
234
234
  }
235
235
  }
@@ -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(), h = /* @__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)) {
274
+ function x(b, g, E) {
275
+ if (!(!b || typeof g.getModifierState != "function")) {
276
+ for (const [w, A] of h) if (g.getModifierState(w)) {
277
277
  E.forEach((C) => A.add(C));
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 E = `${g[0].toUpperCase()}${g.slice(1)}`, w = h.get(E);
285
+ if (!["shift", "alt"].includes(g) || !w) return;
286
+ const A = Array.from(w), C = A.indexOf(g);
287
287
  A.forEach((M, W) => {
288
288
  W >= C && (s.delete(M), $(M, !1));
289
- }), b.clear();
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 E, w;
293
+ const A = (E = b.key) === null || E === void 0 ? void 0 : E.toLowerCase(), C = [(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));
295
+ A && (g ? s.add(A) : s.delete(A));
296
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) => {
297
+ S.add(M), $(M, g);
298
+ x(g, b, [...s, ...C]), 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, E) {
305
+ if (typeof g != "string") return Reflect.get(b, g, E);
306
+ if (g = g.toLowerCase(), g in r && (g = r[g]), !(g in c)) if (/[+_-]/.test(g)) {
307
+ const A = g.split(/[+_-]/g).map((C) => C.trim());
308
+ c[g] = B(() => A.map((C) => H(O[C])).every(Boolean));
309
+ } else c[g] = we(!1);
310
+ const w = Reflect.get(b, g, E);
311
+ return e ? H(w) : w;
312
312
  } });
313
313
  return O;
314
314
  }
@@ -343,7 +343,7 @@ 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,
@@ -355,17 +355,17 @@ const re = De("hst-operation-log", () => {
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
+ }), h = B(() => e.value.length - 1 - t.value), S = B(() => ({
359
359
  canUndo: a.value,
360
360
  canRedo: c.value,
361
361
  undoCount: d.value,
362
- redoCount: g.value,
362
+ redoCount: h.value,
363
363
  currentIndex: t.value
364
364
  }));
365
365
  function $(u) {
366
366
  o.value = { ...o.value, ...u }, o.value.enablePersistence && (p(), y()), o.value.enableCrossTabSync && q();
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(),
@@ -423,16 +423,16 @@ const re = De("hst-operation-log", () => {
423
423
  if (l.type === "batch" && l.childOperationIds)
424
424
  for (let f = l.childOperationIds.length - 1; f >= 0; f--) {
425
425
  const T = l.childOperationIds[f], V = e.value.find((I) => I.id === T);
426
- V && h(V, u);
426
+ V && g(V, u);
427
427
  }
428
428
  else
429
- h(l, u);
429
+ g(l, u);
430
430
  return t.value--, o.value.enableCrossTabSync && v(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 {
@@ -448,13 +448,13 @@ const re = De("hst-operation-log", () => {
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
454
  function E(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],
@@ -492,7 +492,7 @@ const re = De("hst-operation-log", () => {
492
492
  actionResult: T,
493
493
  actionError: V
494
494
  };
495
- return k(I);
495
+ return D(I);
496
496
  }
497
497
  let N = null;
498
498
  function q() {
@@ -543,7 +543,7 @@ const re = De("hst-operation-log", () => {
543
543
  };
544
544
  N.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 {
@@ -558,7 +558,7 @@ const re = De("hst-operation-log", () => {
558
558
  function p() {
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)
@@ -570,7 +570,7 @@ const re = De("hst-operation-log", () => {
570
570
  function m() {
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()
@@ -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: h,
605
605
  // Methods
606
606
  configure: $,
607
- addOperation: k,
607
+ addOperation: D,
608
608
  startBatch: x,
609
609
  commitBatch: F,
610
610
  cancelBatch: R,
611
611
  undo: O,
612
- redo: w,
612
+ redo: b,
613
613
  clear: A,
614
614
  getOperationsFor: C,
615
- getSnapshot: b,
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, h;
734
734
  const S = this.getFieldRollback(r, n), $ = t.enableRollback ?? S ?? this.options.enableRollback;
735
- $ && e.store && (g = this.captureSnapshot(e));
735
+ $ && e.store && (h = 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,22 +741,22 @@ 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 && h && e.store)
754
754
  try {
755
- this.restoreSnapshot(e, g), d = !0;
755
+ this.restoreSnapshot(e, h), 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);
759
+ const D = performance.now() - s, x = a.filter((R) => !R.success);
760
760
  if (x.length > 0 && this.options.errorHandler)
761
761
  for (const R of x)
762
762
  try {
@@ -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 && $ ? h : void 0
775
775
  // Only include snapshot in debug mode if rollback is enabled
776
776
  };
777
777
  }
@@ -989,7 +989,7 @@ function dt(o, e) {
989
989
  } catch {
990
990
  }
991
991
  }
992
- function ge() {
992
+ function he() {
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 = he();
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, h = 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: h,
1080
1080
  beforeValue: i,
1081
1081
  afterValue: t,
1082
1082
  doctype: c,
@@ -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 = he();
1153
1153
  return c && typeof c.addOperation == "function" && c.addOperation(
1154
1154
  {
1155
1155
  type: "transition",
@@ -1276,7 +1276,7 @@ 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;
@@ -1390,12 +1390,12 @@ class Ae {
1390
1390
  * @param args - Action arguments (typically record IDs)
1391
1391
  */
1392
1392
  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();
1393
+ const i = this.registry.registry[e.slug]?.actions?.get(t), s = Array.isArray(r) ? r.filter((h) => typeof h == "string") : void 0, a = this.getOperationLogStore();
1394
1394
  let c = "success", d;
1395
1395
  try {
1396
- i && i.length > 0 && i.forEach((g) => {
1396
+ i && i.length > 0 && i.forEach((h) => {
1397
1397
  try {
1398
- new Function("args", g)(r);
1398
+ new Function("args", h)(r);
1399
1399
  } catch (S) {
1400
1400
  throw c = "failure", d = S instanceof Error ? S.message : "Unknown error", S;
1401
1401
  }
@@ -1447,6 +1447,25 @@ class Ae {
1447
1447
  getStore() {
1448
1448
  return this.hstStore;
1449
1449
  }
1450
+ /**
1451
+ * Determine the current workflow state for a record.
1452
+ *
1453
+ * Reads the record's `status` field from the HST store. If the field is absent or
1454
+ * empty the doctype's declared `workflow.initial` state is used as the fallback,
1455
+ * giving callers a reliable state name without having to duplicate that logic.
1456
+ *
1457
+ * @param doctype - The doctype slug or DoctypeMeta instance
1458
+ * @param recordId - The record identifier
1459
+ * @returns The current state name, or an empty string if the doctype has no workflow
1460
+ *
1461
+ * @public
1462
+ */
1463
+ getRecordState(e, t) {
1464
+ const r = typeof e == "string" ? e : e.slug, n = this.registry.getDoctype(r);
1465
+ if (!n?.workflow) return "";
1466
+ const s = this.getRecordById(r, t)?.get("status"), a = typeof n.workflow.initial == "string" ? n.workflow.initial : Object.keys(n.workflow.states ?? {})[0] ?? "";
1467
+ return s || a;
1468
+ }
1450
1469
  }
1451
1470
  function pt(o) {
1452
1471
  o || (o = {});
@@ -1455,7 +1474,7 @@ function pt(o) {
1455
1474
  const p = o.doctype.schema ? Array.isArray(o.doctype.schema) ? o.doctype.schema : Array.from(o.doctype.schema) : [];
1456
1475
  c.value = e.resolveSchema(p);
1457
1476
  }
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(
1477
+ const d = L([]), h = L(-1), S = B(() => r.value?.getOperationLogStore().canUndo ?? !1), $ = B(() => r.value?.getOperationLogStore().canRedo ?? !1), D = B(() => r.value?.getOperationLogStore().undoCount ?? 0), x = B(() => r.value?.getOperationLogStore().redoCount ?? 0), F = B(
1459
1478
  () => r.value?.getOperationLogStore().undoRedoState ?? {
1460
1479
  canUndo: !1,
1461
1480
  canRedo: !1,
@@ -1463,11 +1482,11 @@ function pt(o) {
1463
1482
  redoCount: 0,
1464
1483
  currentIndex: -1
1465
1484
  }
1466
- ), R = (p) => r.value?.getOperationLogStore().undo(p) ?? !1, O = (p) => r.value?.getOperationLogStore().redo(p) ?? !1, w = () => {
1485
+ ), R = (p) => r.value?.getOperationLogStore().undo(p) ?? !1, O = (p) => r.value?.getOperationLogStore().redo(p) ?? !1, b = () => {
1467
1486
  r.value?.getOperationLogStore().startBatch();
1468
- }, h = (p) => r.value?.getOperationLogStore().commitBatch(p) ?? null, E = () => {
1487
+ }, g = (p) => r.value?.getOperationLogStore().commitBatch(p) ?? null, E = () => {
1469
1488
  r.value?.getOperationLogStore().cancelBatch();
1470
- }, b = () => {
1489
+ }, w = () => {
1471
1490
  r.value?.getOperationLogStore().clear();
1472
1491
  }, A = (p, m) => r.value?.getOperationLogStore().getOperationsFor(p, m) ?? [], C = () => r.value?.getOperationLogStore().getSnapshot() ?? {
1473
1492
  operations: [],
@@ -1482,10 +1501,10 @@ function pt(o) {
1482
1501
  };
1483
1502
  me(async () => {
1484
1503
  if (e) {
1485
- r.value = t || new Ae(e);
1504
+ r.value = t || new Oe(e);
1486
1505
  try {
1487
1506
  const p = r.value.getOperationLogStore(), m = be(p);
1488
- d.value = m.operations.value, g.value = m.currentIndex.value, U(
1507
+ d.value = m.operations.value, h.value = m.currentIndex.value, U(
1489
1508
  () => m.operations.value,
1490
1509
  (y) => {
1491
1510
  d.value = y;
@@ -1493,7 +1512,7 @@ function pt(o) {
1493
1512
  ), U(
1494
1513
  () => m.currentIndex.value,
1495
1514
  (y) => {
1496
- g.value = y;
1515
+ h.value = y;
1497
1516
  }
1498
1517
  );
1499
1518
  } catch {
@@ -1568,8 +1587,8 @@ function pt(o) {
1568
1587
  let K = V;
1569
1588
  for (let Z = 0; Z < I.length - 1; Z++)
1570
1589
  if (K += `.${I[Z]}`, !n.value.has(K)) {
1571
- const ae = I[Z + 1], $e = !isNaN(Number(ae));
1572
- n.value.set(K, $e ? [] : {});
1590
+ const ae = I[Z + 1], Pe = !isNaN(Number(ae));
1591
+ n.value.set(K, Pe ? [] : {});
1573
1592
  }
1574
1593
  }
1575
1594
  }
@@ -1598,7 +1617,7 @@ function pt(o) {
1598
1617
  (I) => "fieldtype" in I && I.fieldtype === "Doctype" && "schema" in I && Array.isArray(I.schema)
1599
1618
  );
1600
1619
  for (const I of V) {
1601
- const K = I, Z = `${y}.${K.fieldname}`, ae = Oe(K.schema, Z, n.value);
1620
+ const K = I, Z = `${y}.${K.fieldname}`, ae = Te(K.schema, Z, n.value);
1602
1621
  l[K.fieldname] = ae;
1603
1622
  }
1604
1623
  return l;
@@ -1611,20 +1630,20 @@ function pt(o) {
1611
1630
  path: f
1612
1631
  });
1613
1632
  }
1614
- }), D = {
1633
+ }), k = {
1615
1634
  operations: d,
1616
- currentIndex: g,
1635
+ currentIndex: h,
1617
1636
  undoRedoState: F,
1618
1637
  canUndo: S,
1619
1638
  canRedo: $,
1620
- undoCount: k,
1639
+ undoCount: D,
1621
1640
  redoCount: x,
1622
1641
  undo: R,
1623
1642
  redo: O,
1624
- startBatch: w,
1625
- commitBatch: h,
1643
+ startBatch: b,
1644
+ commitBatch: g,
1626
1645
  cancelBatch: E,
1627
- clear: b,
1646
+ clear: w,
1628
1647
  getOperationsFor: A,
1629
1648
  getSnapshot: C,
1630
1649
  markIrreversible: M,
@@ -1633,7 +1652,7 @@ function pt(o) {
1633
1652
  };
1634
1653
  return o.doctype ? {
1635
1654
  stonecrop: r,
1636
- operationLog: D,
1655
+ operationLog: k,
1637
1656
  provideHSTPath: q,
1638
1657
  handleHSTChange: _,
1639
1658
  hstStore: n,
@@ -1644,7 +1663,7 @@ function pt(o) {
1644
1663
  createNestedContext: P
1645
1664
  } : !o.doctype && e?.router ? {
1646
1665
  stonecrop: r,
1647
- operationLog: D,
1666
+ operationLog: k,
1648
1667
  provideHSTPath: q,
1649
1668
  handleHSTChange: _,
1650
1669
  hstStore: n,
@@ -1655,7 +1674,7 @@ function pt(o) {
1655
1674
  createNestedContext: P
1656
1675
  } : {
1657
1676
  stonecrop: r,
1658
- operationLog: D
1677
+ operationLog: k
1659
1678
  };
1660
1679
  }
1661
1680
  function z(o) {
@@ -1709,31 +1728,31 @@ function tt(o, e, t) {
1709
1728
  const n = e[e.length - 1];
1710
1729
  r[n] = t;
1711
1730
  }
1712
- function Oe(o, e, t) {
1731
+ function Te(o, e, t) {
1713
1732
  const n = { ...t.get(e) || {} }, i = o.filter(
1714
1733
  (s) => "fieldtype" in s && s.fieldtype === "Doctype" && "schema" in s && Array.isArray(s.schema)
1715
1734
  );
1716
1735
  for (const s of i) {
1717
- const a = s, c = `${e}.${a.fieldname}`, d = Oe(a.schema, c, t);
1736
+ const a = s, c = `${e}.${a.fieldname}`, d = Te(a.schema, c, t);
1718
1737
  n[a.fieldname] = d;
1719
1738
  }
1720
1739
  return n;
1721
1740
  }
1722
- function Te(o) {
1723
- const t = fe("$operationLogStore", void 0) || re();
1741
+ function $e(o) {
1742
+ const t = (Se() ? fe("$operationLogStore", void 0) : void 0) || re();
1724
1743
  o && t.configure(o);
1725
1744
  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);
1745
+ function h(w) {
1746
+ return t.undo(w);
1728
1747
  }
1729
- function S(b) {
1730
- return t.redo(b);
1748
+ function S(w) {
1749
+ return t.redo(w);
1731
1750
  }
1732
1751
  function $() {
1733
1752
  t.startBatch();
1734
1753
  }
1735
- function k(b) {
1736
- return t.commitBatch(b);
1754
+ function D(w) {
1755
+ return t.commitBatch(w);
1737
1756
  }
1738
1757
  function x() {
1739
1758
  t.cancelBatch();
@@ -1741,20 +1760,20 @@ function Te(o) {
1741
1760
  function F() {
1742
1761
  t.clear();
1743
1762
  }
1744
- function R(b, A) {
1745
- return t.getOperationsFor(b, A);
1763
+ function R(w, A) {
1764
+ return t.getOperationsFor(w, A);
1746
1765
  }
1747
1766
  function O() {
1748
1767
  return t.getSnapshot();
1749
1768
  }
1750
- function w(b, A) {
1751
- t.markIrreversible(b, A);
1769
+ function b(w, A) {
1770
+ t.markIrreversible(w, A);
1752
1771
  }
1753
- function h(b, A, C, M = "success", W) {
1754
- return t.logAction(b, A, C, M, W);
1772
+ function g(w, A, C, M = "success", W) {
1773
+ return t.logAction(w, A, C, M, W);
1755
1774
  }
1756
- function E(b) {
1757
- t.configure(b);
1775
+ function E(w) {
1776
+ t.configure(w);
1758
1777
  }
1759
1778
  return {
1760
1779
  // State
@@ -1766,22 +1785,22 @@ function Te(o) {
1766
1785
  undoCount: c,
1767
1786
  redoCount: d,
1768
1787
  // Methods
1769
- undo: g,
1788
+ undo: h,
1770
1789
  redo: S,
1771
1790
  startBatch: $,
1772
- commitBatch: k,
1791
+ commitBatch: D,
1773
1792
  cancelBatch: x,
1774
1793
  clear: F,
1775
1794
  getOperationsFor: R,
1776
1795
  getSnapshot: O,
1777
- markIrreversible: w,
1778
- logAction: h,
1796
+ markIrreversible: b,
1797
+ logAction: g,
1779
1798
  configure: E
1780
1799
  };
1781
1800
  }
1782
- function ht(o, e = !0) {
1801
+ function gt(o, e = !0) {
1783
1802
  if (!e) return;
1784
- const { undo: t, redo: r, canUndo: n, canRedo: i } = Te(), s = Ye();
1803
+ const { undo: t, redo: r, canUndo: n, canRedo: i } = $e(), s = Ye();
1785
1804
  X(s["Ctrl+Z"], () => {
1786
1805
  n.value && t(o);
1787
1806
  }), X(s["Meta+Z"], () => {
@@ -1794,8 +1813,8 @@ function ht(o, e = !0) {
1794
1813
  i.value && r(o);
1795
1814
  });
1796
1815
  }
1797
- async function gt(o, e) {
1798
- const { startBatch: t, commitBatch: r, cancelBatch: n } = Te();
1816
+ async function ht(o, e) {
1817
+ const { startBatch: t, commitBatch: r, cancelBatch: n } = $e();
1799
1818
  t();
1800
1819
  try {
1801
1820
  return await o(), r(e);
@@ -1845,6 +1864,30 @@ class vt {
1845
1864
  constructor(e, t, r, n, i) {
1846
1865
  this.doctype = e, this.schema = t, this.workflow = r, this.actions = n, this.component = i;
1847
1866
  }
1867
+ /**
1868
+ * Returns the transitions available from a given workflow state, derived from the
1869
+ * doctype's XState workflow configuration.
1870
+ *
1871
+ * @param currentState - The state name to read transitions from
1872
+ * @returns Array of transition descriptors with `name` and `targetState`
1873
+ *
1874
+ * @example
1875
+ * ```ts
1876
+ * const transitions = doctype.getAvailableTransitions('draft')
1877
+ * // [{ name: 'SUBMIT', targetState: 'submitted' }]
1878
+ * ```
1879
+ *
1880
+ * @public
1881
+ */
1882
+ getAvailableTransitions(e) {
1883
+ const t = this.workflow?.states;
1884
+ if (!t) return [];
1885
+ const r = t[e];
1886
+ return r?.on ? Object.entries(r.on).map(([n, i]) => ({
1887
+ name: n,
1888
+ targetState: typeof i == "string" ? i : "unknown"
1889
+ })) : [];
1890
+ }
1848
1891
  /**
1849
1892
  * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
1850
1893
  * - It replaces camelCase and PascalCase with kebab-case strings
@@ -2041,6 +2084,15 @@ class te {
2041
2084
  }
2042
2085
  }), t;
2043
2086
  }
2087
+ /**
2088
+ * Get a registered doctype by slug
2089
+ * @param slug - The doctype slug to look up
2090
+ * @returns The DoctypeMeta instance if found, or undefined
2091
+ * @public
2092
+ */
2093
+ getDoctype(e) {
2094
+ return this.registry[e];
2095
+ }
2044
2096
  // TODO: should we allow clearing the registry at all?
2045
2097
  // clear() {
2046
2098
  // this.registry = {}
@@ -2067,7 +2119,7 @@ const mt = {
2067
2119
  !t && r && o.use(r);
2068
2120
  const i = new te(n, e?.getMeta);
2069
2121
  o.provide("$registry", i), o.config.globalProperties.$registry = i;
2070
- const s = new Ae(i);
2122
+ const s = new Oe(i);
2071
2123
  o.provide("$stonecrop", s), o.config.globalProperties.$stonecrop = s;
2072
2124
  try {
2073
2125
  const a = o.config.globalProperties.$pinia;
@@ -2111,17 +2163,17 @@ class ot {
2111
2163
  validate(e, t, r, n) {
2112
2164
  const i = [], s = t ? Array.isArray(t) ? t : t.toArray() : [];
2113
2165
  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));
2166
+ const h = n instanceof Map ? n : n.toObject();
2167
+ i.push(...this.validateActionRegistration(e, h));
2116
2168
  }
2117
2169
  const a = i.filter(
2118
- (g) => g.severity === "error"
2170
+ (h) => h.severity === "error"
2119
2171
  /* ERROR */
2120
2172
  ).length, c = i.filter(
2121
- (g) => g.severity === "warning"
2173
+ (h) => h.severity === "warning"
2122
2174
  /* WARNING */
2123
2175
  ).length, d = i.filter(
2124
- (g) => g.severity === "info"
2176
+ (h) => h.severity === "info"
2125
2177
  /* INFO */
2126
2178
  ).length;
2127
2179
  return {
@@ -2238,11 +2290,11 @@ class ot {
2238
2290
  for (const [s, a] of Object.entries(t.states)) {
2239
2291
  const c = a;
2240
2292
  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;
2293
+ for (const [d, h] of Object.entries(c.on))
2294
+ if (typeof h == "string")
2295
+ i.add(h);
2296
+ else if (h && typeof h == "object") {
2297
+ const S = "target" in h ? h.target : void 0;
2246
2298
  typeof S == "string" ? i.add(S) : Array.isArray(S) && S.forEach(($) => {
2247
2299
  typeof $ == "string" && i.add($);
2248
2300
  });
@@ -2304,7 +2356,7 @@ export {
2304
2356
  Y as HST,
2305
2357
  te as Registry,
2306
2358
  ot as SchemaValidator,
2307
- Ae as Stonecrop,
2359
+ Oe as Stonecrop,
2308
2360
  nt as ValidationSeverity,
2309
2361
  et as createHST,
2310
2362
  it as createValidator,
@@ -2315,11 +2367,11 @@ export {
2315
2367
  lt as registerTransitionAction,
2316
2368
  ut as setFieldRollback,
2317
2369
  ft as triggerTransition,
2318
- Te as useOperationLog,
2370
+ $e as useOperationLog,
2319
2371
  re as useOperationLogStore,
2320
2372
  pt as useStonecrop,
2321
- ht as useUndoRedoShortcuts,
2373
+ gt as useUndoRedoShortcuts,
2322
2374
  yt as validateSchema,
2323
- gt as withBatch
2375
+ ht as withBatch
2324
2376
  };
2325
2377
  //# sourceMappingURL=stonecrop.js.map