@stonecrop/stonecrop 0.16.5 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -8
- package/dist/src/client-action.d.ts +31 -0
- package/dist/src/client-action.d.ts.map +1 -0
- package/dist/src/client-action.js +169 -0
- package/dist/src/composables/stonecrop.d.ts +9 -6
- package/dist/src/composables/stonecrop.d.ts.map +1 -1
- package/dist/src/composables/stonecrop.js +19 -90
- package/dist/src/doctype.d.ts +15 -12
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/doctype.js +19 -20
- package/dist/src/draft.d.ts +35 -0
- package/dist/src/draft.d.ts.map +1 -0
- package/dist/src/draft.js +36 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +10 -4
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +6 -8
- package/dist/src/stonecrop.d.ts +67 -27
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stonecrop.js +98 -84
- package/dist/src/stores/operation-log.d.ts +1 -1
- package/dist/src/types/client-action.d.ts +121 -0
- package/dist/src/types/client-action.d.ts.map +1 -0
- package/dist/src/types/client-action.js +0 -0
- package/dist/src/types/doctype.d.ts +1 -4
- package/dist/src/types/doctype.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -0
- package/dist/stonecrop.d.ts +274 -49
- package/dist/stonecrop.js +662 -617
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
- package/src/client-action.ts +207 -0
- package/src/composables/stonecrop.ts +28 -102
- package/src/doctype.ts +18 -20
- package/src/draft.ts +38 -0
- package/src/index.ts +8 -2
- package/src/registry.ts +6 -8
- package/src/stonecrop.ts +107 -93
- package/src/types/client-action.ts +121 -0
- package/src/types/doctype.ts +1 -4
- package/src/types/index.ts +1 -0
package/dist/stonecrop.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defineStore as
|
|
1
|
+
import { useRouter as Te } from "vue-router";
|
|
2
|
+
import { defineStore as be, storeToRefs as ke } from "pinia";
|
|
3
|
+
import { ref as E, computed as P, watch as X, reactive as ue, inject as ee, onMounted as Ce, provide as de, getCurrentInstance as De, nextTick as Pe } from "vue";
|
|
3
4
|
import { useLocalStorage as Le, useMagicKeys as xe, whenever as q } from "@vueuse/core";
|
|
4
|
-
import { normalizeFieldKind as
|
|
5
|
-
import { List as
|
|
6
|
-
const
|
|
5
|
+
import { normalizeFieldKind as Fe, getRecordIdentity as _e, getRecordIdField as Ne, isActionAllowedInState as fe, resolveLinkRenderMode as ge, componentLinkExpansion as Se, componentCategory as Me } from "@stonecrop/schema";
|
|
6
|
+
import { List as he } from "immutable";
|
|
7
|
+
const Be = Object.getPrototypeOf(async () => {
|
|
7
8
|
}).constructor;
|
|
8
|
-
async function
|
|
9
|
+
async function Re(s, e = {}) {
|
|
9
10
|
const t = Object.keys(e);
|
|
10
|
-
return new
|
|
11
|
+
return new Be(...t, s)(...t.map((i) => e[i]));
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
const We = "new";
|
|
14
|
+
function _(s) {
|
|
15
|
+
return s === We;
|
|
16
|
+
}
|
|
17
|
+
function le() {
|
|
13
18
|
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
14
19
|
}
|
|
15
20
|
function Y(s) {
|
|
@@ -26,7 +31,7 @@ function Y(s) {
|
|
|
26
31
|
timestamp: t.timestamp.toISOString()
|
|
27
32
|
}))), e;
|
|
28
33
|
}
|
|
29
|
-
function
|
|
34
|
+
function ze(s) {
|
|
30
35
|
const e = {
|
|
31
36
|
type: s.type,
|
|
32
37
|
clientId: s.clientId,
|
|
@@ -40,39 +45,39 @@ function We(s) {
|
|
|
40
45
|
timestamp: new Date(t.timestamp)
|
|
41
46
|
}))), e;
|
|
42
47
|
}
|
|
43
|
-
function
|
|
48
|
+
function pe(s, e) {
|
|
44
49
|
(s.type === "set" || s.type === "delete") && e && typeof e.set == "function" && e.set(s.path, s.beforeValue, "undo");
|
|
45
50
|
}
|
|
46
|
-
function
|
|
51
|
+
function ve(s, e) {
|
|
47
52
|
(s.type === "set" || s.type === "delete") && e && typeof e.set == "function" && e.set(s.path, s.afterValue, "redo");
|
|
48
53
|
}
|
|
49
|
-
const
|
|
50
|
-
const s =
|
|
54
|
+
const G = be("hst-operation-log", () => {
|
|
55
|
+
const s = E({
|
|
51
56
|
maxOperations: 100,
|
|
52
57
|
enableCrossTabSync: !0,
|
|
53
58
|
enablePersistence: !1,
|
|
54
59
|
persistenceKeyPrefix: "stonecrop-ops"
|
|
55
|
-
}), e =
|
|
56
|
-
let
|
|
57
|
-
for (let
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
}), u =
|
|
60
|
+
}), e = E([]), t = E(-1), r = E(le()), i = E(!1), n = E([]), o = P(() => t.value < 0 ? !1 : e.value[t.value]?.reversible ?? !1), a = P(() => t.value < e.value.length - 1), c = P(() => {
|
|
61
|
+
let h = 0;
|
|
62
|
+
for (let p = t.value; p >= 0 && e.value[p]?.reversible; p--)
|
|
63
|
+
h++;
|
|
64
|
+
return h;
|
|
65
|
+
}), u = P(() => e.value.length - 1 - t.value), l = P(() => ({
|
|
61
66
|
canUndo: o.value,
|
|
62
67
|
canRedo: a.value,
|
|
63
68
|
undoCount: c.value,
|
|
64
69
|
redoCount: u.value,
|
|
65
70
|
currentIndex: t.value
|
|
66
71
|
}));
|
|
67
|
-
function d(
|
|
68
|
-
s.value = { ...s.value, ...
|
|
72
|
+
function d(h) {
|
|
73
|
+
s.value = { ...s.value, ...h }, s.value.enablePersistence && (oe(), H()), s.value.enableCrossTabSync && z();
|
|
69
74
|
}
|
|
70
|
-
function
|
|
75
|
+
function v(h, p = "user") {
|
|
71
76
|
const f = {
|
|
72
|
-
...
|
|
73
|
-
id:
|
|
77
|
+
...h,
|
|
78
|
+
id: le(),
|
|
74
79
|
timestamp: /* @__PURE__ */ new Date(),
|
|
75
|
-
source:
|
|
80
|
+
source: p,
|
|
76
81
|
userId: s.value.userId
|
|
77
82
|
};
|
|
78
83
|
if (s.value.operationFilter && !s.value.operationFilter(f))
|
|
@@ -80,25 +85,25 @@ const Z = Se("hst-operation-log", () => {
|
|
|
80
85
|
if (i.value && n.value.length > 0)
|
|
81
86
|
return n.value[n.value.length - 1].operations.push(f), f.id;
|
|
82
87
|
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
|
-
const
|
|
84
|
-
e.value = e.value.slice(
|
|
88
|
+
const I = e.value.length - s.value.maxOperations;
|
|
89
|
+
e.value = e.value.slice(I), t.value -= I;
|
|
85
90
|
}
|
|
86
|
-
return s.value.enableCrossTabSync &&
|
|
91
|
+
return s.value.enableCrossTabSync && V(f), f.id;
|
|
87
92
|
}
|
|
88
|
-
function
|
|
93
|
+
function S() {
|
|
89
94
|
i.value = !0, n.value.push({
|
|
90
|
-
id:
|
|
95
|
+
id: le(),
|
|
91
96
|
operations: []
|
|
92
97
|
});
|
|
93
98
|
}
|
|
94
|
-
function m(
|
|
99
|
+
function m(h) {
|
|
95
100
|
if (!i.value || n.value.length === 0)
|
|
96
101
|
return null;
|
|
97
|
-
const
|
|
102
|
+
const p = n.value.pop(), f = p.operations;
|
|
98
103
|
if (f.length === 0)
|
|
99
104
|
return n.value.length === 0 && (i.value = !1), null;
|
|
100
|
-
const
|
|
101
|
-
id:
|
|
105
|
+
const I = p.id, F = f.every((y) => y.reversible), g = {
|
|
106
|
+
id: I,
|
|
102
107
|
type: "batch",
|
|
103
108
|
path: "",
|
|
104
109
|
// Batch doesn't have a single path
|
|
@@ -108,186 +113,186 @@ const Z = Se("hst-operation-log", () => {
|
|
|
108
113
|
doctype: f[0]?.doctype || "",
|
|
109
114
|
timestamp: /* @__PURE__ */ new Date(),
|
|
110
115
|
source: "user",
|
|
111
|
-
reversible:
|
|
112
|
-
irreversibleReason:
|
|
113
|
-
descendantOperationIds: f.map((
|
|
114
|
-
metadata: { description:
|
|
116
|
+
reversible: F,
|
|
117
|
+
irreversibleReason: F ? void 0 : "Contains irreversible operations",
|
|
118
|
+
descendantOperationIds: f.map((y) => y.id),
|
|
119
|
+
metadata: { description: h }
|
|
115
120
|
};
|
|
116
|
-
return f.forEach((
|
|
117
|
-
|
|
118
|
-
}), n.value.length > 0 ? n.value[n.value.length - 1].operations.push(
|
|
121
|
+
return f.forEach((y) => {
|
|
122
|
+
y.ancestorOperationId = I;
|
|
123
|
+
}), n.value.length > 0 ? n.value[n.value.length - 1].operations.push(g) : (e.value.push(...f, g), t.value = e.value.length - 1), s.value.enableCrossTabSync && re(f, g), n.value.length === 0 && (i.value = !1), I;
|
|
119
124
|
}
|
|
120
|
-
function
|
|
125
|
+
function k() {
|
|
121
126
|
n.value = [], i.value = !1;
|
|
122
127
|
}
|
|
123
|
-
function
|
|
128
|
+
function w(h) {
|
|
124
129
|
if (!o.value) return !1;
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
127
|
-
return typeof console < "u" &&
|
|
130
|
+
const p = e.value[t.value];
|
|
131
|
+
if (!p.reversible)
|
|
132
|
+
return typeof console < "u" && p.irreversibleReason && console.warn("Cannot undo irreversible operation:", p.irreversibleReason), !1;
|
|
128
133
|
try {
|
|
129
|
-
if (
|
|
130
|
-
for (let f =
|
|
131
|
-
const
|
|
132
|
-
|
|
134
|
+
if (p.type === "batch" && p.descendantOperationIds)
|
|
135
|
+
for (let f = p.descendantOperationIds.length - 1; f >= 0; f--) {
|
|
136
|
+
const I = p.descendantOperationIds[f], F = e.value.find((g) => g.id === I);
|
|
137
|
+
F && pe(F, h);
|
|
133
138
|
}
|
|
134
139
|
else
|
|
135
|
-
|
|
136
|
-
return t.value--, s.value.enableCrossTabSync && ne(
|
|
140
|
+
pe(p, h);
|
|
141
|
+
return t.value--, s.value.enableCrossTabSync && ne(p), !0;
|
|
137
142
|
} catch (f) {
|
|
138
143
|
return typeof console < "u" && console.error("Undo failed:", f), !1;
|
|
139
144
|
}
|
|
140
145
|
}
|
|
141
|
-
function
|
|
146
|
+
function R(h) {
|
|
142
147
|
if (!a.value) return !1;
|
|
143
|
-
const
|
|
148
|
+
const p = e.value[t.value + 1];
|
|
144
149
|
try {
|
|
145
|
-
if (
|
|
146
|
-
for (const f of
|
|
147
|
-
const
|
|
148
|
-
|
|
150
|
+
if (p.type === "batch" && p.descendantOperationIds)
|
|
151
|
+
for (const f of p.descendantOperationIds) {
|
|
152
|
+
const I = e.value.find((F) => F.id === f);
|
|
153
|
+
I && ve(I, h);
|
|
149
154
|
}
|
|
150
155
|
else
|
|
151
|
-
|
|
152
|
-
return t.value++, s.value.enableCrossTabSync && ie(
|
|
156
|
+
ve(p, h);
|
|
157
|
+
return t.value++, s.value.enableCrossTabSync && ie(p), !0;
|
|
153
158
|
} catch (f) {
|
|
154
159
|
return typeof console < "u" && console.error("Redo failed:", f), !1;
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
|
-
function
|
|
158
|
-
const
|
|
162
|
+
function C() {
|
|
163
|
+
const h = e.value.filter((f) => f.reversible).length, p = e.value.map((f) => f.timestamp);
|
|
159
164
|
return {
|
|
160
165
|
operations: [...e.value],
|
|
161
166
|
currentIndex: t.value,
|
|
162
167
|
totalOperations: e.value.length,
|
|
163
|
-
reversibleOperations:
|
|
164
|
-
irreversibleOperations: e.value.length -
|
|
165
|
-
oldestOperation:
|
|
166
|
-
newestOperation:
|
|
168
|
+
reversibleOperations: h,
|
|
169
|
+
irreversibleOperations: e.value.length - h,
|
|
170
|
+
oldestOperation: p.length > 0 ? new Date(Math.min(...p.map((f) => f.getTime()))) : void 0,
|
|
171
|
+
newestOperation: p.length > 0 ? new Date(Math.max(...p.map((f) => f.getTime()))) : void 0
|
|
167
172
|
};
|
|
168
173
|
}
|
|
169
|
-
function
|
|
174
|
+
function L() {
|
|
170
175
|
e.value = [], t.value = -1;
|
|
171
176
|
}
|
|
172
|
-
function
|
|
173
|
-
return e.value.filter((f) => f.doctype ===
|
|
177
|
+
function N(h, p) {
|
|
178
|
+
return e.value.filter((f) => f.doctype === h && (p === void 0 || f.recordId === p));
|
|
174
179
|
}
|
|
175
|
-
function
|
|
176
|
-
const f = e.value.find((
|
|
177
|
-
f && (f.reversible = !1, f.irreversibleReason =
|
|
180
|
+
function $(h, p) {
|
|
181
|
+
const f = e.value.find((I) => I.id === h);
|
|
182
|
+
f && (f.reversible = !1, f.irreversibleReason = p);
|
|
178
183
|
}
|
|
179
|
-
function x(
|
|
180
|
-
const
|
|
184
|
+
function x(h, p, f, I = "success", F) {
|
|
185
|
+
const g = {
|
|
181
186
|
type: "action",
|
|
182
|
-
path: f && f.length > 0 ? `${
|
|
187
|
+
path: f && f.length > 0 ? `${h}.${f[0]}` : h,
|
|
183
188
|
fieldname: "",
|
|
184
189
|
beforeValue: null,
|
|
185
190
|
afterValue: null,
|
|
186
|
-
doctype:
|
|
191
|
+
doctype: h,
|
|
187
192
|
recordId: f && f.length > 0 ? f[0] : void 0,
|
|
188
193
|
reversible: !1,
|
|
189
194
|
// Actions are typically not reversible
|
|
190
|
-
actionName:
|
|
195
|
+
actionName: p,
|
|
191
196
|
actionRecordIds: f,
|
|
192
|
-
actionResult:
|
|
193
|
-
actionError:
|
|
197
|
+
actionResult: I,
|
|
198
|
+
actionError: F
|
|
194
199
|
};
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
let
|
|
198
|
-
function
|
|
199
|
-
typeof window > "u" || !window.BroadcastChannel || (
|
|
200
|
-
const
|
|
201
|
-
if (!
|
|
202
|
-
const f =
|
|
200
|
+
return v(g);
|
|
201
|
+
}
|
|
202
|
+
let T = null;
|
|
203
|
+
function z() {
|
|
204
|
+
typeof window > "u" || !window.BroadcastChannel || (T = new BroadcastChannel("stonecrop-operation-log"), T.addEventListener("message", (h) => {
|
|
205
|
+
const p = h.data;
|
|
206
|
+
if (!p || typeof p != "object") return;
|
|
207
|
+
const f = ze(p);
|
|
203
208
|
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((
|
|
209
|
+
...f.operations.map((I) => Object.assign({}, I, { source: "sync" }))
|
|
205
210
|
), t.value = e.value.length - 1));
|
|
206
211
|
}));
|
|
207
212
|
}
|
|
208
|
-
function
|
|
209
|
-
if (!
|
|
210
|
-
const
|
|
213
|
+
function V(h) {
|
|
214
|
+
if (!T) return;
|
|
215
|
+
const p = {
|
|
211
216
|
type: "operation",
|
|
212
|
-
operation:
|
|
217
|
+
operation: h,
|
|
213
218
|
clientId: r.value,
|
|
214
219
|
timestamp: /* @__PURE__ */ new Date()
|
|
215
220
|
};
|
|
216
|
-
|
|
221
|
+
T.postMessage(Y(p));
|
|
217
222
|
}
|
|
218
|
-
function re(
|
|
219
|
-
if (!
|
|
223
|
+
function re(h, p) {
|
|
224
|
+
if (!T) return;
|
|
220
225
|
const f = {
|
|
221
226
|
type: "operation",
|
|
222
|
-
operations: [...
|
|
227
|
+
operations: [...h, p],
|
|
223
228
|
clientId: r.value,
|
|
224
229
|
timestamp: /* @__PURE__ */ new Date()
|
|
225
230
|
};
|
|
226
|
-
|
|
231
|
+
T.postMessage(Y(f));
|
|
227
232
|
}
|
|
228
|
-
function ne(
|
|
229
|
-
if (!
|
|
230
|
-
const
|
|
233
|
+
function ne(h) {
|
|
234
|
+
if (!T) return;
|
|
235
|
+
const p = {
|
|
231
236
|
type: "undo",
|
|
232
|
-
operation:
|
|
237
|
+
operation: h,
|
|
233
238
|
clientId: r.value,
|
|
234
239
|
timestamp: /* @__PURE__ */ new Date()
|
|
235
240
|
};
|
|
236
|
-
|
|
241
|
+
T.postMessage(Y(p));
|
|
237
242
|
}
|
|
238
|
-
function ie(
|
|
239
|
-
if (!
|
|
240
|
-
const
|
|
243
|
+
function ie(h) {
|
|
244
|
+
if (!T) return;
|
|
245
|
+
const p = {
|
|
241
246
|
type: "redo",
|
|
242
|
-
operation:
|
|
247
|
+
operation: h,
|
|
243
248
|
clientId: r.value,
|
|
244
249
|
timestamp: /* @__PURE__ */ new Date()
|
|
245
250
|
};
|
|
246
|
-
|
|
251
|
+
T.postMessage(Y(p));
|
|
247
252
|
}
|
|
248
|
-
const
|
|
253
|
+
const K = Le("stonecrop-operations", null, {
|
|
249
254
|
serializer: {
|
|
250
|
-
read: (
|
|
255
|
+
read: (h) => {
|
|
251
256
|
try {
|
|
252
|
-
return JSON.parse(
|
|
257
|
+
return JSON.parse(h);
|
|
253
258
|
} catch {
|
|
254
259
|
return null;
|
|
255
260
|
}
|
|
256
261
|
},
|
|
257
|
-
write: (
|
|
262
|
+
write: (h) => h ? JSON.stringify(h) : ""
|
|
258
263
|
}
|
|
259
264
|
});
|
|
260
265
|
function oe() {
|
|
261
266
|
if (!(typeof window > "u"))
|
|
262
267
|
try {
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
...
|
|
266
|
-
timestamp: new Date(
|
|
267
|
-
})), t.value =
|
|
268
|
-
} catch (
|
|
269
|
-
typeof console < "u" && console.error("Failed to load operations from persistence:",
|
|
268
|
+
const h = K.value;
|
|
269
|
+
h && Array.isArray(h.operations) && (e.value = h.operations.map((p) => ({
|
|
270
|
+
...p,
|
|
271
|
+
timestamp: new Date(p.timestamp)
|
|
272
|
+
})), t.value = h.currentIndex ?? -1);
|
|
273
|
+
} catch (h) {
|
|
274
|
+
typeof console < "u" && console.error("Failed to load operations from persistence:", h);
|
|
270
275
|
}
|
|
271
276
|
}
|
|
272
|
-
function
|
|
277
|
+
function Z() {
|
|
273
278
|
if (!(typeof window > "u"))
|
|
274
279
|
try {
|
|
275
|
-
|
|
276
|
-
operations: e.value.map((
|
|
277
|
-
...
|
|
278
|
-
timestamp:
|
|
280
|
+
K.value = {
|
|
281
|
+
operations: e.value.map((h) => ({
|
|
282
|
+
...h,
|
|
283
|
+
timestamp: h.timestamp.toISOString()
|
|
279
284
|
})),
|
|
280
285
|
currentIndex: t.value
|
|
281
286
|
};
|
|
282
|
-
} catch (
|
|
283
|
-
typeof console < "u" && console.error("Failed to save operations to persistence:",
|
|
287
|
+
} catch (h) {
|
|
288
|
+
typeof console < "u" && console.error("Failed to save operations to persistence:", h);
|
|
284
289
|
}
|
|
285
290
|
}
|
|
286
|
-
function
|
|
291
|
+
function H() {
|
|
287
292
|
X(
|
|
288
293
|
[e, t],
|
|
289
294
|
() => {
|
|
290
|
-
s.value.enablePersistence &&
|
|
295
|
+
s.value.enablePersistence && Z();
|
|
291
296
|
},
|
|
292
297
|
{ deep: !0 }
|
|
293
298
|
);
|
|
@@ -306,20 +311,20 @@ const Z = Se("hst-operation-log", () => {
|
|
|
306
311
|
redoCount: u,
|
|
307
312
|
// Methods
|
|
308
313
|
configure: d,
|
|
309
|
-
addOperation:
|
|
310
|
-
startBatch:
|
|
314
|
+
addOperation: v,
|
|
315
|
+
startBatch: S,
|
|
311
316
|
commitBatch: m,
|
|
312
|
-
cancelBatch:
|
|
313
|
-
undo:
|
|
314
|
-
redo:
|
|
315
|
-
clear:
|
|
316
|
-
getOperationsFor:
|
|
317
|
-
getSnapshot:
|
|
318
|
-
markIrreversible:
|
|
317
|
+
cancelBatch: k,
|
|
318
|
+
undo: w,
|
|
319
|
+
redo: R,
|
|
320
|
+
clear: L,
|
|
321
|
+
getOperationsFor: N,
|
|
322
|
+
getSnapshot: C,
|
|
323
|
+
markIrreversible: $,
|
|
319
324
|
logAction: x
|
|
320
325
|
};
|
|
321
326
|
});
|
|
322
|
-
class
|
|
327
|
+
class U {
|
|
323
328
|
/**
|
|
324
329
|
* The root FieldTriggerEngine instance
|
|
325
330
|
*/
|
|
@@ -340,7 +345,7 @@ class G {
|
|
|
340
345
|
* @param options - Configuration options for the field trigger engine
|
|
341
346
|
*/
|
|
342
347
|
constructor(e = {}) {
|
|
343
|
-
return
|
|
348
|
+
return U._root ? U._root : (U._root = this, this.options = {
|
|
344
349
|
defaultTimeout: e.defaultTimeout ?? 5e3,
|
|
345
350
|
debug: e.debug ?? !1,
|
|
346
351
|
enableRollback: e.enableRollback ?? !0,
|
|
@@ -439,47 +444,47 @@ class G {
|
|
|
439
444
|
};
|
|
440
445
|
const o = performance.now(), a = [];
|
|
441
446
|
let c = !1, u = !1, l;
|
|
442
|
-
const d = this.getFieldRollback(r, i),
|
|
443
|
-
|
|
444
|
-
for (const
|
|
447
|
+
const d = this.getFieldRollback(r, i), v = t.enableRollback ?? d ?? this.options.enableRollback;
|
|
448
|
+
v && e.store && (l = this.captureSnapshot(e));
|
|
449
|
+
for (const w of n)
|
|
445
450
|
try {
|
|
446
|
-
const
|
|
447
|
-
if (a.push(
|
|
451
|
+
const R = await this.executeAction(w, e, t.timeout);
|
|
452
|
+
if (a.push(R), !R.success) {
|
|
448
453
|
c = !0;
|
|
449
454
|
break;
|
|
450
455
|
}
|
|
451
|
-
} catch (
|
|
452
|
-
const
|
|
456
|
+
} catch (R) {
|
|
457
|
+
const L = {
|
|
453
458
|
success: !1,
|
|
454
|
-
error:
|
|
459
|
+
error: R instanceof Error ? R : new Error(String(R)),
|
|
455
460
|
executionTime: 0,
|
|
456
|
-
action:
|
|
461
|
+
action: w
|
|
457
462
|
};
|
|
458
|
-
a.push(
|
|
463
|
+
a.push(L), c = !0;
|
|
459
464
|
break;
|
|
460
465
|
}
|
|
461
|
-
if (
|
|
466
|
+
if (v && c && l && e.store)
|
|
462
467
|
try {
|
|
463
468
|
this.restoreSnapshot(e, l), u = !0;
|
|
464
|
-
} catch (
|
|
465
|
-
console.error("[FieldTriggers] Rollback failed:",
|
|
469
|
+
} catch (w) {
|
|
470
|
+
console.error("[FieldTriggers] Rollback failed:", w);
|
|
466
471
|
}
|
|
467
|
-
const
|
|
472
|
+
const S = performance.now() - o, m = a.filter((w) => !w.success && w.error != null);
|
|
468
473
|
if (m.length > 0 && this.options.errorHandler)
|
|
469
|
-
for (const
|
|
474
|
+
for (const w of m)
|
|
470
475
|
try {
|
|
471
|
-
|
|
472
|
-
} catch (
|
|
473
|
-
console.error("[FieldTriggers] Error in global error handler:",
|
|
476
|
+
w.error && this.options.errorHandler(w.error, e, w.action);
|
|
477
|
+
} catch (R) {
|
|
478
|
+
console.error("[FieldTriggers] Error in global error handler:", R);
|
|
474
479
|
}
|
|
475
480
|
return {
|
|
476
481
|
path: e.path,
|
|
477
482
|
actionResults: a,
|
|
478
|
-
totalExecutionTime:
|
|
479
|
-
allSucceeded: a.every((
|
|
483
|
+
totalExecutionTime: S,
|
|
484
|
+
allSucceeded: a.every((w) => w.success),
|
|
480
485
|
stoppedOnError: c,
|
|
481
486
|
rolledBack: u,
|
|
482
|
-
snapshot: this.options.debug &&
|
|
487
|
+
snapshot: this.options.debug && v ? l : void 0
|
|
483
488
|
// Only include snapshot in debug mode if rollback is enabled
|
|
484
489
|
};
|
|
485
490
|
}
|
|
@@ -659,20 +664,20 @@ class G {
|
|
|
659
664
|
}
|
|
660
665
|
}
|
|
661
666
|
}
|
|
662
|
-
function
|
|
663
|
-
return new
|
|
667
|
+
function B(s) {
|
|
668
|
+
return new U(s);
|
|
664
669
|
}
|
|
665
|
-
function
|
|
666
|
-
|
|
670
|
+
function rt(s, e) {
|
|
671
|
+
B().registerAction(s, e);
|
|
667
672
|
}
|
|
668
|
-
function
|
|
669
|
-
|
|
673
|
+
function nt(s, e) {
|
|
674
|
+
B().registerTransitionAction(s, e);
|
|
670
675
|
}
|
|
671
|
-
function
|
|
672
|
-
|
|
676
|
+
function it(s, e, t) {
|
|
677
|
+
B().setFieldRollback(s, e, t);
|
|
673
678
|
}
|
|
674
|
-
async function
|
|
675
|
-
const r =
|
|
679
|
+
async function ot(s, e, t) {
|
|
680
|
+
const r = B(), i = {
|
|
676
681
|
path: t?.path || (t?.recordId ? `${s}.${t.recordId}` : s),
|
|
677
682
|
fieldname: "",
|
|
678
683
|
beforeValue: void 0,
|
|
@@ -688,28 +693,28 @@ async function et(s, e, t) {
|
|
|
688
693
|
};
|
|
689
694
|
return await r.executeTransitionActions(i);
|
|
690
695
|
}
|
|
691
|
-
function
|
|
696
|
+
function st(s, e) {
|
|
692
697
|
if (s)
|
|
693
698
|
try {
|
|
694
|
-
|
|
699
|
+
G().markIrreversible(s, e);
|
|
695
700
|
} catch {
|
|
696
701
|
}
|
|
697
702
|
}
|
|
698
|
-
function
|
|
703
|
+
function me() {
|
|
699
704
|
try {
|
|
700
|
-
return
|
|
705
|
+
return G();
|
|
701
706
|
} catch {
|
|
702
707
|
return null;
|
|
703
708
|
}
|
|
704
709
|
}
|
|
705
|
-
class
|
|
710
|
+
class W {
|
|
706
711
|
static instance;
|
|
707
712
|
/**
|
|
708
713
|
* Gets the singleton instance of HST
|
|
709
714
|
* @returns The HST singleton instance
|
|
710
715
|
*/
|
|
711
716
|
static getInstance() {
|
|
712
|
-
return
|
|
717
|
+
return W.instance || (W.instance = new W()), W.instance;
|
|
713
718
|
}
|
|
714
719
|
/**
|
|
715
720
|
* Gets the global registry instance
|
|
@@ -750,7 +755,7 @@ class te {
|
|
|
750
755
|
doctype;
|
|
751
756
|
hst;
|
|
752
757
|
constructor(e, t, r = "", i = null) {
|
|
753
|
-
return this.target = e, this.ancestorPath = r, this.rootNode = i || this, this.doctype = t, this.hst =
|
|
758
|
+
return this.target = e, this.ancestorPath = r, this.rootNode = i || this, this.doctype = t, this.hst = W.getInstance(), new Proxy(this, {
|
|
754
759
|
get(n, o) {
|
|
755
760
|
if (o in n) return Reflect.get(n, o);
|
|
756
761
|
const a = String(o);
|
|
@@ -779,12 +784,12 @@ class te {
|
|
|
779
784
|
}
|
|
780
785
|
const n = this.has(e) ? this.get(e) : void 0;
|
|
781
786
|
if (r !== "undo" && r !== "redo") {
|
|
782
|
-
const o =
|
|
787
|
+
const o = me();
|
|
783
788
|
if (o && typeof o.addOperation == "function") {
|
|
784
|
-
const a = i.split("."), c = this.doctype === "StonecropStore" && a.length >= 1 ? a[0] : this.doctype, u = a.length >= 2 ? a[1] : void 0, l = a.slice(2).join(".") || a[a.length - 1],
|
|
789
|
+
const a = i.split("."), c = this.doctype === "StonecropStore" && a.length >= 1 ? a[0] : this.doctype, u = a.length >= 2 ? a[1] : void 0, l = a.slice(2).join(".") || a[a.length - 1], v = t === void 0 && n !== void 0 ? "delete" : "set";
|
|
785
790
|
o.addOperation(
|
|
786
791
|
{
|
|
787
|
-
type:
|
|
792
|
+
type: v,
|
|
788
793
|
path: i,
|
|
789
794
|
fieldname: l,
|
|
790
795
|
beforeValue: n,
|
|
@@ -841,7 +846,7 @@ class te {
|
|
|
841
846
|
* Trigger an XState transition with optional context data
|
|
842
847
|
*/
|
|
843
848
|
async triggerTransition(e, t) {
|
|
844
|
-
const r =
|
|
849
|
+
const r = B(), i = this.ancestorPath.split(".");
|
|
845
850
|
let n = this.doctype, o;
|
|
846
851
|
this.doctype === "StonecropStore" && i.length >= 1 && (n = i[0]), i.length >= 2 && (o = i[1]);
|
|
847
852
|
const a = {
|
|
@@ -859,7 +864,7 @@ class te {
|
|
|
859
864
|
currentState: t?.currentState,
|
|
860
865
|
targetState: t?.targetState,
|
|
861
866
|
fsmContext: t?.fsmContext
|
|
862
|
-
}, c =
|
|
867
|
+
}, c = me();
|
|
863
868
|
return c && typeof c.addOperation == "function" && c.addOperation(
|
|
864
869
|
{
|
|
865
870
|
type: "transition",
|
|
@@ -926,7 +931,7 @@ class te {
|
|
|
926
931
|
const i = e.split(".");
|
|
927
932
|
if (i.length < 3)
|
|
928
933
|
return;
|
|
929
|
-
const n =
|
|
934
|
+
const n = B(), o = i.slice(2).join(".") || i[i.length - 1];
|
|
930
935
|
let a = this.doctype;
|
|
931
936
|
this.doctype === "StonecropStore" && i.length >= 1 && (a = i[0]);
|
|
932
937
|
let c;
|
|
@@ -982,10 +987,10 @@ class te {
|
|
|
982
987
|
return e ? e.replace(/\[(\d+)\]/g, ".$1").split(".").filter((r) => r.length > 0) : [];
|
|
983
988
|
}
|
|
984
989
|
}
|
|
985
|
-
function
|
|
990
|
+
function Ve(s, e) {
|
|
986
991
|
return new te(s, e, "", null);
|
|
987
992
|
}
|
|
988
|
-
class
|
|
993
|
+
class M {
|
|
989
994
|
/**
|
|
990
995
|
* Singleton instance of Stonecrop. Only one Stonecrop instance can exist
|
|
991
996
|
* per application, ensuring consistent HST state and registry access.
|
|
@@ -998,6 +1003,11 @@ class F {
|
|
|
998
1003
|
_operationLogStore;
|
|
999
1004
|
_operationLogConfig;
|
|
1000
1005
|
_client;
|
|
1006
|
+
/**
|
|
1007
|
+
* Per-doctype page info from the last list read, keyed by slug. Reactive so views tracking
|
|
1008
|
+
* it update on fetch. Deliberately not in HST — see {@link Stonecrop.getRecords}.
|
|
1009
|
+
*/
|
|
1010
|
+
pageInfo = ue({});
|
|
1001
1011
|
/** The registry instance containing all doctype definitions */
|
|
1002
1012
|
registry;
|
|
1003
1013
|
/**
|
|
@@ -1007,7 +1017,7 @@ class F {
|
|
|
1007
1017
|
* @param options - Options including the data client (can be set later via setClient)
|
|
1008
1018
|
*/
|
|
1009
1019
|
constructor(e, t, r) {
|
|
1010
|
-
return
|
|
1020
|
+
return M._root ? M._root : (M._root = this, this.registry = e, this._operationLogConfig = t, this._client = r?.client, this.initializeHSTStore(), this.setupRegistrySync(), this);
|
|
1011
1021
|
}
|
|
1012
1022
|
/**
|
|
1013
1023
|
* Set the data client for fetching doctype metadata and records.
|
|
@@ -1037,7 +1047,7 @@ class F {
|
|
|
1037
1047
|
* @internal
|
|
1038
1048
|
*/
|
|
1039
1049
|
getOperationLogStore() {
|
|
1040
|
-
return this._operationLogStore || (this._operationLogStore =
|
|
1050
|
+
return this._operationLogStore || (this._operationLogStore = G(), this._operationLogConfig && this._operationLogStore.configure(this._operationLogConfig)), this._operationLogStore;
|
|
1041
1051
|
}
|
|
1042
1052
|
/**
|
|
1043
1053
|
* Initialize the HST store structure
|
|
@@ -1046,7 +1056,7 @@ class F {
|
|
|
1046
1056
|
const e = {};
|
|
1047
1057
|
Object.keys(this.registry.registry).forEach((t) => {
|
|
1048
1058
|
e[t] = {};
|
|
1049
|
-
}), this.hstStore =
|
|
1059
|
+
}), this.hstStore = Ve(ue(e), "StonecropStore");
|
|
1050
1060
|
}
|
|
1051
1061
|
/**
|
|
1052
1062
|
* Setup automatic sync with Registry when doctypes are added
|
|
@@ -1124,53 +1134,6 @@ class F {
|
|
|
1124
1134
|
setup(e) {
|
|
1125
1135
|
this.ensureDoctypeExists(e.slug);
|
|
1126
1136
|
}
|
|
1127
|
-
/**
|
|
1128
|
-
* Run action on doctype
|
|
1129
|
-
* Executes the action and logs it to the operation log for audit tracking
|
|
1130
|
-
* @param doctype - The doctype
|
|
1131
|
-
* @param action - The action to run
|
|
1132
|
-
* @param args - Action arguments (typically record IDs)
|
|
1133
|
-
*/
|
|
1134
|
-
runAction(e, t, r) {
|
|
1135
|
-
const n = this.registry.registry[e.slug]?.actions?.get(t), o = Array.isArray(r) ? r.filter((w) => typeof w == "string") : void 0, a = o?.[0], c = a ? this.isWorkflowReady(e, a) : { ready: !0 };
|
|
1136
|
-
if (!c.ready)
|
|
1137
|
-
throw this.getOperationLogStore().logAction(
|
|
1138
|
-
e.doctype,
|
|
1139
|
-
t,
|
|
1140
|
-
o,
|
|
1141
|
-
"failure",
|
|
1142
|
-
`BLOCKED: missing data for links: ${c.blockedLinks?.join(", ")}`
|
|
1143
|
-
), new Error(`Workflow blocked: missing data for links: ${c.blockedLinks?.join(", ")}`);
|
|
1144
|
-
const u = this.getOperationLogStore();
|
|
1145
|
-
let l = "success", d;
|
|
1146
|
-
try {
|
|
1147
|
-
if (n && n.length > 0) {
|
|
1148
|
-
const w = _();
|
|
1149
|
-
n.forEach(($) => {
|
|
1150
|
-
try {
|
|
1151
|
-
const m = w.getAction($);
|
|
1152
|
-
if (!m) throw new Error(`Action "${$}" is not registered in FieldTriggerEngine`);
|
|
1153
|
-
const S = {
|
|
1154
|
-
path: `${e.slug}.${o?.[0] ?? ""}`,
|
|
1155
|
-
fieldname: t,
|
|
1156
|
-
beforeValue: void 0,
|
|
1157
|
-
afterValue: r,
|
|
1158
|
-
operation: "set",
|
|
1159
|
-
doctype: e.doctype,
|
|
1160
|
-
recordId: a,
|
|
1161
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
1162
|
-
};
|
|
1163
|
-
m(S);
|
|
1164
|
-
} catch (m) {
|
|
1165
|
-
throw l = "failure", d = m instanceof Error ? m.message : "Unknown error", m;
|
|
1166
|
-
}
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
} catch {
|
|
1170
|
-
} finally {
|
|
1171
|
-
u.logAction(e.doctype, t, o, l, d);
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
1137
|
/**
|
|
1175
1138
|
* Get the effective blockWorkflows value for a link.
|
|
1176
1139
|
* Returns true if blockWorkflows is explicitly true, or if it's absent and fetch method is 'sync'.
|
|
@@ -1188,7 +1151,7 @@ class F {
|
|
|
1188
1151
|
* @returns Object with `ready: true` if all blocked links are loaded, or `ready: false` with `blockedLinks` array
|
|
1189
1152
|
*/
|
|
1190
1153
|
isWorkflowReady(e, t) {
|
|
1191
|
-
if (t
|
|
1154
|
+
if (_(t))
|
|
1192
1155
|
return { ready: !0 };
|
|
1193
1156
|
const r = this.registry.getDescendantLinks(e.slug), i = [];
|
|
1194
1157
|
for (const n of r)
|
|
@@ -1199,41 +1162,98 @@ class F {
|
|
|
1199
1162
|
return i.length > 0 ? { ready: !1, blockedLinks: i } : { ready: !0 };
|
|
1200
1163
|
}
|
|
1201
1164
|
/**
|
|
1202
|
-
*
|
|
1165
|
+
* Fetch a doctype's records from the server and store them in HST.
|
|
1166
|
+
*
|
|
1167
|
+
* This is the one read path for a list. Every caller shares its keying rule, so a row is
|
|
1168
|
+
* always stored under the identity its Edit link will later ask for.
|
|
1169
|
+
*
|
|
1170
|
+
* Deliberately unguarded, unlike {@link Stonecrop.getRecord}: a list is a view of data that
|
|
1171
|
+
* changes, so revisiting one must re-read it rather than serve whatever HST happens to hold.
|
|
1172
|
+
*
|
|
1173
|
+
* `options` is forwarded to the client untouched — no row limit is invented here, because
|
|
1174
|
+
* nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
|
|
1175
|
+
* passes none gets whatever the server considers a reasonable page.
|
|
1176
|
+
*
|
|
1203
1177
|
* @param doctype - The doctype
|
|
1178
|
+
* @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
|
|
1204
1179
|
* @throws Error if no data client has been configured
|
|
1180
|
+
* @public
|
|
1205
1181
|
*/
|
|
1206
|
-
async getRecords(e) {
|
|
1182
|
+
async getRecords(e, t) {
|
|
1207
1183
|
if (!this._client)
|
|
1208
1184
|
throw new Error(
|
|
1209
1185
|
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records."
|
|
1210
1186
|
);
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1187
|
+
const r = await this._client.getRecords(e, t), i = r.data;
|
|
1188
|
+
return this.pageInfo[e.slug] = { hasMore: r.hasMore, count: r.count }, i.forEach((n) => {
|
|
1189
|
+
const o = e.getRecordId(n);
|
|
1190
|
+
o !== void 0 && this.addRecord(e, o, n);
|
|
1191
|
+
}), r;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* What the last {@link Stonecrop.getRecords} for this doctype returned about the wider set.
|
|
1195
|
+
*
|
|
1196
|
+
* Answers the question HST cannot: HST holds what was fetched, so counting its keys reports
|
|
1197
|
+
* how much has been seen, never how much exists. Reactive, so a view reading it re-renders
|
|
1198
|
+
* when a fetch lands.
|
|
1199
|
+
*
|
|
1200
|
+
* @param doctype - The doctype slug string or Doctype object
|
|
1201
|
+
* @returns Page info, or undefined if this doctype's records have not been fetched
|
|
1202
|
+
* @public
|
|
1203
|
+
*/
|
|
1204
|
+
getPageInfo(e) {
|
|
1205
|
+
const t = typeof e == "string" ? e : e.slug;
|
|
1206
|
+
return this.pageInfo[t];
|
|
1215
1207
|
}
|
|
1216
1208
|
/**
|
|
1217
|
-
*
|
|
1209
|
+
* Fetch a single record from the server and store it in HST.
|
|
1210
|
+
*
|
|
1211
|
+
* This is the one read path for a record, and it owns the whole job: deciding whether a fetch
|
|
1212
|
+
* is warranted, performing it, and writing the result back under the doctype's declared
|
|
1213
|
+
* identity. Callers ask for a record and get one; they do not re-derive when to ask.
|
|
1214
|
+
*
|
|
1215
|
+
* Two cases return without touching the network, because in both the answer is already known:
|
|
1216
|
+
* a draft does not exist on the server yet, and a record already in HST has been read.
|
|
1217
|
+
* Refetching the latter would also discard unsaved edits sitting in the store.
|
|
1218
|
+
*
|
|
1218
1219
|
* @param doctype - The doctype slug string or Doctype object
|
|
1219
1220
|
* @param recordId - The record ID
|
|
1221
|
+
* @param options - Query options (includeNested, maxDepth), forwarded to the client
|
|
1220
1222
|
* @throws Error if no data client has been configured
|
|
1221
1223
|
* @throws Error if a slug string is given and no matching doctype is found in the registry
|
|
1224
|
+
* @public
|
|
1222
1225
|
*/
|
|
1223
|
-
async getRecord(e, t) {
|
|
1226
|
+
async getRecord(e, t, r) {
|
|
1224
1227
|
if (!this._client)
|
|
1225
1228
|
throw new Error(
|
|
1226
1229
|
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records."
|
|
1227
1230
|
);
|
|
1228
|
-
const
|
|
1229
|
-
if (!
|
|
1231
|
+
const i = typeof e == "string" ? this.registry.getDoctype(e) : e;
|
|
1232
|
+
if (!i)
|
|
1230
1233
|
throw new Error(`Doctype not found: ${typeof e == "string" ? e : e.slug}`);
|
|
1231
|
-
|
|
1232
|
-
|
|
1234
|
+
if (_(t) || this.getRecordById(i.slug, t))
|
|
1235
|
+
return;
|
|
1236
|
+
const n = await this._client.getRecord(i, t, r);
|
|
1237
|
+
n?.record && this.addRecord(i, t, n.record);
|
|
1233
1238
|
}
|
|
1234
1239
|
/**
|
|
1235
|
-
* Dispatch an action to the server via the configured data client
|
|
1236
|
-
*
|
|
1240
|
+
* Dispatch an action to the server via the configured data client, and file the record it
|
|
1241
|
+
* returns into HST under the identity the *server* settled on.
|
|
1242
|
+
*
|
|
1243
|
+
* The write is the point. For a created record the settled identity is never the one that was
|
|
1244
|
+
* dispatched, so a caller that stores the result under the id it sent files the record under a
|
|
1245
|
+
* key nothing can fetch and leaves the next save creating a second one. Every host that
|
|
1246
|
+
* hand-rolled this got it wrong the same way, so it stops being the caller's job — this is the
|
|
1247
|
+
* write-side twin of {@link Stonecrop.getRecords}, which keys reads by the same rule.
|
|
1248
|
+
*
|
|
1249
|
+
* Two things are deliberately NOT done here, because both need the id that was dispatched and
|
|
1250
|
+
* that lives inside `args` — an opaque array whose shape is a convention between a host's
|
|
1251
|
+
* client and its server handlers, not something this layer may parse. Dropping the stale key
|
|
1252
|
+
* and moving the route therefore stay with `useClientAction`, which knows both ids.
|
|
1253
|
+
*
|
|
1254
|
+
* A result that states no identity of its own — a `{ state: 'APPROVED' }` outcome — is left
|
|
1255
|
+
* alone rather than guessed at, for the same reason `settledRecordId` is strict: a partial
|
|
1256
|
+
* record must not be able to look like a rename.
|
|
1237
1257
|
*
|
|
1238
1258
|
* @param doctype - The doctype
|
|
1239
1259
|
* @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
|
|
@@ -1246,7 +1266,15 @@ class F {
|
|
|
1246
1266
|
throw new Error(
|
|
1247
1267
|
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before dispatching actions."
|
|
1248
1268
|
);
|
|
1249
|
-
|
|
1269
|
+
const i = await this._client.runAction(e, t, r);
|
|
1270
|
+
if (i.success && i.data && typeof i.data == "object" && !Array.isArray(i.data)) {
|
|
1271
|
+
const n = i.data;
|
|
1272
|
+
if (n[e.recordIdField] !== void 0) {
|
|
1273
|
+
const o = e.getRecordId(n);
|
|
1274
|
+
o !== void 0 && this.addRecord(e, o, n);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return i;
|
|
1250
1278
|
}
|
|
1251
1279
|
/**
|
|
1252
1280
|
* Ensure doctype section exists in HST store
|
|
@@ -1348,7 +1376,7 @@ class F {
|
|
|
1348
1376
|
*/
|
|
1349
1377
|
async fetchNestedData(e, t, r, i) {
|
|
1350
1378
|
if (!this._client)
|
|
1351
|
-
throw
|
|
1379
|
+
throw ye(
|
|
1352
1380
|
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records.",
|
|
1353
1381
|
"CLIENT_REQUIRED"
|
|
1354
1382
|
);
|
|
@@ -1356,7 +1384,7 @@ class F {
|
|
|
1356
1384
|
includeNested: i?.includeNested ?? !0
|
|
1357
1385
|
});
|
|
1358
1386
|
if (!n?.record)
|
|
1359
|
-
throw
|
|
1387
|
+
throw ye(`Record not found: ${t.doctype} ${r}`, "RECORD_NOT_FOUND");
|
|
1360
1388
|
const o = t.slug;
|
|
1361
1389
|
this.ensureDoctypeExists(o), this.hstStore.get(`${o}.${r}`) || this.hstStore.set(`${o}.${r}`, {}, "system");
|
|
1362
1390
|
for (const [c, u] of Object.entries(n.record))
|
|
@@ -1384,69 +1412,15 @@ class F {
|
|
|
1384
1412
|
return i;
|
|
1385
1413
|
}
|
|
1386
1414
|
}
|
|
1387
|
-
function
|
|
1388
|
-
return F._root;
|
|
1389
|
-
}
|
|
1390
|
-
function be(s, e) {
|
|
1415
|
+
function ye(s, e) {
|
|
1391
1416
|
const t = new Error(s);
|
|
1392
1417
|
return t.code = e, t;
|
|
1393
1418
|
}
|
|
1394
|
-
function
|
|
1395
|
-
const r = ee("$stonecrop") || F._root;
|
|
1396
|
-
if (!r)
|
|
1397
|
-
throw new Error("Stonecrop instance not available. Ensure useStonecrop() has been called first.");
|
|
1398
|
-
const i = O(!1), n = O(!1), o = O(null), a = r.getStore(), c = () => `${s.slug || s.doctype}.${e}.${t}`, u = () => s.links?.[t]?.fetch, l = async (m) => {
|
|
1399
|
-
try {
|
|
1400
|
-
return await new Function(
|
|
1401
|
-
"stonecrop",
|
|
1402
|
-
"path",
|
|
1403
|
-
"hst",
|
|
1404
|
-
`
|
|
1405
|
-
return (${m})(stonecrop, path, hst)
|
|
1406
|
-
`
|
|
1407
|
-
)(r, c(), a);
|
|
1408
|
-
} catch (S) {
|
|
1409
|
-
throw new Error(`Custom handler failed: ${S instanceof Error ? S.message : String(S)}`, { cause: S });
|
|
1410
|
-
}
|
|
1411
|
-
}, d = async () => {
|
|
1412
|
-
const m = u(), S = `${s.slug || s.doctype}.${e}`;
|
|
1413
|
-
if (m?.method === "custom") {
|
|
1414
|
-
a.has(S) || a.set(S, {}, "system");
|
|
1415
|
-
const b = await l(m.handler);
|
|
1416
|
-
a.set(c(), b, "system");
|
|
1417
|
-
} else
|
|
1418
|
-
await r.fetchNestedData(S, s, e, { includeNested: [t] });
|
|
1419
|
-
}, w = async () => {
|
|
1420
|
-
if (!i.value) {
|
|
1421
|
-
i.value = !0, o.value = null;
|
|
1422
|
-
try {
|
|
1423
|
-
await d(), n.value = !0;
|
|
1424
|
-
} catch (m) {
|
|
1425
|
-
throw o.value = m instanceof Error ? m : new Error(String(m)), m;
|
|
1426
|
-
} finally {
|
|
1427
|
-
i.value = !1;
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
}, $ = C(() => {
|
|
1431
|
-
if (n.value)
|
|
1432
|
-
return a.get(c());
|
|
1433
|
-
});
|
|
1434
|
-
return {
|
|
1435
|
-
// State
|
|
1436
|
-
loading: i,
|
|
1437
|
-
loaded: n,
|
|
1438
|
-
error: o,
|
|
1439
|
-
// Computed
|
|
1440
|
-
data: $,
|
|
1441
|
-
// Actions
|
|
1442
|
-
reload: w
|
|
1443
|
-
};
|
|
1444
|
-
}
|
|
1445
|
-
function it(s) {
|
|
1419
|
+
function He(s) {
|
|
1446
1420
|
s || (s = {});
|
|
1447
|
-
const e = s.registry || ee("$registry"), t = ee("$stonecrop"), r =
|
|
1448
|
-
|
|
1449
|
-
const S =
|
|
1421
|
+
const e = s.registry || ee("$registry"), t = ee("$stonecrop"), r = E(), i = E(), n = E({}), o = E([]), a = E(!1), c = E(null), u = E(), l = P(() => !r.value || !u.value || !s.recordId || _(s.recordId) ? !0 : r.value.isWorkflowReady(u.value, s.recordId).ready), d = P(() => !r.value || !u.value || !s.recordId || _(s.recordId) ? [] : r.value.isWorkflowReady(u.value, s.recordId).blockedLinks ?? []), v = t || M._root;
|
|
1422
|
+
v && (r.value = v), s?.doctype && typeof s.doctype != "string" && (u.value = s.doctype);
|
|
1423
|
+
const S = E([]), m = E(-1), k = P(() => r.value?.getOperationLogStore().canUndo ?? !1), w = P(() => r.value?.getOperationLogStore().canRedo ?? !1), R = P(() => r.value?.getOperationLogStore().undoCount ?? 0), C = P(() => r.value?.getOperationLogStore().redoCount ?? 0), L = P(
|
|
1450
1424
|
() => r.value?.getOperationLogStore().undoRedoState ?? {
|
|
1451
1425
|
canUndo: !1,
|
|
1452
1426
|
canRedo: !1,
|
|
@@ -1454,231 +1428,184 @@ function it(s) {
|
|
|
1454
1428
|
redoCount: 0,
|
|
1455
1429
|
currentIndex: -1
|
|
1456
1430
|
}
|
|
1457
|
-
),
|
|
1431
|
+
), N = (g) => r.value?.getOperationLogStore().undo(g) ?? !1, $ = (g) => r.value?.getOperationLogStore().redo(g) ?? !1, x = () => {
|
|
1458
1432
|
r.value?.getOperationLogStore().startBatch();
|
|
1459
|
-
},
|
|
1433
|
+
}, T = (g) => r.value?.getOperationLogStore().commitBatch(g) ?? null, z = () => {
|
|
1460
1434
|
r.value?.getOperationLogStore().cancelBatch();
|
|
1461
|
-
},
|
|
1435
|
+
}, V = () => {
|
|
1462
1436
|
r.value?.getOperationLogStore().clear();
|
|
1463
|
-
},
|
|
1437
|
+
}, re = (g, y) => r.value?.getOperationLogStore().getOperationsFor(g, y) ?? [], ne = () => r.value?.getOperationLogStore().getSnapshot() ?? {
|
|
1464
1438
|
operations: [],
|
|
1465
1439
|
currentIndex: -1,
|
|
1466
1440
|
totalOperations: 0,
|
|
1467
1441
|
reversibleOperations: 0,
|
|
1468
1442
|
irreversibleOperations: 0
|
|
1469
|
-
},
|
|
1470
|
-
r.value?.getOperationLogStore().markIrreversible(
|
|
1471
|
-
},
|
|
1472
|
-
r.value?.getOperationLogStore().configure(
|
|
1443
|
+
}, ie = (g, y) => {
|
|
1444
|
+
r.value?.getOperationLogStore().markIrreversible(g, y);
|
|
1445
|
+
}, K = (g, y, b, O = "success", D) => r.value?.getOperationLogStore().logAction(g, y, b, O, D) ?? "", oe = (g) => {
|
|
1446
|
+
r.value?.getOperationLogStore().configure(g);
|
|
1473
1447
|
};
|
|
1474
1448
|
if (e && r.value)
|
|
1475
1449
|
try {
|
|
1476
|
-
const
|
|
1477
|
-
S.value = y.operations.value,
|
|
1450
|
+
const g = r.value.getOperationLogStore(), y = ke(g);
|
|
1451
|
+
S.value = y.operations.value, m.value = y.currentIndex.value, X(
|
|
1478
1452
|
() => y.operations.value,
|
|
1479
|
-
(
|
|
1480
|
-
S.value =
|
|
1453
|
+
(b) => {
|
|
1454
|
+
S.value = b;
|
|
1481
1455
|
}
|
|
1482
1456
|
), X(
|
|
1483
1457
|
() => y.currentIndex.value,
|
|
1484
|
-
(
|
|
1485
|
-
|
|
1458
|
+
(b) => {
|
|
1459
|
+
m.value = b;
|
|
1486
1460
|
}
|
|
1487
1461
|
);
|
|
1488
1462
|
} catch {
|
|
1489
1463
|
}
|
|
1490
|
-
s.doctype && typeof s.doctype != "string" && e && r.value && (i.value = r.value.getStore(),
|
|
1491
|
-
if (!(!e || !r.value)) {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
if (B)
|
|
1505
|
-
n.value = B.get("") || {};
|
|
1506
|
-
else
|
|
1507
|
-
try {
|
|
1508
|
-
await r.value.getRecord(R, v);
|
|
1509
|
-
const z = r.value.getRecordById(R, v);
|
|
1510
|
-
z && (n.value = z.get("") || {});
|
|
1511
|
-
} catch {
|
|
1512
|
-
n.value = e.initializeRecord(c.value);
|
|
1513
|
-
}
|
|
1514
|
-
} else
|
|
1515
|
-
n.value = e.initializeRecord(c.value);
|
|
1516
|
-
i.value && de(R, v || "new", n, i.value), r.value.runAction(R, "load", v ? [v] : void 0);
|
|
1464
|
+
s.doctype && typeof s.doctype != "string" && e && r.value && (i.value = r.value.getStore(), o.value = e.resolveSchema(s.doctype), (!s.recordId || _(s.recordId)) && (n.value = e.initializeRecord(o.value)), i.value && we(s.doctype, s.recordId || "new", n, i.value)), Ce(async () => {
|
|
1465
|
+
if (!(!e || !r.value) && s.doctype) {
|
|
1466
|
+
const g = s.recordId;
|
|
1467
|
+
if (typeof s.doctype == "string") {
|
|
1468
|
+
const y = s.doctype;
|
|
1469
|
+
i.value = r.value.getStore(), a.value = !0, c.value = null;
|
|
1470
|
+
let b;
|
|
1471
|
+
try {
|
|
1472
|
+
if (b = e.getDoctype(y), !b && e.getMeta) {
|
|
1473
|
+
const O = {
|
|
1474
|
+
path: `/${y}`,
|
|
1475
|
+
segments: [y]
|
|
1476
|
+
};
|
|
1477
|
+
b = await e.getMeta(O), b && e.addDoctype(b);
|
|
1517
1478
|
}
|
|
1479
|
+
b || (c.value = new Error(`Doctype '${y}' not found in registry and getMeta returned no result`));
|
|
1480
|
+
} catch (O) {
|
|
1481
|
+
c.value = O instanceof Error ? O : new Error(String(O));
|
|
1482
|
+
} finally {
|
|
1483
|
+
a.value = !1;
|
|
1518
1484
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
i.value = r.value.getStore(), u.value = !0, l.value = null;
|
|
1525
|
-
let v;
|
|
1526
|
-
try {
|
|
1527
|
-
if (v = e.getDoctype(y), !v && e.getMeta) {
|
|
1528
|
-
const k = {
|
|
1529
|
-
path: `/${y}`,
|
|
1530
|
-
segments: [y]
|
|
1531
|
-
};
|
|
1532
|
-
v = await e.getMeta(k), v && e.addDoctype(v);
|
|
1533
|
-
}
|
|
1534
|
-
v || (l.value = new Error(`Doctype '${y}' not found in registry and getMeta returned no result`));
|
|
1535
|
-
} catch (k) {
|
|
1536
|
-
l.value = k instanceof Error ? k : new Error(String(k));
|
|
1537
|
-
} finally {
|
|
1538
|
-
u.value = !1;
|
|
1539
|
-
}
|
|
1540
|
-
if (d.value = v, !v) return;
|
|
1541
|
-
if (c.value = e.resolveSchema(v), p && p !== "new") {
|
|
1542
|
-
const k = r.value.getRecordById(v, p);
|
|
1543
|
-
if (k)
|
|
1544
|
-
n.value = k.get("") || {};
|
|
1545
|
-
else
|
|
1546
|
-
try {
|
|
1547
|
-
await r.value.getRecord(v, p);
|
|
1548
|
-
const R = r.value.getRecordById(v, p);
|
|
1549
|
-
R && (n.value = R.get("") || {});
|
|
1550
|
-
} catch {
|
|
1551
|
-
n.value = e.initializeRecord(c.value);
|
|
1552
|
-
}
|
|
1553
|
-
} else
|
|
1554
|
-
n.value = e.initializeRecord(c.value);
|
|
1555
|
-
i.value && de(v, p || "new", n, i.value);
|
|
1556
|
-
} else if (p && p !== "new") {
|
|
1557
|
-
const y = s.doctype, v = r.value.getRecordById(y, p);
|
|
1558
|
-
if (v)
|
|
1559
|
-
n.value = v.get("") || {};
|
|
1485
|
+
if (u.value = b, !b) return;
|
|
1486
|
+
if (o.value = e.resolveSchema(b), g && !_(g)) {
|
|
1487
|
+
const O = r.value.getRecordById(b, g);
|
|
1488
|
+
if (O)
|
|
1489
|
+
n.value = O.get("") || {};
|
|
1560
1490
|
else
|
|
1561
1491
|
try {
|
|
1562
|
-
await r.value.getRecord(
|
|
1563
|
-
const
|
|
1564
|
-
|
|
1492
|
+
await r.value.getRecord(b, g);
|
|
1493
|
+
const D = r.value.getRecordById(b, g);
|
|
1494
|
+
D && (n.value = D.get("") || {});
|
|
1565
1495
|
} catch {
|
|
1566
|
-
n.value = e.initializeRecord(
|
|
1496
|
+
n.value = e.initializeRecord(o.value);
|
|
1567
1497
|
}
|
|
1568
|
-
}
|
|
1498
|
+
} else
|
|
1499
|
+
n.value = e.initializeRecord(o.value);
|
|
1500
|
+
i.value && we(b, g || "new", n, i.value);
|
|
1501
|
+
} else if (g && !_(g)) {
|
|
1502
|
+
const y = s.doctype, b = r.value.getRecordById(y, g);
|
|
1503
|
+
if (b)
|
|
1504
|
+
n.value = b.get("") || {};
|
|
1505
|
+
else
|
|
1506
|
+
try {
|
|
1507
|
+
await r.value.getRecord(y, g);
|
|
1508
|
+
const O = r.value.getRecordById(y, g);
|
|
1509
|
+
O && (n.value = O.get("") || {});
|
|
1510
|
+
} catch {
|
|
1511
|
+
n.value = e.initializeRecord(o.value);
|
|
1512
|
+
}
|
|
1569
1513
|
}
|
|
1570
1514
|
}
|
|
1571
1515
|
});
|
|
1572
|
-
const
|
|
1573
|
-
const
|
|
1574
|
-
if (!
|
|
1575
|
-
const
|
|
1576
|
-
return `${
|
|
1577
|
-
},
|
|
1578
|
-
const y =
|
|
1516
|
+
const Z = (g, y) => {
|
|
1517
|
+
const b = u.value;
|
|
1518
|
+
if (!b) return "";
|
|
1519
|
+
const O = y || s.recordId || "new";
|
|
1520
|
+
return `${b.slug}.${O}.${g}`;
|
|
1521
|
+
}, H = (g) => {
|
|
1522
|
+
const y = u.value;
|
|
1579
1523
|
if (!(!i.value || !r.value || !y))
|
|
1580
1524
|
try {
|
|
1581
|
-
const
|
|
1582
|
-
if (
|
|
1583
|
-
const
|
|
1584
|
-
if (i.value.has(`${
|
|
1585
|
-
const
|
|
1586
|
-
let
|
|
1587
|
-
for (let Q = 0; Q <
|
|
1588
|
-
if (
|
|
1589
|
-
const
|
|
1590
|
-
i.value.set(
|
|
1525
|
+
const b = g.path.split(".");
|
|
1526
|
+
if (b.length >= 2) {
|
|
1527
|
+
const J = b[0], se = b[1];
|
|
1528
|
+
if (i.value.has(`${J}.${se}`) || r.value.addRecord(y, se, { ...n.value }), b.length > 3) {
|
|
1529
|
+
const Ie = `${J}.${se}`, ae = b.slice(2);
|
|
1530
|
+
let ce = Ie;
|
|
1531
|
+
for (let Q = 0; Q < ae.length - 1; Q++)
|
|
1532
|
+
if (ce += `.${ae[Q]}`, !i.value.has(ce)) {
|
|
1533
|
+
const Ae = ae[Q + 1], Ee = !isNaN(Number(Ae));
|
|
1534
|
+
i.value.set(ce, Ee ? [] : {});
|
|
1591
1535
|
}
|
|
1592
1536
|
}
|
|
1593
1537
|
}
|
|
1594
|
-
i.value.set(
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1538
|
+
i.value.set(g.path, g.value);
|
|
1539
|
+
const O = g.fieldname.split("."), D = { ...n.value };
|
|
1540
|
+
O.length === 1 ? D[O[0]] = g.value : qe(D, O, g.value), n.value = D;
|
|
1597
1541
|
} catch {
|
|
1598
1542
|
}
|
|
1599
1543
|
};
|
|
1600
|
-
|
|
1601
|
-
const
|
|
1544
|
+
s.doctype && (de("hstPathProvider", Z), de("hstChangeHandler", H));
|
|
1545
|
+
const h = (g, y) => {
|
|
1602
1546
|
if (!r.value)
|
|
1603
1547
|
throw new Error("Stonecrop instance not available");
|
|
1604
|
-
return r.value.initializeNestedData(
|
|
1605
|
-
},
|
|
1548
|
+
return r.value.initializeNestedData(g, y);
|
|
1549
|
+
}, p = async (g, y, b, O) => {
|
|
1606
1550
|
if (!r.value)
|
|
1607
1551
|
throw new Error("Stonecrop instance not available");
|
|
1608
|
-
return r.value.fetchNestedData(
|
|
1609
|
-
},
|
|
1552
|
+
return r.value.fetchNestedData(g, y, b, O);
|
|
1553
|
+
}, f = (g, y) => {
|
|
1610
1554
|
if (!r.value)
|
|
1611
1555
|
throw new Error("Stonecrop instance not available");
|
|
1612
|
-
return r.value.collectRecordPayload(
|
|
1613
|
-
},
|
|
1614
|
-
provideHSTPath: (
|
|
1615
|
-
handleHSTChange: (
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
...
|
|
1619
|
-
path:
|
|
1556
|
+
return r.value.collectRecordPayload(g, y);
|
|
1557
|
+
}, I = (g, y) => ({
|
|
1558
|
+
provideHSTPath: (D) => `${g}.${D}`,
|
|
1559
|
+
handleHSTChange: (D) => {
|
|
1560
|
+
const J = D.path.startsWith(g) ? D.path : `${g}.${D.fieldname}`;
|
|
1561
|
+
H({
|
|
1562
|
+
...D,
|
|
1563
|
+
path: J
|
|
1620
1564
|
});
|
|
1621
1565
|
}
|
|
1622
|
-
}),
|
|
1566
|
+
}), F = {
|
|
1623
1567
|
operations: S,
|
|
1624
|
-
currentIndex:
|
|
1625
|
-
undoRedoState:
|
|
1626
|
-
canUndo:
|
|
1627
|
-
canRedo:
|
|
1628
|
-
undoCount:
|
|
1629
|
-
redoCount:
|
|
1630
|
-
undo:
|
|
1631
|
-
redo:
|
|
1632
|
-
startBatch:
|
|
1633
|
-
commitBatch:
|
|
1634
|
-
cancelBatch:
|
|
1635
|
-
clear:
|
|
1636
|
-
getOperationsFor:
|
|
1637
|
-
getSnapshot:
|
|
1638
|
-
markIrreversible:
|
|
1639
|
-
logAction:
|
|
1640
|
-
configure:
|
|
1568
|
+
currentIndex: m,
|
|
1569
|
+
undoRedoState: L,
|
|
1570
|
+
canUndo: k,
|
|
1571
|
+
canRedo: w,
|
|
1572
|
+
undoCount: R,
|
|
1573
|
+
redoCount: C,
|
|
1574
|
+
undo: N,
|
|
1575
|
+
redo: $,
|
|
1576
|
+
startBatch: x,
|
|
1577
|
+
commitBatch: T,
|
|
1578
|
+
cancelBatch: z,
|
|
1579
|
+
clear: V,
|
|
1580
|
+
getOperationsFor: re,
|
|
1581
|
+
getSnapshot: ne,
|
|
1582
|
+
markIrreversible: ie,
|
|
1583
|
+
logAction: K,
|
|
1584
|
+
configure: oe
|
|
1641
1585
|
};
|
|
1642
1586
|
return s.doctype ? {
|
|
1643
1587
|
stonecrop: r,
|
|
1644
|
-
operationLog:
|
|
1645
|
-
provideHSTPath:
|
|
1646
|
-
handleHSTChange:
|
|
1588
|
+
operationLog: F,
|
|
1589
|
+
provideHSTPath: Z,
|
|
1590
|
+
handleHSTChange: H,
|
|
1647
1591
|
hstStore: i,
|
|
1648
1592
|
formData: n,
|
|
1649
|
-
resolvedSchema:
|
|
1650
|
-
initializeNestedData:
|
|
1651
|
-
fetchNestedData:
|
|
1652
|
-
collectRecordPayload:
|
|
1653
|
-
createNestedContext:
|
|
1654
|
-
isLoading:
|
|
1655
|
-
error:
|
|
1656
|
-
resolvedDoctype:
|
|
1657
|
-
isWorkflowReady:
|
|
1658
|
-
blockedLinks:
|
|
1659
|
-
} : !s.doctype && e?.router ? {
|
|
1660
|
-
stonecrop: r,
|
|
1661
|
-
operationLog: N,
|
|
1662
|
-
provideHSTPath: g,
|
|
1663
|
-
handleHSTChange: h,
|
|
1664
|
-
hstStore: i,
|
|
1665
|
-
formData: n,
|
|
1666
|
-
resolvedSchema: c,
|
|
1667
|
-
initializeNestedData: f,
|
|
1668
|
-
fetchNestedData: A,
|
|
1669
|
-
collectRecordPayload: P,
|
|
1670
|
-
createNestedContext: L,
|
|
1671
|
-
isLoading: u,
|
|
1672
|
-
error: l,
|
|
1673
|
-
resolvedDoctype: d,
|
|
1674
|
-
isWorkflowReady: w,
|
|
1675
|
-
blockedLinks: $
|
|
1593
|
+
resolvedSchema: o,
|
|
1594
|
+
initializeNestedData: h,
|
|
1595
|
+
fetchNestedData: p,
|
|
1596
|
+
collectRecordPayload: f,
|
|
1597
|
+
createNestedContext: I,
|
|
1598
|
+
isLoading: a,
|
|
1599
|
+
error: c,
|
|
1600
|
+
resolvedDoctype: u,
|
|
1601
|
+
isWorkflowReady: l,
|
|
1602
|
+
blockedLinks: d
|
|
1676
1603
|
} : {
|
|
1677
1604
|
stonecrop: r,
|
|
1678
|
-
operationLog:
|
|
1605
|
+
operationLog: F
|
|
1679
1606
|
};
|
|
1680
1607
|
}
|
|
1681
|
-
function
|
|
1608
|
+
function we(s, e, t, r) {
|
|
1682
1609
|
X(
|
|
1683
1610
|
t,
|
|
1684
1611
|
(i) => {
|
|
@@ -1694,7 +1621,7 @@ function de(s, e, t, r) {
|
|
|
1694
1621
|
{ deep: !0 }
|
|
1695
1622
|
);
|
|
1696
1623
|
}
|
|
1697
|
-
function
|
|
1624
|
+
function qe(s, e, t) {
|
|
1698
1625
|
let r = s;
|
|
1699
1626
|
for (let n = 0; n < e.length - 1; n++) {
|
|
1700
1627
|
const o = e[n];
|
|
@@ -1703,42 +1630,157 @@ function Ve(s, e, t) {
|
|
|
1703
1630
|
const i = e[e.length - 1];
|
|
1704
1631
|
r[i] = t;
|
|
1705
1632
|
}
|
|
1633
|
+
function Ue(s, e) {
|
|
1634
|
+
if (e[s.recordIdField] !== void 0)
|
|
1635
|
+
return s.getRecordId(e);
|
|
1636
|
+
}
|
|
1637
|
+
function je(s) {
|
|
1638
|
+
console.error("Action failed:", s.message), typeof window < "u" && window.alert(s.message);
|
|
1639
|
+
}
|
|
1640
|
+
function at(s = {}) {
|
|
1641
|
+
const { stonecrop: e } = He(), t = Te(), r = s.onError ?? je, i = () => t ?? e.value?.registry.router, n = s.buildArgs ?? // Spreading `undefined` in an object literal adds nothing, so `extra` needs no fallback.
|
|
1642
|
+
(({ recordId: u, isDraft: l, data: d, extra: v }) => [{ ...l ? {} : { id: u }, data: d, ...v }]), o = s.followRecord ?? (async ({ doctype: u, recordId: l }) => {
|
|
1643
|
+
await i()?.replace(`/${u}/${l}`);
|
|
1644
|
+
});
|
|
1645
|
+
async function a(u, l, d, v, S) {
|
|
1646
|
+
const m = e.value;
|
|
1647
|
+
if (!m) return { success: !1, data: null, error: "Stonecrop is not initialized" };
|
|
1648
|
+
const k = m.registry.getDoctype(u);
|
|
1649
|
+
if (!k) return { success: !1, data: null, error: `Unknown doctype: ${u}` };
|
|
1650
|
+
const w = _(l), R = await m.dispatchAction(
|
|
1651
|
+
k,
|
|
1652
|
+
v,
|
|
1653
|
+
n({ doctype: u, action: v, recordId: l, isDraft: w, data: d, extra: S })
|
|
1654
|
+
);
|
|
1655
|
+
if (R.success && R.data) {
|
|
1656
|
+
const C = R.data, L = Ue(k, C);
|
|
1657
|
+
if (L === void 0)
|
|
1658
|
+
return w || m.addRecord(u, l, C), R;
|
|
1659
|
+
l !== L && (m.removeRecord(u, l), await o({ doctype: u, recordId: L, previousRecordId: l }));
|
|
1660
|
+
}
|
|
1661
|
+
return R;
|
|
1662
|
+
}
|
|
1663
|
+
async function c(u) {
|
|
1664
|
+
const l = e.value;
|
|
1665
|
+
if (!l) return;
|
|
1666
|
+
const { name: d, doctype: v, recordId: S, data: m } = u, R = l.registry.getDoctype(v)?.workflow?.actions?.[d]?.clientHandler;
|
|
1667
|
+
try {
|
|
1668
|
+
if (!R) {
|
|
1669
|
+
const $ = await a(v, S, m, d);
|
|
1670
|
+
$.success || r({
|
|
1671
|
+
message: $.error ?? `Action "${d}" failed`,
|
|
1672
|
+
action: d,
|
|
1673
|
+
doctype: v,
|
|
1674
|
+
recordId: S
|
|
1675
|
+
});
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
const C = l.getRecordById(v, S)?.get("") ?? m, L = ($, x) => a(v, S, m, $, x), N = {
|
|
1679
|
+
query($, x) {
|
|
1680
|
+
const T = l.getClient();
|
|
1681
|
+
return T?.query ? T.query($, x) : Promise.reject(new Error("The configured data client does not support graphql.query"));
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
await Re(R, { router: i(), record: C, runAction: L, graphql: N });
|
|
1685
|
+
} catch (C) {
|
|
1686
|
+
r({
|
|
1687
|
+
message: C instanceof Error ? C.message : String(C),
|
|
1688
|
+
action: d,
|
|
1689
|
+
doctype: v,
|
|
1690
|
+
recordId: S,
|
|
1691
|
+
cause: C
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
return { run: c };
|
|
1696
|
+
}
|
|
1697
|
+
function ct(s, e, t) {
|
|
1698
|
+
const r = ee("$stonecrop") || M._root;
|
|
1699
|
+
if (!r)
|
|
1700
|
+
throw new Error("Stonecrop instance not available. Ensure useStonecrop() has been called first.");
|
|
1701
|
+
const i = E(!1), n = E(!1), o = E(null), a = r.getStore(), c = () => `${s.slug || s.doctype}.${e}.${t}`, u = () => s.links?.[t]?.fetch, l = async (m) => {
|
|
1702
|
+
try {
|
|
1703
|
+
return await new Function(
|
|
1704
|
+
"stonecrop",
|
|
1705
|
+
"path",
|
|
1706
|
+
"hst",
|
|
1707
|
+
`
|
|
1708
|
+
return (${m})(stonecrop, path, hst)
|
|
1709
|
+
`
|
|
1710
|
+
)(r, c(), a);
|
|
1711
|
+
} catch (k) {
|
|
1712
|
+
throw new Error(`Custom handler failed: ${k instanceof Error ? k.message : String(k)}`, { cause: k });
|
|
1713
|
+
}
|
|
1714
|
+
}, d = async () => {
|
|
1715
|
+
const m = u(), k = `${s.slug || s.doctype}.${e}`;
|
|
1716
|
+
if (m?.method === "custom") {
|
|
1717
|
+
a.has(k) || a.set(k, {}, "system");
|
|
1718
|
+
const w = await l(m.handler);
|
|
1719
|
+
a.set(c(), w, "system");
|
|
1720
|
+
} else
|
|
1721
|
+
await r.fetchNestedData(k, s, e, { includeNested: [t] });
|
|
1722
|
+
}, v = async () => {
|
|
1723
|
+
if (!i.value) {
|
|
1724
|
+
i.value = !0, o.value = null;
|
|
1725
|
+
try {
|
|
1726
|
+
await d(), n.value = !0;
|
|
1727
|
+
} catch (m) {
|
|
1728
|
+
throw o.value = m instanceof Error ? m : new Error(String(m)), m;
|
|
1729
|
+
} finally {
|
|
1730
|
+
i.value = !1;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}, S = P(() => {
|
|
1734
|
+
if (n.value)
|
|
1735
|
+
return a.get(c());
|
|
1736
|
+
});
|
|
1737
|
+
return {
|
|
1738
|
+
// State
|
|
1739
|
+
loading: i,
|
|
1740
|
+
loaded: n,
|
|
1741
|
+
error: o,
|
|
1742
|
+
// Computed
|
|
1743
|
+
data: S,
|
|
1744
|
+
// Actions
|
|
1745
|
+
reload: v
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1706
1748
|
function $e(s) {
|
|
1707
|
-
const t = (De() ? ee("$operationLogStore", void 0) : void 0) ||
|
|
1749
|
+
const t = (De() ? ee("$operationLogStore", void 0) : void 0) || G();
|
|
1708
1750
|
s && t.configure(s);
|
|
1709
1751
|
const { operations: r, currentIndex: i, undoRedoState: n, canUndo: o, canRedo: a, undoCount: c, redoCount: u } = ke(t);
|
|
1710
|
-
function l(
|
|
1711
|
-
return t.undo(
|
|
1752
|
+
function l($) {
|
|
1753
|
+
return t.undo($);
|
|
1712
1754
|
}
|
|
1713
|
-
function d(
|
|
1714
|
-
return t.redo(
|
|
1755
|
+
function d($) {
|
|
1756
|
+
return t.redo($);
|
|
1715
1757
|
}
|
|
1716
|
-
function
|
|
1758
|
+
function v() {
|
|
1717
1759
|
t.startBatch();
|
|
1718
1760
|
}
|
|
1719
|
-
function $
|
|
1720
|
-
return t.commitBatch(
|
|
1761
|
+
function S($) {
|
|
1762
|
+
return t.commitBatch($);
|
|
1721
1763
|
}
|
|
1722
1764
|
function m() {
|
|
1723
1765
|
t.cancelBatch();
|
|
1724
1766
|
}
|
|
1725
|
-
function
|
|
1767
|
+
function k() {
|
|
1726
1768
|
t.clear();
|
|
1727
1769
|
}
|
|
1728
|
-
function
|
|
1729
|
-
return t.getOperationsFor(
|
|
1770
|
+
function w($, x) {
|
|
1771
|
+
return t.getOperationsFor($, x);
|
|
1730
1772
|
}
|
|
1731
|
-
function
|
|
1773
|
+
function R() {
|
|
1732
1774
|
return t.getSnapshot();
|
|
1733
1775
|
}
|
|
1734
|
-
function
|
|
1735
|
-
t.markIrreversible(
|
|
1776
|
+
function C($, x) {
|
|
1777
|
+
t.markIrreversible($, x);
|
|
1736
1778
|
}
|
|
1737
|
-
function
|
|
1738
|
-
return t.logAction(
|
|
1779
|
+
function L($, x, T, z = "success", V) {
|
|
1780
|
+
return t.logAction($, x, T, z, V);
|
|
1739
1781
|
}
|
|
1740
|
-
function
|
|
1741
|
-
t.configure(
|
|
1782
|
+
function N($) {
|
|
1783
|
+
t.configure($);
|
|
1742
1784
|
}
|
|
1743
1785
|
return {
|
|
1744
1786
|
// State
|
|
@@ -1752,18 +1794,18 @@ function $e(s) {
|
|
|
1752
1794
|
// Methods
|
|
1753
1795
|
undo: l,
|
|
1754
1796
|
redo: d,
|
|
1755
|
-
startBatch:
|
|
1756
|
-
commitBatch:
|
|
1797
|
+
startBatch: v,
|
|
1798
|
+
commitBatch: S,
|
|
1757
1799
|
cancelBatch: m,
|
|
1758
|
-
clear:
|
|
1759
|
-
getOperationsFor:
|
|
1760
|
-
getSnapshot:
|
|
1761
|
-
markIrreversible:
|
|
1762
|
-
logAction:
|
|
1763
|
-
configure:
|
|
1800
|
+
clear: k,
|
|
1801
|
+
getOperationsFor: w,
|
|
1802
|
+
getSnapshot: R,
|
|
1803
|
+
markIrreversible: C,
|
|
1804
|
+
logAction: L,
|
|
1805
|
+
configure: N
|
|
1764
1806
|
};
|
|
1765
1807
|
}
|
|
1766
|
-
function
|
|
1808
|
+
function lt(s, e = !0) {
|
|
1767
1809
|
if (!e) return;
|
|
1768
1810
|
const { undo: t, redo: r, canUndo: i, canRedo: n } = $e(), o = xe();
|
|
1769
1811
|
q(o["Ctrl+Z"], () => {
|
|
@@ -1778,7 +1820,7 @@ function ot(s, e = !0) {
|
|
|
1778
1820
|
n.value && r(s);
|
|
1779
1821
|
});
|
|
1780
1822
|
}
|
|
1781
|
-
async function
|
|
1823
|
+
async function ut(s, e) {
|
|
1782
1824
|
const { startBatch: t, commitBatch: r, cancelBatch: i } = $e();
|
|
1783
1825
|
t();
|
|
1784
1826
|
try {
|
|
@@ -1814,12 +1856,6 @@ class Oe {
|
|
|
1814
1856
|
* @readonly
|
|
1815
1857
|
*/
|
|
1816
1858
|
workflow;
|
|
1817
|
-
/**
|
|
1818
|
-
* The doctype actions and field triggers
|
|
1819
|
-
* @public
|
|
1820
|
-
* @readonly
|
|
1821
|
-
*/
|
|
1822
|
-
actions;
|
|
1823
1859
|
/**
|
|
1824
1860
|
* The doctype component
|
|
1825
1861
|
* @public
|
|
@@ -1837,12 +1873,11 @@ class Oe {
|
|
|
1837
1873
|
* @param doctype - The doctype name
|
|
1838
1874
|
* @param schema - The doctype schema definition
|
|
1839
1875
|
* @param workflow - The doctype workflow configuration (XState machine)
|
|
1840
|
-
* @param actions - The doctype actions and field triggers
|
|
1841
1876
|
* @param component - Optional Vue component for rendering the doctype
|
|
1842
1877
|
* @param links - Optional relationship links to other doctypes
|
|
1843
1878
|
*/
|
|
1844
|
-
constructor(e, t, r, i, n
|
|
1845
|
-
this.doctype = e, this.schema = t, this.workflow = r, this.
|
|
1879
|
+
constructor(e, t, r, i, n) {
|
|
1880
|
+
this.doctype = e, this.schema = t, this.workflow = r, this.component = i, this.links = n;
|
|
1846
1881
|
}
|
|
1847
1882
|
/**
|
|
1848
1883
|
* Creates a Doctype instance from a plain configuration object.
|
|
@@ -1883,8 +1918,8 @@ class Oe {
|
|
|
1883
1918
|
* @public
|
|
1884
1919
|
*/
|
|
1885
1920
|
static fromObject(e) {
|
|
1886
|
-
const t = e.fields?.map(
|
|
1887
|
-
return new Oe(e.name, r, e.workflow,
|
|
1921
|
+
const t = e.fields?.map(Fe), r = t ? he(t) : he();
|
|
1922
|
+
return new Oe(e.name, r, e.workflow, void 0, e.links);
|
|
1888
1923
|
}
|
|
1889
1924
|
/**
|
|
1890
1925
|
* Returns the raw authoring schema as a plain array.
|
|
@@ -1920,15 +1955,25 @@ class Oe {
|
|
|
1920
1955
|
return _e(this.getSchemaArray(), e);
|
|
1921
1956
|
}
|
|
1922
1957
|
/**
|
|
1923
|
-
*
|
|
1924
|
-
*
|
|
1958
|
+
* The field a record of this doctype is identified by: the declared `primaryKey`, or `id`
|
|
1959
|
+
* when nothing is declared.
|
|
1960
|
+
*
|
|
1961
|
+
* The client-side twin of the adapters' `recordLookupField`. Both are the same call to
|
|
1962
|
+
* `@stonecrop/schema`'s `getRecordIdField`, so the field a caller reads an identity out of is
|
|
1963
|
+
* the same field the adapter builds its lookup predicate on.
|
|
1925
1964
|
*
|
|
1926
|
-
*
|
|
1965
|
+
* Use this to ask whether a record *states* its own identity. `getRecordId` deliberately
|
|
1966
|
+
* falls back to `id` when the declared key is missing, which is right for resolving a link
|
|
1967
|
+
* from a record already in hand and wrong for deciding whether a server response settled on
|
|
1968
|
+
* a new identity: a response that omits a natural key would resolve through that fallback to
|
|
1969
|
+
* a surrogate the adapter cannot look up.
|
|
1970
|
+
*
|
|
1971
|
+
* @returns The identifying fieldname
|
|
1927
1972
|
*
|
|
1928
1973
|
* @public
|
|
1929
1974
|
*/
|
|
1930
|
-
|
|
1931
|
-
return this.
|
|
1975
|
+
get recordIdField() {
|
|
1976
|
+
return Ne(this.getSchemaArray());
|
|
1932
1977
|
}
|
|
1933
1978
|
/**
|
|
1934
1979
|
* Returns the transitions available from a given workflow state, derived from the
|
|
@@ -1951,7 +1996,7 @@ class Oe {
|
|
|
1951
1996
|
if (Array.isArray(t.states)) {
|
|
1952
1997
|
if (!t.states.includes(e)) return [];
|
|
1953
1998
|
const o = t.actions;
|
|
1954
|
-
return o ? Object.entries(o).filter(([, a]) => !a.stateless &&
|
|
1999
|
+
return o ? Object.entries(o).filter(([, a]) => !a.stateless && fe(a, e)).map(([a, c]) => ({
|
|
1955
2000
|
name: a,
|
|
1956
2001
|
targetState: c.nextState ?? e
|
|
1957
2002
|
})) : [];
|
|
@@ -1987,7 +2032,7 @@ class Oe {
|
|
|
1987
2032
|
const t = this.workflow;
|
|
1988
2033
|
if (!t) return [];
|
|
1989
2034
|
const r = t.actions;
|
|
1990
|
-
return r ? Object.entries(r).filter(([, i]) => i.stateless === !0 &&
|
|
2035
|
+
return r ? Object.entries(r).filter(([, i]) => i.stateless === !0 && fe(i, e ?? "")).map(([i]) => ({ name: i })) : [];
|
|
1991
2036
|
}
|
|
1992
2037
|
/**
|
|
1993
2038
|
* Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
|
|
@@ -2048,7 +2093,7 @@ class Oe {
|
|
|
2048
2093
|
return this.doctype.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
2049
2094
|
}
|
|
2050
2095
|
}
|
|
2051
|
-
class
|
|
2096
|
+
class j {
|
|
2052
2097
|
/**
|
|
2053
2098
|
* The root Registry instance
|
|
2054
2099
|
*/
|
|
@@ -2093,7 +2138,7 @@ class K {
|
|
|
2093
2138
|
* @param getMeta - Optional function to fetch doctype metadata from an API
|
|
2094
2139
|
*/
|
|
2095
2140
|
constructor(e, t) {
|
|
2096
|
-
return
|
|
2141
|
+
return j._root ? j._root : (j._root = this, this.router = e, this.getMeta = t, this);
|
|
2097
2142
|
}
|
|
2098
2143
|
/**
|
|
2099
2144
|
* The getMeta function fetches doctype metadata from an API based on route context
|
|
@@ -2107,9 +2152,7 @@ class K {
|
|
|
2107
2152
|
* @see {@link Doctype}
|
|
2108
2153
|
*/
|
|
2109
2154
|
addDoctype(e) {
|
|
2110
|
-
e.slug in this.registry || (this.registry[e.slug] = e, this._ancestorIndexDirty = !0)
|
|
2111
|
-
const t = _();
|
|
2112
|
-
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({
|
|
2155
|
+
e.slug in this.registry || (this.registry[e.slug] = e, this._ancestorIndexDirty = !0), e.component && this.router && !this.router.hasRoute(e.doctype) && this.router.addRoute({
|
|
2113
2156
|
path: `/${e.slug}`,
|
|
2114
2157
|
name: e.slug,
|
|
2115
2158
|
component: e.component
|
|
@@ -2157,33 +2200,33 @@ class K {
|
|
|
2157
2200
|
const o = n.kind === "field" ? t.get(n.fieldname) : void 0;
|
|
2158
2201
|
if (n.kind === "field" && (o || n.doctype)) {
|
|
2159
2202
|
const a = o, c = a?.target ?? n.doctype;
|
|
2160
|
-
if (!a ||
|
|
2161
|
-
const { cardinality:
|
|
2203
|
+
if (!a || ge(a, n.component) === "inline") {
|
|
2204
|
+
const { cardinality: k, ...w } = n;
|
|
2162
2205
|
i.push({
|
|
2163
|
-
...
|
|
2164
|
-
component:
|
|
2206
|
+
...w,
|
|
2207
|
+
component: w.component || "AFormLink",
|
|
2165
2208
|
...c !== void 0 ? { doctype: c } : {}
|
|
2166
2209
|
});
|
|
2167
2210
|
continue;
|
|
2168
2211
|
}
|
|
2169
2212
|
const u = this.registry[a.target];
|
|
2170
2213
|
if (!u) {
|
|
2171
|
-
const { cardinality:
|
|
2172
|
-
i.push({ ...
|
|
2214
|
+
const { cardinality: k, ...w } = n;
|
|
2215
|
+
i.push({ ...w });
|
|
2173
2216
|
continue;
|
|
2174
2217
|
}
|
|
2175
|
-
const l = this.resolveSchema(u, new Set(r)), { options: d, cardinality:
|
|
2176
|
-
if (
|
|
2218
|
+
const l = this.resolveSchema(u, new Set(r)), { options: d, cardinality: v, kind: S, ...m } = n;
|
|
2219
|
+
if (ge(a, n.component) === "table")
|
|
2177
2220
|
i.push(this.buildTableConfig(n, l, a.component));
|
|
2178
2221
|
else {
|
|
2179
|
-
const
|
|
2222
|
+
const k = {
|
|
2180
2223
|
...m,
|
|
2181
2224
|
kind: "link",
|
|
2182
2225
|
label: m.label || n.fieldname,
|
|
2183
2226
|
component: a.component || m.component || "AForm",
|
|
2184
2227
|
schema: l
|
|
2185
2228
|
};
|
|
2186
|
-
i.push(
|
|
2229
|
+
i.push(k);
|
|
2187
2230
|
}
|
|
2188
2231
|
} else if (n.kind === "fieldset") {
|
|
2189
2232
|
const a = this.resolveFields(n.schema, t, r), { schema: c, ...u } = n, l = {
|
|
@@ -2201,7 +2244,7 @@ class K {
|
|
|
2201
2244
|
};
|
|
2202
2245
|
i.push(l);
|
|
2203
2246
|
} else {
|
|
2204
|
-
n.kind === "field" &&
|
|
2247
|
+
n.kind === "field" && Se(n.component) && console.warn(
|
|
2205
2248
|
`[Stonecrop] Field "${n.fieldname}" renders with "${n.component}", which is a link component, but the field is not a link: it has no \`doctype\` and no \`links\` declaration. It will render as a plain field. Add \`"doctype": "<doctype-slug>"\` to the field definition.`
|
|
2206
2249
|
);
|
|
2207
2250
|
const { cardinality: a, ...c } = n;
|
|
@@ -2252,7 +2295,7 @@ class K {
|
|
|
2252
2295
|
if (i !== void 0)
|
|
2253
2296
|
t[r.fieldname] = i;
|
|
2254
2297
|
else {
|
|
2255
|
-
const n =
|
|
2298
|
+
const n = Me(r.component);
|
|
2256
2299
|
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;
|
|
2257
2300
|
}
|
|
2258
2301
|
}
|
|
@@ -2349,25 +2392,25 @@ class K {
|
|
|
2349
2392
|
// }
|
|
2350
2393
|
// }
|
|
2351
2394
|
}
|
|
2352
|
-
async function
|
|
2395
|
+
async function Ge(s, e, t) {
|
|
2353
2396
|
await Pe();
|
|
2354
2397
|
try {
|
|
2355
2398
|
await t(s, e);
|
|
2356
2399
|
} catch {
|
|
2357
2400
|
}
|
|
2358
2401
|
}
|
|
2359
|
-
const
|
|
2402
|
+
const dt = {
|
|
2360
2403
|
install: (s, e) => {
|
|
2361
2404
|
const t = s.config.globalProperties.$router, r = e?.router, i = t || r;
|
|
2362
2405
|
!t && r && s.use(r);
|
|
2363
|
-
const n = new
|
|
2406
|
+
const n = new j(i, e?.getMeta);
|
|
2364
2407
|
s.provide("$registry", n), s.config.globalProperties.$registry = n;
|
|
2365
|
-
const o = new
|
|
2408
|
+
const o = new M(n);
|
|
2366
2409
|
e?.client && o.setClient(e.client), s.provide("$stonecrop", o), s.config.globalProperties.$stonecrop = o;
|
|
2367
2410
|
try {
|
|
2368
2411
|
const a = s.config.globalProperties.$pinia;
|
|
2369
2412
|
if (a) {
|
|
2370
|
-
const c =
|
|
2413
|
+
const c = G(a);
|
|
2371
2414
|
s.provide("$operationLogStore", c), s.config.globalProperties.$operationLogStore = c;
|
|
2372
2415
|
}
|
|
2373
2416
|
} catch (a) {
|
|
@@ -2376,10 +2419,10 @@ const at = {
|
|
|
2376
2419
|
if (e?.components)
|
|
2377
2420
|
for (const [a, c] of Object.entries(e.components))
|
|
2378
2421
|
s.component(a, c);
|
|
2379
|
-
e?.autoInitializeRouter && e.onRouterInitialized &&
|
|
2422
|
+
e?.autoInitializeRouter && e.onRouterInitialized && Ge(n, o, e.onRouterInitialized);
|
|
2380
2423
|
}
|
|
2381
|
-
},
|
|
2382
|
-
const s =
|
|
2424
|
+
}, ft = be("stonecrop-validation", () => {
|
|
2425
|
+
const s = E([]), e = P(() => s.value.length === 0), t = P(() => {
|
|
2383
2426
|
const l = {};
|
|
2384
2427
|
for (const d of s.value)
|
|
2385
2428
|
l[d.field] || (l[d.field] = []), l[d.field].push(d.message);
|
|
@@ -2388,8 +2431,8 @@ const at = {
|
|
|
2388
2431
|
function r(l) {
|
|
2389
2432
|
return s.value.filter((d) => d.field === l).map((d) => d.message);
|
|
2390
2433
|
}
|
|
2391
|
-
function i(l, d,
|
|
2392
|
-
s.value.push({ trigger: l, field: d, message:
|
|
2434
|
+
function i(l, d, v) {
|
|
2435
|
+
s.value.push({ trigger: l, field: d, message: v });
|
|
2393
2436
|
}
|
|
2394
2437
|
function n(l) {
|
|
2395
2438
|
s.value = s.value.filter((d) => d.trigger !== l);
|
|
@@ -2397,26 +2440,26 @@ const at = {
|
|
|
2397
2440
|
function o() {
|
|
2398
2441
|
s.value = [];
|
|
2399
2442
|
}
|
|
2400
|
-
async function a(l, d,
|
|
2443
|
+
async function a(l, d, v, S) {
|
|
2401
2444
|
n(l);
|
|
2402
|
-
const m = Object.freeze({ ...
|
|
2445
|
+
const m = Object.freeze({ ...v }), k = (w, R) => i(l, w, R);
|
|
2403
2446
|
try {
|
|
2404
|
-
await
|
|
2405
|
-
} catch (
|
|
2447
|
+
await Re(d.clientHandler, { record: m, value: S, setError: k });
|
|
2448
|
+
} catch (w) {
|
|
2406
2449
|
typeof console < "u" && console.error(
|
|
2407
2450
|
`Validation trigger "${l}" threw and was ignored (advisory — save is not blocked). Fix its clientHandler:`,
|
|
2408
|
-
|
|
2451
|
+
w
|
|
2409
2452
|
);
|
|
2410
2453
|
}
|
|
2411
2454
|
}
|
|
2412
|
-
async function c(l, d,
|
|
2413
|
-
const
|
|
2414
|
-
for (const [m,
|
|
2415
|
-
|
|
2416
|
-
await Promise.all(
|
|
2455
|
+
async function c(l, d, v) {
|
|
2456
|
+
const S = [];
|
|
2457
|
+
for (const [m, k] of Object.entries(l))
|
|
2458
|
+
k.on.includes(d) && S.push(a(m, k, v, v[d]));
|
|
2459
|
+
await Promise.all(S);
|
|
2417
2460
|
}
|
|
2418
2461
|
async function u(l, d) {
|
|
2419
|
-
await Promise.all(Object.entries(l).map(([
|
|
2462
|
+
await Promise.all(Object.entries(l).map(([v, S]) => a(v, S, d, void 0)));
|
|
2420
2463
|
}
|
|
2421
2464
|
return {
|
|
2422
2465
|
errors: s,
|
|
@@ -2430,8 +2473,8 @@ const at = {
|
|
|
2430
2473
|
validateRecord: u
|
|
2431
2474
|
};
|
|
2432
2475
|
});
|
|
2433
|
-
var
|
|
2434
|
-
class
|
|
2476
|
+
var A = /* @__PURE__ */ ((s) => (s.ERROR = "error", s.WARNING = "warning", s.INFO = "info", s))(A || {});
|
|
2477
|
+
class Ke {
|
|
2435
2478
|
options;
|
|
2436
2479
|
/**
|
|
2437
2480
|
* Creates a new SchemaValidator instance
|
|
@@ -2462,7 +2505,7 @@ class Ue {
|
|
|
2462
2505
|
const d = i instanceof Map ? i : i.toObject();
|
|
2463
2506
|
o.push(...this.validateActionRegistration(e, d));
|
|
2464
2507
|
}
|
|
2465
|
-
const c = o.filter((d) => d.severity ===
|
|
2508
|
+
const c = o.filter((d) => d.severity === A.ERROR).length, u = o.filter((d) => d.severity === A.WARNING).length, l = o.filter((d) => d.severity === A.INFO).length;
|
|
2466
2509
|
return {
|
|
2467
2510
|
valid: c === 0,
|
|
2468
2511
|
issues: o,
|
|
@@ -2480,7 +2523,7 @@ class Ue {
|
|
|
2480
2523
|
for (const n of t) {
|
|
2481
2524
|
if (!n.fieldname) {
|
|
2482
2525
|
i.push({
|
|
2483
|
-
severity:
|
|
2526
|
+
severity: A.ERROR,
|
|
2484
2527
|
rule: "required-fieldname",
|
|
2485
2528
|
message: "Field is missing required property: fieldname",
|
|
2486
2529
|
doctype: e,
|
|
@@ -2489,13 +2532,13 @@ class Ue {
|
|
|
2489
2532
|
continue;
|
|
2490
2533
|
}
|
|
2491
2534
|
n.kind === "field" && !n.component && i.push({
|
|
2492
|
-
severity:
|
|
2535
|
+
severity: A.ERROR,
|
|
2493
2536
|
rule: "required-component",
|
|
2494
2537
|
message: `Field "${n.fieldname}" must have a component property`,
|
|
2495
2538
|
doctype: e,
|
|
2496
2539
|
fieldname: n.fieldname
|
|
2497
|
-
}), n.kind === "field" &&
|
|
2498
|
-
severity:
|
|
2540
|
+
}), n.kind === "field" && Se(n.component) && !n.doctype && !r?.[n.fieldname] && i.push({
|
|
2541
|
+
severity: A.ERROR,
|
|
2499
2542
|
rule: "link-component-without-doctype",
|
|
2500
2543
|
message: `Field "${n.fieldname}" renders with "${n.component}", which is a link component, but has no \`doctype\` to name its target`,
|
|
2501
2544
|
doctype: e,
|
|
@@ -2514,7 +2557,7 @@ class Ue {
|
|
|
2514
2557
|
if (n.kind === "field" && n.doctype) {
|
|
2515
2558
|
const o = n.doctype;
|
|
2516
2559
|
r.registry[o] || r.registry[o.toLowerCase()] || i.push({
|
|
2517
|
-
severity:
|
|
2560
|
+
severity: A.ERROR,
|
|
2518
2561
|
rule: "link-invalid-target",
|
|
2519
2562
|
message: `Link field "${n.fieldname}" references non-existent doctype: "${o}"`,
|
|
2520
2563
|
doctype: e,
|
|
@@ -2538,7 +2581,7 @@ class Ue {
|
|
|
2538
2581
|
const u = i.registry[c.target];
|
|
2539
2582
|
if (!u) {
|
|
2540
2583
|
n.push({
|
|
2541
|
-
severity:
|
|
2584
|
+
severity: A.ERROR,
|
|
2542
2585
|
rule: "link-invalid-target",
|
|
2543
2586
|
message: `Link "${a}" references non-existent doctype: "${c.target}"`,
|
|
2544
2587
|
doctype: e,
|
|
@@ -2548,7 +2591,7 @@ class Ue {
|
|
|
2548
2591
|
continue;
|
|
2549
2592
|
}
|
|
2550
2593
|
if (c.target === e && n.push({
|
|
2551
|
-
severity:
|
|
2594
|
+
severity: A.WARNING,
|
|
2552
2595
|
rule: "link-self-referential",
|
|
2553
2596
|
message: `Link "${a}" is self-referential (target: "${c.target}")`,
|
|
2554
2597
|
doctype: e,
|
|
@@ -2557,14 +2600,14 @@ class Ue {
|
|
|
2557
2600
|
}), c.backlink && u.links) {
|
|
2558
2601
|
const l = u.links[c.backlink];
|
|
2559
2602
|
l ? l.target !== e && n.push({
|
|
2560
|
-
severity:
|
|
2603
|
+
severity: A.WARNING,
|
|
2561
2604
|
rule: "link-backlink-mismatch",
|
|
2562
2605
|
message: `Backlink "${c.backlink}" on "${c.target}" points to "${l.target}" instead of "${e}"`,
|
|
2563
2606
|
doctype: e,
|
|
2564
2607
|
fieldname: a,
|
|
2565
2608
|
context: { backlink: c.backlink, target: c.target, actualTarget: l.target }
|
|
2566
2609
|
}) : n.push({
|
|
2567
|
-
severity:
|
|
2610
|
+
severity: A.ERROR,
|
|
2568
2611
|
rule: "link-backlink-missing",
|
|
2569
2612
|
message: `Backlink "${c.backlink}" not found on target doctype "${c.target}"`,
|
|
2570
2613
|
doctype: e,
|
|
@@ -2577,7 +2620,7 @@ class Ue {
|
|
|
2577
2620
|
if (l && l.kind === "field") {
|
|
2578
2621
|
const d = l.doctype;
|
|
2579
2622
|
d && d !== c.target && n.push({
|
|
2580
|
-
severity:
|
|
2623
|
+
severity: A.ERROR,
|
|
2581
2624
|
rule: "link-field-target-mismatch",
|
|
2582
2625
|
message: `Link field "${c.fieldname}" targets "${d}" but link declaration targets "${c.target}"`,
|
|
2583
2626
|
doctype: e,
|
|
@@ -2596,19 +2639,19 @@ class Ue {
|
|
|
2596
2639
|
validateWorkflow(e, t) {
|
|
2597
2640
|
const r = [];
|
|
2598
2641
|
if (!t.initial && !t.type && r.push({
|
|
2599
|
-
severity:
|
|
2642
|
+
severity: A.WARNING,
|
|
2600
2643
|
rule: "workflow-missing-initial",
|
|
2601
2644
|
message: "Workflow is missing initial state property",
|
|
2602
2645
|
doctype: e
|
|
2603
2646
|
}), !t.states || Object.keys(t.states).length === 0)
|
|
2604
2647
|
return r.push({
|
|
2605
|
-
severity:
|
|
2648
|
+
severity: A.WARNING,
|
|
2606
2649
|
rule: "workflow-no-states",
|
|
2607
2650
|
message: "Workflow has no states defined",
|
|
2608
2651
|
doctype: e
|
|
2609
2652
|
}), r;
|
|
2610
2653
|
t.initial && typeof t.initial == "string" && !t.states[t.initial] && r.push({
|
|
2611
|
-
severity:
|
|
2654
|
+
severity: A.ERROR,
|
|
2612
2655
|
rule: "workflow-invalid-initial",
|
|
2613
2656
|
message: `Workflow initial state "${t.initial}" does not exist in states`,
|
|
2614
2657
|
doctype: e,
|
|
@@ -2624,15 +2667,15 @@ class Ue {
|
|
|
2624
2667
|
n.add(l);
|
|
2625
2668
|
else if (l && typeof l == "object") {
|
|
2626
2669
|
const d = "target" in l ? l.target : void 0;
|
|
2627
|
-
typeof d == "string" ? n.add(d) : Array.isArray(d) && d.forEach((
|
|
2628
|
-
typeof
|
|
2670
|
+
typeof d == "string" ? n.add(d) : Array.isArray(d) && d.forEach((v) => {
|
|
2671
|
+
typeof v == "string" && n.add(v);
|
|
2629
2672
|
});
|
|
2630
2673
|
}
|
|
2631
2674
|
}
|
|
2632
2675
|
}
|
|
2633
2676
|
for (const o of i)
|
|
2634
2677
|
n.has(o) || r.push({
|
|
2635
|
-
severity:
|
|
2678
|
+
severity: A.WARNING,
|
|
2636
2679
|
rule: "workflow-unreachable-state",
|
|
2637
2680
|
message: `Workflow state "${o}" may not be reachable`,
|
|
2638
2681
|
doctype: e,
|
|
@@ -2645,11 +2688,11 @@ class Ue {
|
|
|
2645
2688
|
* @internal
|
|
2646
2689
|
*/
|
|
2647
2690
|
validateActionRegistration(e, t) {
|
|
2648
|
-
const r = [], i =
|
|
2691
|
+
const r = [], i = B();
|
|
2649
2692
|
for (const [n, o] of Object.entries(t)) {
|
|
2650
2693
|
if (!Array.isArray(o)) {
|
|
2651
2694
|
r.push({
|
|
2652
|
-
severity:
|
|
2695
|
+
severity: A.ERROR,
|
|
2653
2696
|
rule: "action-invalid-format",
|
|
2654
2697
|
message: `Action configuration for "${n}" must be an array`,
|
|
2655
2698
|
doctype: e,
|
|
@@ -2660,7 +2703,7 @@ class Ue {
|
|
|
2660
2703
|
for (const a of o) {
|
|
2661
2704
|
const c = i;
|
|
2662
2705
|
c.globalActions?.has(a) || c.globalTransitionActions?.has(a) || r.push({
|
|
2663
|
-
severity:
|
|
2706
|
+
severity: A.WARNING,
|
|
2664
2707
|
rule: "action-not-registered",
|
|
2665
2708
|
message: `Action "${a}" referenced in "${n}" is not registered in FieldTriggerEngine`,
|
|
2666
2709
|
doctype: e,
|
|
@@ -2671,41 +2714,43 @@ class Ue {
|
|
|
2671
2714
|
return r;
|
|
2672
2715
|
}
|
|
2673
2716
|
}
|
|
2674
|
-
function
|
|
2675
|
-
return new
|
|
2717
|
+
function Ze(s, e) {
|
|
2718
|
+
return new Ke({
|
|
2676
2719
|
registry: s,
|
|
2677
2720
|
...e
|
|
2678
2721
|
});
|
|
2679
2722
|
}
|
|
2680
|
-
function
|
|
2681
|
-
return
|
|
2723
|
+
function gt(s, e, t, r, i) {
|
|
2724
|
+
return Ze(t).validate(s, e, r, i);
|
|
2682
2725
|
}
|
|
2683
2726
|
export {
|
|
2727
|
+
We as DRAFT_RECORD_ID,
|
|
2684
2728
|
Oe as Doctype,
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2729
|
+
U as FieldTriggerEngine,
|
|
2730
|
+
W as HST,
|
|
2731
|
+
j as Registry,
|
|
2732
|
+
Ke as SchemaValidator,
|
|
2733
|
+
M as Stonecrop,
|
|
2734
|
+
A as ValidationSeverity,
|
|
2735
|
+
Ve as createHST,
|
|
2736
|
+
Ze as createValidator,
|
|
2737
|
+
dt as default,
|
|
2738
|
+
Re as executeClientHandler,
|
|
2739
|
+
B as getGlobalTriggerEngine,
|
|
2740
|
+
_ as isDraftRecordId,
|
|
2741
|
+
st as markOperationIrreversible,
|
|
2742
|
+
rt as registerGlobalAction,
|
|
2743
|
+
nt as registerTransitionAction,
|
|
2744
|
+
it as setFieldRollback,
|
|
2745
|
+
ot as triggerTransition,
|
|
2746
|
+
at as useClientAction,
|
|
2747
|
+
ct as useLazyLink,
|
|
2703
2748
|
$e as useOperationLog,
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2749
|
+
G as useOperationLogStore,
|
|
2750
|
+
He as useStonecrop,
|
|
2751
|
+
lt as useUndoRedoShortcuts,
|
|
2752
|
+
ft as useValidationStore,
|
|
2753
|
+
gt as validateSchema,
|
|
2754
|
+
ut as withBatch
|
|
2710
2755
|
};
|
|
2711
2756
|
//# sourceMappingURL=stonecrop.js.map
|