@agile-team/mach-report 2.11.0 → 2.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,311 @@
1
+ import { computed as W, ref as _, shallowRef as K, watch as O, onBeforeUnmount as oe, defineComponent as re, openBlock as u, createElementBlock as c, unref as e, createElementVNode as i, toDisplayString as l, withDirectives as F, withKeys as ae, isRef as z, vModelText as Y, Fragment as j, renderList as J, vModelSelect as le, createCommentVNode as g, createTextVNode as G, withModifiers as ie, normalizeClass as se } from "vue";
2
+ import { parseReportTemplate as M, cloneReportTemplate as ne } from "@agile-team/mach-report";
3
+ import { TEMPLATE_LIBRARY_MESSAGES as de } from "./designer.js";
4
+ import { _ as ue } from "./_plugin-vue_export-helper-8SL1F89S.js";
5
+ function ce(r) {
6
+ return !r || typeof r.id != "string" || !r.id.trim() || typeof r.name != "string" || !r.name.trim() || [r.draftRevision, r.publishedRevision].some((p) => p !== void 0 && (typeof p != "string" || !p.trim())) ? !1 : r.tags === void 0 || Array.isArray(r.tags) && r.tags.length <= 20 && r.tags.every((p) => typeof p == "string");
7
+ }
8
+ function ve(r) {
9
+ if (!r || !Array.isArray(r.items) || r.items.length > 100 || r.next !== void 0 && (typeof r.next != "string" || !r.next || r.next.length > 4096)) throw new Error("invalid");
10
+ const p = /* @__PURE__ */ new Set();
11
+ for (const d of r.items) {
12
+ if (!ce(d) || p.has(d.id)) throw new Error("invalid");
13
+ p.add(d.id);
14
+ }
15
+ if (r.categories !== void 0 && (!Array.isArray(r.categories) || r.categories.length > 1e3 || r.categories.some((d) => !d || typeof d.id != "string" || !d.id || typeof d.label != "string"))) throw new Error("invalid");
16
+ }
17
+ function ye(r, p) {
18
+ const d = W(() => ({ ...de, ...r.messages })), N = _(""), a = _(""), D = K([]), L = K([]), f = _([void 0]), w = _(), S = _(!1), T = _(!1), m = _(""), v = K(), q = _(""), $ = _(""), k = _("search"), x = _(""), E = K();
19
+ let h = 0, C = 0, P, I, V;
20
+ const B = W(() => ({ search: d.value.retrySearch, open: d.value.retryOpen, copy: d.value.retryCopy })[k.value]);
21
+ function A() {
22
+ m.value = "", E.value = void 0;
23
+ }
24
+ function s(t, n) {
25
+ if (ve(t), t.next !== void 0 && (t.next === n.cursor || !n.previous && f.value.includes(t.next))) throw new Error(d.value.stale);
26
+ D.value = t.items.map((y) => ({ ...y, ...y.tags ? { tags: [...y.tags] } : {} })), w.value = t.next, n.previous ? f.value = f.value.slice(0, -1) : n.more && (f.value = [...f.value, n.cursor]), t.categories && (L.value = t.categories);
27
+ }
28
+ function o(t) {
29
+ return t instanceof Error ? t.message === "invalid" ? d.value.invalid : t.message : String(t);
30
+ }
31
+ async function R(t) {
32
+ clearTimeout(V), P?.abort();
33
+ const n = ++h, y = new AbortController();
34
+ P = y, S.value = !0, A(), !t.more && !t.previous && (D.value = [], w.value = void 0, f.value = [void 0]);
35
+ try {
36
+ const b = await r.provider.search({ query: t.query, category: t.category, cursor: t.cursor, limit: 30, signal: y.signal });
37
+ if (n !== h) return;
38
+ s(b, t);
39
+ } catch (b) {
40
+ n === h && !y.signal.aborted && (m.value = o(b), k.value = "search", E.value = () => R(t));
41
+ } finally {
42
+ n === h && (S.value = !1);
43
+ }
44
+ }
45
+ async function U(t = !1, n = !1) {
46
+ t && !w.value || n && f.value.length < 2 || await R({ query: N.value.trim(), category: a.value || void 0, cursor: n ? f.value.at(-2) : t ? w.value : void 0, more: t, previous: n });
47
+ }
48
+ async function X(t, n, y) {
49
+ if (t.savedDocument) return M(t.savedDocument);
50
+ if (t.candidate) return M(t.candidate);
51
+ const b = await r.provider.get(t.entry.id, { signal: n, mode: t.mode });
52
+ if (y !== C) return;
53
+ if (!b || b.id !== t.entry.id) throw new Error(d.value.missing);
54
+ const H = M(b);
55
+ if (t.mode === "published" && t.entry.publishedRevision !== H.revision) throw new Error(d.value.publicationChanged);
56
+ return t.copy ? (t.candidate = ne(H, t.identity), M(t.candidate)) : H;
57
+ }
58
+ async function Q(t) {
59
+ if (T.value) return;
60
+ const n = ++C, y = new AbortController();
61
+ I = y, T.value = !0, A(), x.value = (t.copy && !t.savedDocument ? d.value.creatingTarget : d.value.openingTarget).replace("{name}", t.savedDocument?.name ?? t.entry.name);
62
+ try {
63
+ let b = await X(t, y.signal, n);
64
+ if (!b || n !== C) return;
65
+ if (t.copy && !t.savedDocument) {
66
+ if (!t.create || (b = M(await t.create(b, { signal: y.signal })), n !== C)) return;
67
+ if (b.id !== t.identity.id) throw new Error(d.value.invalid);
68
+ t.savedDocument = M(b), v.value = void 0;
69
+ }
70
+ p(b, { mode: t.mode }), t.copy && U();
71
+ } catch (b) {
72
+ n === C && !y.signal.aborted && (m.value = o(b), k.value = t.copy && !t.savedDocument ? "copy" : "open", E.value = () => Q(t));
73
+ } finally {
74
+ n === C && (T.value = !1, x.value = "");
75
+ }
76
+ }
77
+ async function Z(t, n = !1, y = "edit") {
78
+ await Q({ entry: { ...t }, copy: n, mode: n ? "edit" : y, identity: { id: q.value.trim(), name: $.value.trim() }, create: r.create });
79
+ }
80
+ function ee() {
81
+ h++, P?.abort(), D.value = [], w.value = void 0, f.value = [void 0], S.value = !0, A(), clearTimeout(V), V = setTimeout(() => {
82
+ U();
83
+ }, 180);
84
+ }
85
+ function te() {
86
+ C++, I?.abort(), T.value = !1, x.value = "", v.value = void 0, U();
87
+ }
88
+ return O([N, a], ee), O([() => r.provider, () => r.create], te), O([q, $], () => {
89
+ k.value === "copy" && A();
90
+ }), oe(() => {
91
+ h++, C++, clearTimeout(V), P?.abort(), I?.abort();
92
+ }), U(), {
93
+ m: d,
94
+ cursors: f,
95
+ query: N,
96
+ category: a,
97
+ entries: D,
98
+ categories: L,
99
+ next: w,
100
+ loading: S,
101
+ busy: T,
102
+ error: m,
103
+ errorKind: k,
104
+ retryLabel: B,
105
+ loadingTarget: x,
106
+ copying: v,
107
+ newId: q,
108
+ newName: $,
109
+ search: U,
110
+ load: Z,
111
+ retry: async () => {
112
+ !T.value && !S.value && await E.value?.();
113
+ },
114
+ beginCopy: (t) => {
115
+ A(), v.value = t, q.value = "", $.value = t.name;
116
+ },
117
+ cancelCopy: () => {
118
+ T.value || (v.value = void 0, A());
119
+ }
120
+ };
121
+ }
122
+ const be = ["aria-label", "aria-busy"], fe = ["disabled"], me = { class: "mr-library-search" }, pe = ["placeholder", "aria-label"], ge = ["aria-label"], he = { value: "" }, _e = ["value"], we = {
123
+ key: 0,
124
+ class: "mr-library-progress",
125
+ role: "status"
126
+ }, ke = {
127
+ key: 1,
128
+ role: "alert",
129
+ class: "mr-library-error"
130
+ }, Ce = ["disabled"], Re = ["disabled"], Te = ["disabled"], xe = ["disabled"], Ee = ["disabled"], Ae = { key: 3 }, $e = { class: "mr-library-info" }, De = ["title", "disabled", "onClick"], Se = ["title"], qe = { key: 0 }, Le = { key: 1 }, Pe = {
131
+ key: 2,
132
+ class: "mr-library-tags"
133
+ }, Ve = ["title"], Me = { class: "mr-library-actions" }, Ne = ["disabled", "onClick"], Ie = ["disabled", "onClick"], Ue = ["disabled", "onClick"], Be = {
134
+ key: 4,
135
+ class: "mr-library-empty",
136
+ role: "status"
137
+ }, Ke = { key: 0 }, Fe = ["disabled"], ze = ["disabled"], Ge = /* @__PURE__ */ re({
138
+ __name: "ReportTemplateLibrary",
139
+ props: {
140
+ provider: {},
141
+ messages: {},
142
+ create: { type: Function }
143
+ },
144
+ emits: ["open"],
145
+ setup(r, { emit: p }) {
146
+ const d = r, N = p, { m: a, cursors: D, query: L, category: f, entries: w, categories: S, next: T, loading: m, busy: v, error: q, copying: $, newId: k, newName: x, search: E, load: h, beginCopy: C, cancelCopy: P, retry: I, retryLabel: V, loadingTarget: B } = ye(d, (A, s) => N("open", A, s));
147
+ return (A, s) => (u(), c("section", {
148
+ class: "mr-library",
149
+ "aria-label": e(a).title,
150
+ "aria-busy": e(m) || e(v)
151
+ }, [
152
+ i("header", null, [
153
+ i("div", null, [
154
+ i("h2", null, l(e(a).title), 1),
155
+ i("p", null, l(e(a).subtitle), 1)
156
+ ]),
157
+ i("button", {
158
+ type: "button",
159
+ disabled: e(m) || e(v),
160
+ onClick: s[0] || (s[0] = (o) => e(E)())
161
+ }, l(e(a).refresh), 9, fe)
162
+ ]),
163
+ i("div", me, [
164
+ F(i("input", {
165
+ "onUpdate:modelValue": s[1] || (s[1] = (o) => z(L) ? L.value = o : null),
166
+ type: "search",
167
+ placeholder: e(a).search,
168
+ "aria-label": e(a).search,
169
+ onKeydown: s[2] || (s[2] = ae((o) => e(E)(), ["enter"]))
170
+ }, null, 40, pe), [
171
+ [Y, e(L)]
172
+ ]),
173
+ F(i("select", {
174
+ "onUpdate:modelValue": s[3] || (s[3] = (o) => z(f) ? f.value = o : null),
175
+ "aria-label": e(a).all
176
+ }, [
177
+ i("option", he, l(e(a).all), 1),
178
+ (u(!0), c(j, null, J(e(S), (o) => (u(), c("option", {
179
+ key: o.id,
180
+ value: o.id
181
+ }, l(o.label) + l(o.count === void 0 ? "" : ` (${o.count})`), 9, _e))), 128))
182
+ ], 8, ge), [
183
+ [le, e(f)]
184
+ ])
185
+ ]),
186
+ e(B) ? (u(), c("div", we, l(e(B)), 1)) : g("", !0),
187
+ e(q) ? (u(), c("div", ke, [
188
+ G(l(e(q)) + " ", 1),
189
+ i("button", {
190
+ type: "button",
191
+ disabled: e(m) || e(v),
192
+ onClick: s[4] || (s[4] = (o) => e(I)())
193
+ }, l(e(V)), 9, Ce)
194
+ ])) : g("", !0),
195
+ e($) ? (u(), c("form", {
196
+ key: 2,
197
+ class: "mr-library-copy",
198
+ onSubmit: s[8] || (s[8] = ie((o) => e(h)(e($), !0), ["prevent"]))
199
+ }, [
200
+ i("strong", null, l(e(a).copyTitle) + " · " + l(e($).name), 1),
201
+ i("label", null, [
202
+ G(l(e(a).newId), 1),
203
+ F(i("input", {
204
+ "onUpdate:modelValue": s[5] || (s[5] = (o) => z(k) ? k.value = o : null),
205
+ required: "",
206
+ maxlength: "256",
207
+ disabled: e(v)
208
+ }, null, 8, Re), [
209
+ [Y, e(k)]
210
+ ])
211
+ ]),
212
+ i("label", null, [
213
+ G(l(e(a).newName), 1),
214
+ F(i("input", {
215
+ "onUpdate:modelValue": s[6] || (s[6] = (o) => z(x) ? x.value = o : null),
216
+ required: "",
217
+ maxlength: "256",
218
+ disabled: e(v)
219
+ }, null, 8, Te), [
220
+ [Y, e(x)]
221
+ ])
222
+ ]),
223
+ i("div", null, [
224
+ i("button", {
225
+ type: "button",
226
+ disabled: e(v),
227
+ onClick: s[7] || (s[7] = (o) => e(P)())
228
+ }, l(e(a).cancel), 9, xe),
229
+ i("button", {
230
+ type: "submit",
231
+ disabled: e(v) || !e(k).trim() || !e(x).trim()
232
+ }, l(e(v) ? e(a).loading : e(a).create), 9, Ee)
233
+ ])
234
+ ], 32)) : g("", !0),
235
+ e(w).length ? (u(), c("ul", Ae, [
236
+ (u(!0), c(j, null, J(e(w), (o) => (u(), c("li", {
237
+ key: o.id
238
+ }, [
239
+ i("div", $e, [
240
+ i("button", {
241
+ class: "mr-library-name",
242
+ title: o.name,
243
+ type: "button",
244
+ disabled: e(v),
245
+ onClick: (R) => e(h)(o)
246
+ }, l(o.name), 9, De),
247
+ i("small", {
248
+ title: o.id
249
+ }, [
250
+ G(l(o.id), 1),
251
+ o.revision ? (u(), c("span", qe, " · " + l(e(a).revision) + " " + l(o.revision), 1)) : g("", !0)
252
+ ], 8, Se),
253
+ o.draftRevision || o.publishedRevision ? (u(), c("span", {
254
+ key: 0,
255
+ class: se(["mr-library-state", { "mr-library-state--draft": o.draftRevision }])
256
+ }, l(o.draftRevision ? o.publishedRevision ? e(a).draftPending : e(a).draft : e(a).published), 3)) : g("", !0),
257
+ o.description ? (u(), c("p", Le, l(o.description), 1)) : g("", !0),
258
+ o.tags?.length ? (u(), c("div", Pe, [
259
+ (u(!0), c(j, null, J(o.tags, (R) => (u(), c("span", {
260
+ key: R,
261
+ title: R
262
+ }, l(R), 9, Ve))), 128))
263
+ ])) : g("", !0)
264
+ ]),
265
+ i("div", Me, [
266
+ r.create ? (u(), c("button", {
267
+ key: 0,
268
+ type: "button",
269
+ disabled: e(v),
270
+ onClick: (R) => e(C)(o)
271
+ }, l(e(a).copy), 9, Ne)) : g("", !0),
272
+ o.publishedRevision ? (u(), c("button", {
273
+ key: 1,
274
+ type: "button",
275
+ disabled: e(v),
276
+ onClick: (R) => e(h)(o, !1, "published")
277
+ }, l(e(a).viewPublished), 9, Ie)) : g("", !0),
278
+ i("button", {
279
+ type: "button",
280
+ disabled: e(v),
281
+ onClick: (R) => e(h)(o)
282
+ }, l(o.draftRevision ? e(a).continueDraft : e(a).open), 9, Ue)
283
+ ])
284
+ ]))), 128))
285
+ ])) : (u(), c("div", Be, [
286
+ i("strong", null, l(e(m) ? e(a).loading : e(a).empty), 1),
287
+ e(m) ? g("", !0) : (u(), c("p", Ke, l(e(a).emptyHint), 1))
288
+ ])),
289
+ i("footer", null, [
290
+ i("span", null, l(e(D).length) + " " + l(e(a).page) + " · " + l(e(w).length) + " " + l(e(a).count), 1),
291
+ i("div", null, [
292
+ e(D).length > 1 ? (u(), c("button", {
293
+ key: 0,
294
+ type: "button",
295
+ disabled: e(m) || e(v),
296
+ onClick: s[9] || (s[9] = (o) => e(E)(!1, !0))
297
+ }, l(e(a).previous), 9, Fe)) : g("", !0),
298
+ e(T) ? (u(), c("button", {
299
+ key: 1,
300
+ type: "button",
301
+ disabled: e(m) || e(v),
302
+ onClick: s[10] || (s[10] = (o) => e(E)(!0))
303
+ }, l(e(m) ? e(a).loading : e(a).loadMore), 9, ze)) : g("", !0)
304
+ ])
305
+ ])
306
+ ], 8, be));
307
+ }
308
+ }), Je = /* @__PURE__ */ ue(Ge, [["__scopeId", "data-v-9513aca4"]]);
309
+ export {
310
+ Je as default
311
+ };