@stonecrop/stonecrop 0.16.4 → 0.16.5
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/src/doctype.d.ts +13 -0
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/doctype.js +16 -1
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stonecrop.js +7 -6
- package/dist/stonecrop.d.ts +13 -0
- package/dist/stonecrop.js +149 -133
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
- package/src/doctype.ts +17 -1
- package/src/stonecrop.ts +7 -5
package/dist/stonecrop.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ref as O, computed as C, watch as X, reactive as Te, inject as ee, onMounted as Ce, provide as
|
|
1
|
+
import { ref as O, computed as C, watch as X, reactive as Te, inject as ee, onMounted as Ce, provide as fe, getCurrentInstance as De, nextTick as Pe } from "vue";
|
|
2
2
|
import { defineStore as Se, storeToRefs as ke } from "pinia";
|
|
3
3
|
import { useLocalStorage as Le, useMagicKeys as xe, whenever as q } from "@vueuse/core";
|
|
4
|
-
import { normalizeFieldKind as Ne, isActionAllowedInState as ge, resolveLinkRenderMode as he, componentLinkExpansion as Re, componentCategory as
|
|
4
|
+
import { normalizeFieldKind as Ne, getRecordIdentity as _e, isActionAllowedInState as ge, resolveLinkRenderMode as he, componentLinkExpansion as Re, componentCategory as Fe } from "@stonecrop/schema";
|
|
5
5
|
import { List as pe, Map as ve } from "immutable";
|
|
6
|
-
const
|
|
6
|
+
const Me = Object.getPrototypeOf(async () => {
|
|
7
7
|
}).constructor;
|
|
8
|
-
async function
|
|
8
|
+
async function Be(s, e = {}) {
|
|
9
9
|
const t = Object.keys(e);
|
|
10
|
-
return new
|
|
10
|
+
return new Me(...t, s)(...t.map((i) => e[i]));
|
|
11
11
|
}
|
|
12
12
|
function ue() {
|
|
13
13
|
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
@@ -26,7 +26,7 @@ function Y(s) {
|
|
|
26
26
|
timestamp: t.timestamp.toISOString()
|
|
27
27
|
}))), e;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function We(s) {
|
|
30
30
|
const e = {
|
|
31
31
|
type: s.type,
|
|
32
32
|
clientId: s.clientId,
|
|
@@ -64,26 +64,26 @@ const Z = Se("hst-operation-log", () => {
|
|
|
64
64
|
redoCount: u.value,
|
|
65
65
|
currentIndex: t.value
|
|
66
66
|
}));
|
|
67
|
-
function
|
|
67
|
+
function d(g) {
|
|
68
68
|
s.value = { ...s.value, ...g }, s.value.enablePersistence && (oe(), ae()), s.value.enableCrossTabSync && U();
|
|
69
69
|
}
|
|
70
70
|
function w(g, h = "user") {
|
|
71
|
-
const
|
|
71
|
+
const f = {
|
|
72
72
|
...g,
|
|
73
73
|
id: ue(),
|
|
74
74
|
timestamp: /* @__PURE__ */ new Date(),
|
|
75
75
|
source: h,
|
|
76
76
|
userId: s.value.userId
|
|
77
77
|
};
|
|
78
|
-
if (s.value.operationFilter && !s.value.operationFilter(
|
|
79
|
-
return
|
|
78
|
+
if (s.value.operationFilter && !s.value.operationFilter(f))
|
|
79
|
+
return f.id;
|
|
80
80
|
if (i.value && n.value.length > 0)
|
|
81
|
-
return n.value[n.value.length - 1].operations.push(
|
|
82
|
-
if (t.value < e.value.length - 1 && (e.value = e.value.slice(0, t.value + 1)), e.value.push(
|
|
81
|
+
return n.value[n.value.length - 1].operations.push(f), f.id;
|
|
82
|
+
if (t.value < e.value.length - 1 && (e.value = e.value.slice(0, t.value + 1)), e.value.push(f), t.value++, s.value.maxOperations && e.value.length > s.value.maxOperations) {
|
|
83
83
|
const A = e.value.length - s.value.maxOperations;
|
|
84
84
|
e.value = e.value.slice(A), t.value -= A;
|
|
85
85
|
}
|
|
86
|
-
return s.value.enableCrossTabSync && j(
|
|
86
|
+
return s.value.enableCrossTabSync && j(f), f.id;
|
|
87
87
|
}
|
|
88
88
|
function $() {
|
|
89
89
|
i.value = !0, n.value.push({
|
|
@@ -94,10 +94,10 @@ const Z = Se("hst-operation-log", () => {
|
|
|
94
94
|
function m(g) {
|
|
95
95
|
if (!i.value || n.value.length === 0)
|
|
96
96
|
return null;
|
|
97
|
-
const h = n.value.pop(),
|
|
98
|
-
if (
|
|
97
|
+
const h = n.value.pop(), f = h.operations;
|
|
98
|
+
if (f.length === 0)
|
|
99
99
|
return n.value.length === 0 && (i.value = !1), null;
|
|
100
|
-
const A = h.id, P =
|
|
100
|
+
const A = h.id, P = f.every((N) => N.reversible), L = {
|
|
101
101
|
id: A,
|
|
102
102
|
type: "batch",
|
|
103
103
|
path: "",
|
|
@@ -105,17 +105,17 @@ const Z = Se("hst-operation-log", () => {
|
|
|
105
105
|
fieldname: "",
|
|
106
106
|
beforeValue: null,
|
|
107
107
|
afterValue: null,
|
|
108
|
-
doctype:
|
|
108
|
+
doctype: f[0]?.doctype || "",
|
|
109
109
|
timestamp: /* @__PURE__ */ new Date(),
|
|
110
110
|
source: "user",
|
|
111
111
|
reversible: P,
|
|
112
112
|
irreversibleReason: P ? void 0 : "Contains irreversible operations",
|
|
113
|
-
descendantOperationIds:
|
|
113
|
+
descendantOperationIds: f.map((N) => N.id),
|
|
114
114
|
metadata: { description: g }
|
|
115
115
|
};
|
|
116
|
-
return
|
|
116
|
+
return f.forEach((N) => {
|
|
117
117
|
N.ancestorOperationId = A;
|
|
118
|
-
}), n.value.length > 0 ? n.value[n.value.length - 1].operations.push(L) : (e.value.push(...
|
|
118
|
+
}), n.value.length > 0 ? n.value[n.value.length - 1].operations.push(L) : (e.value.push(...f, L), t.value = e.value.length - 1), s.value.enableCrossTabSync && re(f, L), n.value.length === 0 && (i.value = !1), A;
|
|
119
119
|
}
|
|
120
120
|
function S() {
|
|
121
121
|
n.value = [], i.value = !1;
|
|
@@ -127,15 +127,15 @@ const Z = Se("hst-operation-log", () => {
|
|
|
127
127
|
return typeof console < "u" && h.irreversibleReason && console.warn("Cannot undo irreversible operation:", h.irreversibleReason), !1;
|
|
128
128
|
try {
|
|
129
129
|
if (h.type === "batch" && h.descendantOperationIds)
|
|
130
|
-
for (let
|
|
131
|
-
const A = h.descendantOperationIds[
|
|
130
|
+
for (let f = h.descendantOperationIds.length - 1; f >= 0; f--) {
|
|
131
|
+
const A = h.descendantOperationIds[f], P = e.value.find((L) => L.id === A);
|
|
132
132
|
P && me(P, g);
|
|
133
133
|
}
|
|
134
134
|
else
|
|
135
135
|
me(h, g);
|
|
136
136
|
return t.value--, s.value.enableCrossTabSync && ne(h), !0;
|
|
137
|
-
} catch (
|
|
138
|
-
return typeof console < "u" && console.error("Undo failed:",
|
|
137
|
+
} catch (f) {
|
|
138
|
+
return typeof console < "u" && console.error("Undo failed:", f), !1;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
function T(g) {
|
|
@@ -143,52 +143,52 @@ const Z = Se("hst-operation-log", () => {
|
|
|
143
143
|
const h = e.value[t.value + 1];
|
|
144
144
|
try {
|
|
145
145
|
if (h.type === "batch" && h.descendantOperationIds)
|
|
146
|
-
for (const
|
|
147
|
-
const A = e.value.find((P) => P.id ===
|
|
146
|
+
for (const f of h.descendantOperationIds) {
|
|
147
|
+
const A = e.value.find((P) => P.id === f);
|
|
148
148
|
A && ye(A, g);
|
|
149
149
|
}
|
|
150
150
|
else
|
|
151
151
|
ye(h, g);
|
|
152
152
|
return t.value++, s.value.enableCrossTabSync && ie(h), !0;
|
|
153
|
-
} catch (
|
|
154
|
-
return typeof console < "u" && console.error("Redo failed:",
|
|
153
|
+
} catch (f) {
|
|
154
|
+
return typeof console < "u" && console.error("Redo failed:", f), !1;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
function W() {
|
|
158
|
-
const g = e.value.filter((
|
|
158
|
+
const g = e.value.filter((f) => f.reversible).length, h = e.value.map((f) => f.timestamp);
|
|
159
159
|
return {
|
|
160
160
|
operations: [...e.value],
|
|
161
161
|
currentIndex: t.value,
|
|
162
162
|
totalOperations: e.value.length,
|
|
163
163
|
reversibleOperations: g,
|
|
164
164
|
irreversibleOperations: e.value.length - g,
|
|
165
|
-
oldestOperation: h.length > 0 ? new Date(Math.min(...h.map((
|
|
166
|
-
newestOperation: h.length > 0 ? new Date(Math.max(...h.map((
|
|
165
|
+
oldestOperation: h.length > 0 ? new Date(Math.min(...h.map((f) => f.getTime()))) : void 0,
|
|
166
|
+
newestOperation: h.length > 0 ? new Date(Math.max(...h.map((f) => f.getTime()))) : void 0
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
function M() {
|
|
170
170
|
e.value = [], t.value = -1;
|
|
171
171
|
}
|
|
172
172
|
function H(g, h) {
|
|
173
|
-
return e.value.filter((
|
|
173
|
+
return e.value.filter((f) => f.doctype === g && (h === void 0 || f.recordId === h));
|
|
174
174
|
}
|
|
175
175
|
function E(g, h) {
|
|
176
|
-
const
|
|
177
|
-
|
|
176
|
+
const f = e.value.find((A) => A.id === g);
|
|
177
|
+
f && (f.reversible = !1, f.irreversibleReason = h);
|
|
178
178
|
}
|
|
179
|
-
function x(g, h,
|
|
179
|
+
function x(g, h, f, A = "success", P) {
|
|
180
180
|
const L = {
|
|
181
181
|
type: "action",
|
|
182
|
-
path:
|
|
182
|
+
path: f && f.length > 0 ? `${g}.${f[0]}` : g,
|
|
183
183
|
fieldname: "",
|
|
184
184
|
beforeValue: null,
|
|
185
185
|
afterValue: null,
|
|
186
186
|
doctype: g,
|
|
187
|
-
recordId:
|
|
187
|
+
recordId: f && f.length > 0 ? f[0] : void 0,
|
|
188
188
|
reversible: !1,
|
|
189
189
|
// Actions are typically not reversible
|
|
190
190
|
actionName: h,
|
|
191
|
-
actionRecordIds:
|
|
191
|
+
actionRecordIds: f,
|
|
192
192
|
actionResult: A,
|
|
193
193
|
actionError: P
|
|
194
194
|
};
|
|
@@ -199,9 +199,9 @@ const Z = Se("hst-operation-log", () => {
|
|
|
199
199
|
typeof window > "u" || !window.BroadcastChannel || (D = new BroadcastChannel("stonecrop-operation-log"), D.addEventListener("message", (g) => {
|
|
200
200
|
const h = g.data;
|
|
201
201
|
if (!h || typeof h != "object") return;
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
...
|
|
202
|
+
const f = We(h);
|
|
203
|
+
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(
|
|
204
|
+
...f.operations.map((A) => Object.assign({}, A, { source: "sync" }))
|
|
205
205
|
), t.value = e.value.length - 1));
|
|
206
206
|
}));
|
|
207
207
|
}
|
|
@@ -217,13 +217,13 @@ const Z = Se("hst-operation-log", () => {
|
|
|
217
217
|
}
|
|
218
218
|
function re(g, h) {
|
|
219
219
|
if (!D) return;
|
|
220
|
-
const
|
|
220
|
+
const f = {
|
|
221
221
|
type: "operation",
|
|
222
222
|
operations: [...g, h],
|
|
223
223
|
clientId: r.value,
|
|
224
224
|
timestamp: /* @__PURE__ */ new Date()
|
|
225
225
|
};
|
|
226
|
-
D.postMessage(Y(
|
|
226
|
+
D.postMessage(Y(f));
|
|
227
227
|
}
|
|
228
228
|
function ne(g) {
|
|
229
229
|
if (!D) return;
|
|
@@ -305,7 +305,7 @@ const Z = Se("hst-operation-log", () => {
|
|
|
305
305
|
undoCount: c,
|
|
306
306
|
redoCount: u,
|
|
307
307
|
// Methods
|
|
308
|
-
configure:
|
|
308
|
+
configure: d,
|
|
309
309
|
addOperation: w,
|
|
310
310
|
startBatch: $,
|
|
311
311
|
commitBatch: m,
|
|
@@ -439,7 +439,7 @@ class G {
|
|
|
439
439
|
};
|
|
440
440
|
const o = performance.now(), a = [];
|
|
441
441
|
let c = !1, u = !1, l;
|
|
442
|
-
const
|
|
442
|
+
const d = this.getFieldRollback(r, i), w = t.enableRollback ?? d ?? this.options.enableRollback;
|
|
443
443
|
w && e.store && (l = this.captureSnapshot(e));
|
|
444
444
|
for (const b of n)
|
|
445
445
|
try {
|
|
@@ -500,14 +500,14 @@ class G {
|
|
|
500
500
|
if (o.push(u), !u.success)
|
|
501
501
|
break;
|
|
502
502
|
} catch (u) {
|
|
503
|
-
const
|
|
503
|
+
const d = {
|
|
504
504
|
success: !1,
|
|
505
505
|
error: u instanceof Error ? u : new Error(String(u)),
|
|
506
506
|
executionTime: 0,
|
|
507
507
|
action: c,
|
|
508
508
|
transition: i
|
|
509
509
|
};
|
|
510
|
-
o.push(
|
|
510
|
+
o.push(d);
|
|
511
511
|
break;
|
|
512
512
|
}
|
|
513
513
|
const a = o.filter((c) => !c.success);
|
|
@@ -662,16 +662,16 @@ class G {
|
|
|
662
662
|
function _(s) {
|
|
663
663
|
return new G(s);
|
|
664
664
|
}
|
|
665
|
-
function
|
|
665
|
+
function Qe(s, e) {
|
|
666
666
|
_().registerAction(s, e);
|
|
667
667
|
}
|
|
668
|
-
function
|
|
668
|
+
function Ye(s, e) {
|
|
669
669
|
_().registerTransitionAction(s, e);
|
|
670
670
|
}
|
|
671
|
-
function
|
|
671
|
+
function Xe(s, e, t) {
|
|
672
672
|
_().setFieldRollback(s, e, t);
|
|
673
673
|
}
|
|
674
|
-
async function
|
|
674
|
+
async function et(s, e, t) {
|
|
675
675
|
const r = _(), i = {
|
|
676
676
|
path: t?.path || (t?.recordId ? `${s}.${t.recordId}` : s),
|
|
677
677
|
fieldname: "",
|
|
@@ -688,7 +688,7 @@ async function Xe(s, e, t) {
|
|
|
688
688
|
};
|
|
689
689
|
return await r.executeTransitionActions(i);
|
|
690
690
|
}
|
|
691
|
-
function
|
|
691
|
+
function tt(s, e) {
|
|
692
692
|
if (s)
|
|
693
693
|
try {
|
|
694
694
|
Z().markIrreversible(s, e);
|
|
@@ -982,7 +982,7 @@ class te {
|
|
|
982
982
|
return e ? e.replace(/\[(\d+)\]/g, ".$1").split(".").filter((r) => r.length > 0) : [];
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
|
-
function
|
|
985
|
+
function ze(s, e) {
|
|
986
986
|
return new te(s, e, "", null);
|
|
987
987
|
}
|
|
988
988
|
class F {
|
|
@@ -1046,7 +1046,7 @@ class F {
|
|
|
1046
1046
|
const e = {};
|
|
1047
1047
|
Object.keys(this.registry.registry).forEach((t) => {
|
|
1048
1048
|
e[t] = {};
|
|
1049
|
-
}), this.hstStore =
|
|
1049
|
+
}), this.hstStore = ze(Te(e), "StonecropStore");
|
|
1050
1050
|
}
|
|
1051
1051
|
/**
|
|
1052
1052
|
* Setup automatic sync with Registry when doctypes are added
|
|
@@ -1142,7 +1142,7 @@ class F {
|
|
|
1142
1142
|
`BLOCKED: missing data for links: ${c.blockedLinks?.join(", ")}`
|
|
1143
1143
|
), new Error(`Workflow blocked: missing data for links: ${c.blockedLinks?.join(", ")}`);
|
|
1144
1144
|
const u = this.getOperationLogStore();
|
|
1145
|
-
let l = "success",
|
|
1145
|
+
let l = "success", d;
|
|
1146
1146
|
try {
|
|
1147
1147
|
if (n && n.length > 0) {
|
|
1148
1148
|
const w = _();
|
|
@@ -1162,13 +1162,13 @@ class F {
|
|
|
1162
1162
|
};
|
|
1163
1163
|
m(S);
|
|
1164
1164
|
} catch (m) {
|
|
1165
|
-
throw l = "failure",
|
|
1165
|
+
throw l = "failure", d = m instanceof Error ? m.message : "Unknown error", m;
|
|
1166
1166
|
}
|
|
1167
1167
|
});
|
|
1168
1168
|
}
|
|
1169
1169
|
} catch {
|
|
1170
1170
|
} finally {
|
|
1171
|
-
u.logAction(e.doctype, t, o, l,
|
|
1171
|
+
u.logAction(e.doctype, t, o, l, d);
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
1174
1174
|
/**
|
|
@@ -1209,7 +1209,8 @@ class F {
|
|
|
1209
1209
|
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records."
|
|
1210
1210
|
);
|
|
1211
1211
|
(await this._client.getRecords(e)).forEach((r) => {
|
|
1212
|
-
|
|
1212
|
+
const i = e.getRecordId(r);
|
|
1213
|
+
i !== void 0 && this.addRecord(e, i, r);
|
|
1213
1214
|
});
|
|
1214
1215
|
}
|
|
1215
1216
|
/**
|
|
@@ -1383,14 +1384,14 @@ class F {
|
|
|
1383
1384
|
return i;
|
|
1384
1385
|
}
|
|
1385
1386
|
}
|
|
1386
|
-
function
|
|
1387
|
+
function rt() {
|
|
1387
1388
|
return F._root;
|
|
1388
1389
|
}
|
|
1389
1390
|
function be(s, e) {
|
|
1390
1391
|
const t = new Error(s);
|
|
1391
1392
|
return t.code = e, t;
|
|
1392
1393
|
}
|
|
1393
|
-
function
|
|
1394
|
+
function nt(s, e, t) {
|
|
1394
1395
|
const r = ee("$stonecrop") || F._root;
|
|
1395
1396
|
if (!r)
|
|
1396
1397
|
throw new Error("Stonecrop instance not available. Ensure useStonecrop() has been called first.");
|
|
@@ -1407,7 +1408,7 @@ function rt(s, e, t) {
|
|
|
1407
1408
|
} catch (S) {
|
|
1408
1409
|
throw new Error(`Custom handler failed: ${S instanceof Error ? S.message : String(S)}`, { cause: S });
|
|
1409
1410
|
}
|
|
1410
|
-
},
|
|
1411
|
+
}, d = async () => {
|
|
1411
1412
|
const m = u(), S = `${s.slug || s.doctype}.${e}`;
|
|
1412
1413
|
if (m?.method === "custom") {
|
|
1413
1414
|
a.has(S) || a.set(S, {}, "system");
|
|
@@ -1419,7 +1420,7 @@ function rt(s, e, t) {
|
|
|
1419
1420
|
if (!i.value) {
|
|
1420
1421
|
i.value = !0, o.value = null;
|
|
1421
1422
|
try {
|
|
1422
|
-
await
|
|
1423
|
+
await d(), n.value = !0;
|
|
1423
1424
|
} catch (m) {
|
|
1424
1425
|
throw o.value = m instanceof Error ? m : new Error(String(m)), m;
|
|
1425
1426
|
} finally {
|
|
@@ -1441,10 +1442,10 @@ function rt(s, e, t) {
|
|
|
1441
1442
|
reload: w
|
|
1442
1443
|
};
|
|
1443
1444
|
}
|
|
1444
|
-
function
|
|
1445
|
+
function it(s) {
|
|
1445
1446
|
s || (s = {});
|
|
1446
|
-
const e = s.registry || ee("$registry"), t = ee("$stonecrop"), r = O(), i = O(), n = O({}), o = O(), a = O(), c = O([]), u = O(!1), l = O(null),
|
|
1447
|
-
m && (r.value = m), s?.doctype && typeof s.doctype != "string" && (
|
|
1447
|
+
const e = s.registry || ee("$registry"), t = ee("$stonecrop"), r = O(), i = O(), n = O({}), o = O(), a = O(), c = O([]), u = O(!1), l = O(null), d = O(), w = C(() => !r.value || !d.value || !s.recordId || s.recordId === "new" ? !0 : r.value.isWorkflowReady(d.value, s.recordId).ready), $ = C(() => !r.value || !d.value || !s.recordId || s.recordId === "new" ? [] : r.value.isWorkflowReady(d.value, s.recordId).blockedLinks ?? []), m = t || F._root;
|
|
1448
|
+
m && (r.value = m), s?.doctype && typeof s.doctype != "string" && (d.value = s.doctype);
|
|
1448
1449
|
const S = O([]), b = O(-1), T = C(() => r.value?.getOperationLogStore().canUndo ?? !1), W = C(() => r.value?.getOperationLogStore().canRedo ?? !1), M = C(() => r.value?.getOperationLogStore().undoCount ?? 0), H = C(() => r.value?.getOperationLogStore().redoCount ?? 0), E = C(
|
|
1449
1450
|
() => r.value?.getOperationLogStore().undoRedoState ?? {
|
|
1450
1451
|
canUndo: !1,
|
|
@@ -1486,7 +1487,7 @@ function nt(s) {
|
|
|
1486
1487
|
);
|
|
1487
1488
|
} catch {
|
|
1488
1489
|
}
|
|
1489
|
-
s.doctype && typeof s.doctype != "string" && e && r.value && (i.value = r.value.getStore(), c.value = e.resolveSchema(s.doctype), (!s.recordId || s.recordId === "new") && (n.value = e.initializeRecord(c.value)), i.value &&
|
|
1490
|
+
s.doctype && typeof s.doctype != "string" && e && r.value && (i.value = r.value.getStore(), c.value = e.resolveSchema(s.doctype), (!s.recordId || s.recordId === "new") && (n.value = e.initializeRecord(c.value)), i.value && de(s.doctype, s.recordId || "new", n, i.value)), Ce(async () => {
|
|
1490
1491
|
if (!(!e || !r.value)) {
|
|
1491
1492
|
if (!s.doctype && e.router) {
|
|
1492
1493
|
const p = e.router.currentRoute.value;
|
|
@@ -1512,7 +1513,7 @@ function nt(s) {
|
|
|
1512
1513
|
}
|
|
1513
1514
|
} else
|
|
1514
1515
|
n.value = e.initializeRecord(c.value);
|
|
1515
|
-
i.value &&
|
|
1516
|
+
i.value && de(R, v || "new", n, i.value), r.value.runAction(R, "load", v ? [v] : void 0);
|
|
1516
1517
|
}
|
|
1517
1518
|
}
|
|
1518
1519
|
}
|
|
@@ -1536,7 +1537,7 @@ function nt(s) {
|
|
|
1536
1537
|
} finally {
|
|
1537
1538
|
u.value = !1;
|
|
1538
1539
|
}
|
|
1539
|
-
if (
|
|
1540
|
+
if (d.value = v, !v) return;
|
|
1540
1541
|
if (c.value = e.resolveSchema(v), p && p !== "new") {
|
|
1541
1542
|
const k = r.value.getRecordById(v, p);
|
|
1542
1543
|
if (k)
|
|
@@ -1551,7 +1552,7 @@ function nt(s) {
|
|
|
1551
1552
|
}
|
|
1552
1553
|
} else
|
|
1553
1554
|
n.value = e.initializeRecord(c.value);
|
|
1554
|
-
i.value &&
|
|
1555
|
+
i.value && de(v, p || "new", n, i.value);
|
|
1555
1556
|
} else if (p && p !== "new") {
|
|
1556
1557
|
const y = s.doctype, v = r.value.getRecordById(y, p);
|
|
1557
1558
|
if (v)
|
|
@@ -1569,12 +1570,12 @@ function nt(s) {
|
|
|
1569
1570
|
}
|
|
1570
1571
|
});
|
|
1571
1572
|
const g = (p, y) => {
|
|
1572
|
-
const v =
|
|
1573
|
+
const v = d.value || o.value;
|
|
1573
1574
|
if (!v) return "";
|
|
1574
1575
|
const k = y || s.recordId || a.value || "new";
|
|
1575
1576
|
return `${v.slug}.${k}.${p}`;
|
|
1576
1577
|
}, h = (p) => {
|
|
1577
|
-
const y =
|
|
1578
|
+
const y = d.value || o.value;
|
|
1578
1579
|
if (!(!i.value || !r.value || !y))
|
|
1579
1580
|
try {
|
|
1580
1581
|
const v = p.path.split(".");
|
|
@@ -1592,12 +1593,12 @@ function nt(s) {
|
|
|
1592
1593
|
}
|
|
1593
1594
|
i.value.set(p.path, p.value);
|
|
1594
1595
|
const k = p.fieldname.split("."), R = { ...n.value };
|
|
1595
|
-
k.length === 1 ? R[k[0]] = p.value :
|
|
1596
|
+
k.length === 1 ? R[k[0]] = p.value : Ve(R, k, p.value), n.value = R;
|
|
1596
1597
|
} catch {
|
|
1597
1598
|
}
|
|
1598
1599
|
};
|
|
1599
|
-
(s.doctype || e?.router) && (
|
|
1600
|
-
const
|
|
1600
|
+
(s.doctype || e?.router) && (fe("hstPathProvider", g), fe("hstChangeHandler", h));
|
|
1601
|
+
const f = (p, y) => {
|
|
1601
1602
|
if (!r.value)
|
|
1602
1603
|
throw new Error("Stonecrop instance not available");
|
|
1603
1604
|
return r.value.initializeNestedData(p, y);
|
|
@@ -1646,13 +1647,13 @@ function nt(s) {
|
|
|
1646
1647
|
hstStore: i,
|
|
1647
1648
|
formData: n,
|
|
1648
1649
|
resolvedSchema: c,
|
|
1649
|
-
initializeNestedData:
|
|
1650
|
+
initializeNestedData: f,
|
|
1650
1651
|
fetchNestedData: A,
|
|
1651
1652
|
collectRecordPayload: P,
|
|
1652
1653
|
createNestedContext: L,
|
|
1653
1654
|
isLoading: u,
|
|
1654
1655
|
error: l,
|
|
1655
|
-
resolvedDoctype:
|
|
1656
|
+
resolvedDoctype: d,
|
|
1656
1657
|
isWorkflowReady: w,
|
|
1657
1658
|
blockedLinks: $
|
|
1658
1659
|
} : !s.doctype && e?.router ? {
|
|
@@ -1663,13 +1664,13 @@ function nt(s) {
|
|
|
1663
1664
|
hstStore: i,
|
|
1664
1665
|
formData: n,
|
|
1665
1666
|
resolvedSchema: c,
|
|
1666
|
-
initializeNestedData:
|
|
1667
|
+
initializeNestedData: f,
|
|
1667
1668
|
fetchNestedData: A,
|
|
1668
1669
|
collectRecordPayload: P,
|
|
1669
1670
|
createNestedContext: L,
|
|
1670
1671
|
isLoading: u,
|
|
1671
1672
|
error: l,
|
|
1672
|
-
resolvedDoctype:
|
|
1673
|
+
resolvedDoctype: d,
|
|
1673
1674
|
isWorkflowReady: w,
|
|
1674
1675
|
blockedLinks: $
|
|
1675
1676
|
} : {
|
|
@@ -1677,7 +1678,7 @@ function nt(s) {
|
|
|
1677
1678
|
operationLog: N
|
|
1678
1679
|
};
|
|
1679
1680
|
}
|
|
1680
|
-
function
|
|
1681
|
+
function de(s, e, t, r) {
|
|
1681
1682
|
X(
|
|
1682
1683
|
t,
|
|
1683
1684
|
(i) => {
|
|
@@ -1693,7 +1694,7 @@ function fe(s, e, t, r) {
|
|
|
1693
1694
|
{ deep: !0 }
|
|
1694
1695
|
);
|
|
1695
1696
|
}
|
|
1696
|
-
function
|
|
1697
|
+
function Ve(s, e, t) {
|
|
1697
1698
|
let r = s;
|
|
1698
1699
|
for (let n = 0; n < e.length - 1; n++) {
|
|
1699
1700
|
const o = e[n];
|
|
@@ -1709,7 +1710,7 @@ function $e(s) {
|
|
|
1709
1710
|
function l(E) {
|
|
1710
1711
|
return t.undo(E);
|
|
1711
1712
|
}
|
|
1712
|
-
function
|
|
1713
|
+
function d(E) {
|
|
1713
1714
|
return t.redo(E);
|
|
1714
1715
|
}
|
|
1715
1716
|
function w() {
|
|
@@ -1750,7 +1751,7 @@ function $e(s) {
|
|
|
1750
1751
|
redoCount: u,
|
|
1751
1752
|
// Methods
|
|
1752
1753
|
undo: l,
|
|
1753
|
-
redo:
|
|
1754
|
+
redo: d,
|
|
1754
1755
|
startBatch: w,
|
|
1755
1756
|
commitBatch: $,
|
|
1756
1757
|
cancelBatch: m,
|
|
@@ -1762,7 +1763,7 @@ function $e(s) {
|
|
|
1762
1763
|
configure: H
|
|
1763
1764
|
};
|
|
1764
1765
|
}
|
|
1765
|
-
function
|
|
1766
|
+
function ot(s, e = !0) {
|
|
1766
1767
|
if (!e) return;
|
|
1767
1768
|
const { undo: t, redo: r, canUndo: i, canRedo: n } = $e(), o = xe();
|
|
1768
1769
|
q(o["Ctrl+Z"], () => {
|
|
@@ -1777,7 +1778,7 @@ function it(s, e = !0) {
|
|
|
1777
1778
|
n.value && r(s);
|
|
1778
1779
|
});
|
|
1779
1780
|
}
|
|
1780
|
-
async function
|
|
1781
|
+
async function st(s, e) {
|
|
1781
1782
|
const { startBatch: t, commitBatch: r, cancelBatch: i } = $e();
|
|
1782
1783
|
t();
|
|
1783
1784
|
try {
|
|
@@ -1903,6 +1904,21 @@ class Oe {
|
|
|
1903
1904
|
getSchemaArray() {
|
|
1904
1905
|
return this.schema ? this.schema.toArray() : [];
|
|
1905
1906
|
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Resolve a record's identity using this doctype's declared `primaryKey`, falling back to `id`.
|
|
1909
|
+
*
|
|
1910
|
+
* Lives here rather than at the call site because the doctype owns its schema — and because the
|
|
1911
|
+
* rule must match the server's, which builds its SQL identity predicate from the same declared
|
|
1912
|
+
* field via `@stonecrop/schema`'s `getPrimaryKeyField`.
|
|
1913
|
+
*
|
|
1914
|
+
* @param record - the record to read the identity from
|
|
1915
|
+
* @returns the identity as a string, or `undefined` when neither the declared key nor `id` yields one
|
|
1916
|
+
*
|
|
1917
|
+
* @public
|
|
1918
|
+
*/
|
|
1919
|
+
getRecordId(e) {
|
|
1920
|
+
return _e(this.getSchemaArray(), e);
|
|
1921
|
+
}
|
|
1906
1922
|
/**
|
|
1907
1923
|
* Returns the actions as a plain object for use with components that expect
|
|
1908
1924
|
* plain JavaScript objects.
|
|
@@ -2156,7 +2172,7 @@ class K {
|
|
|
2156
2172
|
i.push({ ...b });
|
|
2157
2173
|
continue;
|
|
2158
2174
|
}
|
|
2159
|
-
const l = this.resolveSchema(u, new Set(r)), { options:
|
|
2175
|
+
const l = this.resolveSchema(u, new Set(r)), { options: d, cardinality: w, kind: $, ...m } = n;
|
|
2160
2176
|
if (he(a, n.component) === "table")
|
|
2161
2177
|
i.push(this.buildTableConfig(n, l, a.component));
|
|
2162
2178
|
else {
|
|
@@ -2236,7 +2252,7 @@ class K {
|
|
|
2236
2252
|
if (i !== void 0)
|
|
2237
2253
|
t[r.fieldname] = i;
|
|
2238
2254
|
else {
|
|
2239
|
-
const n =
|
|
2255
|
+
const n = Fe(r.component);
|
|
2240
2256
|
n === "text" ? t[r.fieldname] = "" : n === "number" ? t[r.fieldname] = 0 : n === "boolean" ? t[r.fieldname] = !1 : n === "code" && r.language ? t[r.fieldname] = r.language === "json" ? {} : "" : t[r.fieldname] = null;
|
|
2241
2257
|
}
|
|
2242
2258
|
}
|
|
@@ -2333,14 +2349,14 @@ class K {
|
|
|
2333
2349
|
// }
|
|
2334
2350
|
// }
|
|
2335
2351
|
}
|
|
2336
|
-
async function
|
|
2352
|
+
async function He(s, e, t) {
|
|
2337
2353
|
await Pe();
|
|
2338
2354
|
try {
|
|
2339
2355
|
await t(s, e);
|
|
2340
2356
|
} catch {
|
|
2341
2357
|
}
|
|
2342
2358
|
}
|
|
2343
|
-
const
|
|
2359
|
+
const at = {
|
|
2344
2360
|
install: (s, e) => {
|
|
2345
2361
|
const t = s.config.globalProperties.$router, r = e?.router, i = t || r;
|
|
2346
2362
|
!t && r && s.use(r);
|
|
@@ -2360,32 +2376,32 @@ const st = {
|
|
|
2360
2376
|
if (e?.components)
|
|
2361
2377
|
for (const [a, c] of Object.entries(e.components))
|
|
2362
2378
|
s.component(a, c);
|
|
2363
|
-
e?.autoInitializeRouter && e.onRouterInitialized &&
|
|
2379
|
+
e?.autoInitializeRouter && e.onRouterInitialized && He(n, o, e.onRouterInitialized);
|
|
2364
2380
|
}
|
|
2365
|
-
},
|
|
2381
|
+
}, ct = Se("stonecrop-validation", () => {
|
|
2366
2382
|
const s = O([]), e = C(() => s.value.length === 0), t = C(() => {
|
|
2367
2383
|
const l = {};
|
|
2368
|
-
for (const
|
|
2369
|
-
l[
|
|
2384
|
+
for (const d of s.value)
|
|
2385
|
+
l[d.field] || (l[d.field] = []), l[d.field].push(d.message);
|
|
2370
2386
|
return l;
|
|
2371
2387
|
});
|
|
2372
2388
|
function r(l) {
|
|
2373
|
-
return s.value.filter((
|
|
2389
|
+
return s.value.filter((d) => d.field === l).map((d) => d.message);
|
|
2374
2390
|
}
|
|
2375
|
-
function i(l,
|
|
2376
|
-
s.value.push({ trigger: l, field:
|
|
2391
|
+
function i(l, d, w) {
|
|
2392
|
+
s.value.push({ trigger: l, field: d, message: w });
|
|
2377
2393
|
}
|
|
2378
2394
|
function n(l) {
|
|
2379
|
-
s.value = s.value.filter((
|
|
2395
|
+
s.value = s.value.filter((d) => d.trigger !== l);
|
|
2380
2396
|
}
|
|
2381
2397
|
function o() {
|
|
2382
2398
|
s.value = [];
|
|
2383
2399
|
}
|
|
2384
|
-
async function a(l,
|
|
2400
|
+
async function a(l, d, w, $) {
|
|
2385
2401
|
n(l);
|
|
2386
2402
|
const m = Object.freeze({ ...w }), S = (b, T) => i(l, b, T);
|
|
2387
2403
|
try {
|
|
2388
|
-
await
|
|
2404
|
+
await Be(d.clientHandler, { record: m, value: $, setError: S });
|
|
2389
2405
|
} catch (b) {
|
|
2390
2406
|
typeof console < "u" && console.error(
|
|
2391
2407
|
`Validation trigger "${l}" threw and was ignored (advisory — save is not blocked). Fix its clientHandler:`,
|
|
@@ -2393,14 +2409,14 @@ const st = {
|
|
|
2393
2409
|
);
|
|
2394
2410
|
}
|
|
2395
2411
|
}
|
|
2396
|
-
async function c(l,
|
|
2412
|
+
async function c(l, d, w) {
|
|
2397
2413
|
const $ = [];
|
|
2398
2414
|
for (const [m, S] of Object.entries(l))
|
|
2399
|
-
S.on.includes(
|
|
2415
|
+
S.on.includes(d) && $.push(a(m, S, w, w[d]));
|
|
2400
2416
|
await Promise.all($);
|
|
2401
2417
|
}
|
|
2402
|
-
async function u(l,
|
|
2403
|
-
await Promise.all(Object.entries(l).map(([w, $]) => a(w, $,
|
|
2418
|
+
async function u(l, d) {
|
|
2419
|
+
await Promise.all(Object.entries(l).map(([w, $]) => a(w, $, d, void 0)));
|
|
2404
2420
|
}
|
|
2405
2421
|
return {
|
|
2406
2422
|
errors: s,
|
|
@@ -2415,7 +2431,7 @@ const st = {
|
|
|
2415
2431
|
};
|
|
2416
2432
|
});
|
|
2417
2433
|
var I = /* @__PURE__ */ ((s) => (s.ERROR = "error", s.WARNING = "warning", s.INFO = "info", s))(I || {});
|
|
2418
|
-
class
|
|
2434
|
+
class Ue {
|
|
2419
2435
|
options;
|
|
2420
2436
|
/**
|
|
2421
2437
|
* Creates a new SchemaValidator instance
|
|
@@ -2443,10 +2459,10 @@ class He {
|
|
|
2443
2459
|
validate(e, t, r, i, n) {
|
|
2444
2460
|
const o = [], a = t ? Array.isArray(t) ? t : t.toArray() : [];
|
|
2445
2461
|
if (this.options.validateRequiredProperties && o.push(...this.validateRequiredProperties(e, a, n)), this.options.validateLinkTargets && this.options.registry && o.push(...this.validateLinkFields(e, a, this.options.registry)), this.options.validateLinks && this.options.registry && n && o.push(...this.validateLinkDeclarations(e, n, a, this.options.registry)), this.options.validateWorkflows && r && o.push(...this.validateWorkflow(e, r)), this.options.validateActions && i) {
|
|
2446
|
-
const
|
|
2447
|
-
o.push(...this.validateActionRegistration(e,
|
|
2462
|
+
const d = i instanceof Map ? i : i.toObject();
|
|
2463
|
+
o.push(...this.validateActionRegistration(e, d));
|
|
2448
2464
|
}
|
|
2449
|
-
const c = o.filter((
|
|
2465
|
+
const c = o.filter((d) => d.severity === I.ERROR).length, u = o.filter((d) => d.severity === I.WARNING).length, l = o.filter((d) => d.severity === I.INFO).length;
|
|
2450
2466
|
return {
|
|
2451
2467
|
valid: c === 0,
|
|
2452
2468
|
issues: o,
|
|
@@ -2559,14 +2575,14 @@ class He {
|
|
|
2559
2575
|
if (c.fieldname) {
|
|
2560
2576
|
const l = o.get(c.fieldname);
|
|
2561
2577
|
if (l && l.kind === "field") {
|
|
2562
|
-
const
|
|
2563
|
-
|
|
2578
|
+
const d = l.doctype;
|
|
2579
|
+
d && d !== c.target && n.push({
|
|
2564
2580
|
severity: I.ERROR,
|
|
2565
2581
|
rule: "link-field-target-mismatch",
|
|
2566
|
-
message: `Link field "${c.fieldname}" targets "${
|
|
2582
|
+
message: `Link field "${c.fieldname}" targets "${d}" but link declaration targets "${c.target}"`,
|
|
2567
2583
|
doctype: e,
|
|
2568
2584
|
fieldname: c.fieldname,
|
|
2569
|
-
context: { linkFieldTarget:
|
|
2585
|
+
context: { linkFieldTarget: d, linkTarget: c.target }
|
|
2570
2586
|
});
|
|
2571
2587
|
}
|
|
2572
2588
|
}
|
|
@@ -2607,8 +2623,8 @@ class He {
|
|
|
2607
2623
|
if (typeof l == "string")
|
|
2608
2624
|
n.add(l);
|
|
2609
2625
|
else if (l && typeof l == "object") {
|
|
2610
|
-
const
|
|
2611
|
-
typeof
|
|
2626
|
+
const d = "target" in l ? l.target : void 0;
|
|
2627
|
+
typeof d == "string" ? n.add(d) : Array.isArray(d) && d.forEach((w) => {
|
|
2612
2628
|
typeof w == "string" && n.add(w);
|
|
2613
2629
|
});
|
|
2614
2630
|
}
|
|
@@ -2655,41 +2671,41 @@ class He {
|
|
|
2655
2671
|
return r;
|
|
2656
2672
|
}
|
|
2657
2673
|
}
|
|
2658
|
-
function
|
|
2659
|
-
return new
|
|
2674
|
+
function je(s, e) {
|
|
2675
|
+
return new Ue({
|
|
2660
2676
|
registry: s,
|
|
2661
2677
|
...e
|
|
2662
2678
|
});
|
|
2663
2679
|
}
|
|
2664
|
-
function
|
|
2665
|
-
return
|
|
2680
|
+
function lt(s, e, t, r, i) {
|
|
2681
|
+
return je(t).validate(s, e, r, i);
|
|
2666
2682
|
}
|
|
2667
2683
|
export {
|
|
2668
2684
|
Oe as Doctype,
|
|
2669
2685
|
G as FieldTriggerEngine,
|
|
2670
2686
|
V as HST,
|
|
2671
2687
|
K as Registry,
|
|
2672
|
-
|
|
2688
|
+
Ue as SchemaValidator,
|
|
2673
2689
|
F as Stonecrop,
|
|
2674
2690
|
I as ValidationSeverity,
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2691
|
+
ze as createHST,
|
|
2692
|
+
je as createValidator,
|
|
2693
|
+
at as default,
|
|
2694
|
+
Be as executeClientHandler,
|
|
2679
2695
|
_ as getGlobalTriggerEngine,
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2696
|
+
rt as getStonecrop,
|
|
2697
|
+
tt as markOperationIrreversible,
|
|
2698
|
+
Qe as registerGlobalAction,
|
|
2699
|
+
Ye as registerTransitionAction,
|
|
2700
|
+
Xe as setFieldRollback,
|
|
2701
|
+
et as triggerTransition,
|
|
2702
|
+
nt as useLazyLink,
|
|
2687
2703
|
$e as useOperationLog,
|
|
2688
2704
|
Z as useOperationLogStore,
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2705
|
+
it as useStonecrop,
|
|
2706
|
+
ot as useUndoRedoShortcuts,
|
|
2707
|
+
ct as useValidationStore,
|
|
2708
|
+
lt as validateSchema,
|
|
2709
|
+
st as withBatch
|
|
2694
2710
|
};
|
|
2695
2711
|
//# sourceMappingURL=stonecrop.js.map
|