@webx-ui/module-banners 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,607 @@
1
+ import { defineComponent as G, ref as C, useTemplateRef as be, onMounted as fe, nextTick as ye, openBlock as o, createBlock as k, unref as e, isRef as me, withCtx as i, createVNode as u, createElementVNode as T, withKeys as Z, createTextVNode as R, toDisplayString as z, computed as w, watch as A, createElementBlock as L, createSlots as _e, createCommentVNode as U, Fragment as se, normalizeClass as K, resolveDynamicComponent as ke, renderList as we } from "vue";
2
+ import { useRoute as re, useRouter as oe } from "vue-router";
3
+ import { useModal as ge, useLocales as xe, WxDialog as he, WxFormItem as ee, WxInput as ae, WxSpace as We, WxButton as le, WxTooltip as Be, WxIcon as j, WxSegmented as Ve, WxSkeleton as ie, WxEmpty as H, WxSortableList as qe, WxBadge as ne, WxAlert as Pe, toast as h, confirm as ce, createModal as $e, WxCard as Te, WxListDetail as ze, WxText as te, WxIndicator as Ce } from "@webx-ui/core";
4
+ import { useAdmin as J, useTranslate as Q, useErrorText as ue, WxScreenHead as Se, WxRowMenu as de, WxPreviewThumb as Ie, WxListScreen as Me } from "@webx-ui/module-admin";
5
+ import { c as X, u as Y, _ as pe } from "./index-QnpLuOX2.js";
6
+ const De = /* @__PURE__ */ G({
7
+ name: "WxBannerPlaceDialog",
8
+ __name: "PlaceDialog",
9
+ props: {
10
+ place: { default: null }
11
+ },
12
+ setup(M) {
13
+ const W = M, { open: b, resolve: D, dismiss: S } = ge(), g = X(J()), t = xe();
14
+ Y();
15
+ const p = Q("webx-banners"), a = W.place !== null;
16
+ function q() {
17
+ if (W.place === null) return {};
18
+ if (W.place.titles) return { ...W.place.titles };
19
+ const f = t.list.value[0]?.code;
20
+ return f === void 0 ? {} : { [f]: W.place.title };
21
+ }
22
+ const c = C(W.place?.key ?? ""), m = C(q()), B = C(!1), P = C({}), v = be("field");
23
+ fe(async () => {
24
+ await ye(), v.value?.querySelector("input")?.focus();
25
+ });
26
+ function I() {
27
+ return Object.values(m.value).some((f) => f.trim() !== "");
28
+ }
29
+ function x(f) {
30
+ const _ = Object.keys(P.value).find((d) => d === f || d.startsWith(`${f}.`));
31
+ return _ === void 0 ? void 0 : P.value[_]?.[0];
32
+ }
33
+ async function V() {
34
+ if (!(!I() || B.value)) {
35
+ B.value = !0, P.value = {};
36
+ try {
37
+ D(
38
+ a && W.place !== null ? await g.renamePlace(W.place.key, m.value) : await g.createPlace({ key: c.value.trim(), title: m.value })
39
+ );
40
+ } catch (f) {
41
+ P.value = f.body?.errors ?? {};
42
+ } finally {
43
+ B.value = !1;
44
+ }
45
+ }
46
+ }
47
+ return (f, _) => (o(), k(e(he), {
48
+ open: e(b),
49
+ "onUpdate:open": _[3] || (_[3] = (d) => me(b) ? b.value = d : null),
50
+ title: a ? e(p)("places.rename-title") : e(p)("places.new-title"),
51
+ width: 440
52
+ }, {
53
+ footer: i(() => [
54
+ u(e(We), { size: "sm" }, {
55
+ default: i(() => [
56
+ u(e(le), {
57
+ variant: "outline",
58
+ onClick: _[2] || (_[2] = (d) => e(S)())
59
+ }, {
60
+ default: i(() => [
61
+ R(z(e(p)("places.cancel")), 1)
62
+ ]),
63
+ _: 1
64
+ }),
65
+ u(e(le), {
66
+ type: "primary",
67
+ loading: B.value,
68
+ disabled: !I() || c.value.trim() === "",
69
+ onClick: V
70
+ }, {
71
+ default: i(() => [
72
+ R(z(a ? e(p)("places.save") : e(p)("places.create")), 1)
73
+ ]),
74
+ _: 1
75
+ }, 8, ["loading", "disabled"])
76
+ ]),
77
+ _: 1
78
+ })
79
+ ]),
80
+ default: i(() => [
81
+ u(e(ee), {
82
+ label: e(p)("places.field-title"),
83
+ error: x("title"),
84
+ required: ""
85
+ }, {
86
+ default: i(() => [
87
+ T("div", {
88
+ ref_key: "field",
89
+ ref: v
90
+ }, [
91
+ u(e(ae), {
92
+ modelValue: m.value,
93
+ "onUpdate:modelValue": _[0] || (_[0] = (d) => m.value = d),
94
+ localized: "",
95
+ "aria-label": e(p)("places.field-title"),
96
+ onKeyup: Z(V, ["enter"])
97
+ }, null, 8, ["modelValue", "aria-label"])
98
+ ], 512)
99
+ ]),
100
+ _: 1
101
+ }, 8, ["label", "error"]),
102
+ u(e(ee), {
103
+ label: e(p)("places.field-key"),
104
+ error: x("key"),
105
+ help: a ? void 0 : e(p)("places.key-help"),
106
+ required: ""
107
+ }, {
108
+ default: i(() => [
109
+ u(e(ae), {
110
+ modelValue: c.value,
111
+ "onUpdate:modelValue": _[1] || (_[1] = (d) => c.value = d),
112
+ disabled: a,
113
+ "aria-label": e(p)("places.field-key"),
114
+ autocomplete: "off",
115
+ onKeyup: Z(V, ["enter"])
116
+ }, null, 8, ["modelValue", "aria-label"])
117
+ ]),
118
+ _: 1
119
+ }, 8, ["label", "error", "help"])
120
+ ]),
121
+ _: 1
122
+ }, 8, ["open", "title"]));
123
+ }
124
+ }), Ue = { class: "wx-banner-place" }, Le = ["aria-label"], Re = { class: "wx-banner-place__usage" }, Ee = {
125
+ key: 0,
126
+ class: "wx-banner-place__layout"
127
+ }, Fe = { class: "wx-banner-row__thumb" }, Ne = ["src"], Oe = { class: "wx-banner-row__body" }, Ae = { class: "wx-banner-row__title" }, Ke = {
128
+ key: 0,
129
+ class: "wx-banner-row__facts"
130
+ }, je = /* @__PURE__ */ G({
131
+ name: "WxBannerPlacePane",
132
+ __name: "PlacePane",
133
+ props: {
134
+ place: {},
135
+ base: {},
136
+ inline: { type: Boolean, default: !0 }
137
+ },
138
+ emits: ["back", "changed"],
139
+ setup(M, { emit: W }) {
140
+ const b = M, D = W, S = J(), g = X(S), t = re(), p = oe();
141
+ Y();
142
+ const a = Q("webx-banners"), q = ue(), c = C([]), m = C(!0), B = w(() => S.can("banners.manage")), P = w({
143
+ get: () => t.query.view === "trashed" ? "trashed" : "live",
144
+ set: (l) => {
145
+ p.replace({
146
+ query: { ...t.query, view: l === "trashed" ? "trashed" : void 0 }
147
+ });
148
+ }
149
+ }), v = w(() => P.value === "trashed"), I = w(() => [
150
+ { value: "live", label: a("banner.all") },
151
+ { value: "trashed", label: a("banner.trashed"), icon: "trash" }
152
+ ]), x = w(() => B.value && !v.value && c.value.length > 1), V = w(() => ["single", "random", "slider"].includes(b.place.layout) ? a(`places.layout-${b.place.layout}`) : ""), f = w(() => c.value.filter((l) => l.thumb)), _ = w(
153
+ () => f.value.map((l) => ({
154
+ src: l.image ?? l.thumb,
155
+ thumb: l.thumb,
156
+ alt: l.title,
157
+ caption: l.title
158
+ }))
159
+ );
160
+ async function d() {
161
+ m.value = !0;
162
+ try {
163
+ c.value = await g.list(b.place.key, v.value);
164
+ } catch (l) {
165
+ h.danger(q(l));
166
+ } finally {
167
+ m.value = !1;
168
+ }
169
+ }
170
+ A(v, () => {
171
+ d();
172
+ }), d();
173
+ function E(l) {
174
+ return `${b.base}/${l.id}`;
175
+ }
176
+ function F() {
177
+ p.push({ path: `${b.base}/new`, query: { place: b.place.key } });
178
+ }
179
+ async function O() {
180
+ try {
181
+ await g.reorder(
182
+ b.place.key,
183
+ c.value.map((l) => l.id)
184
+ );
185
+ } catch (l) {
186
+ h.danger(q(l, a("banner.reorder-failed"))), await d();
187
+ }
188
+ }
189
+ async function n(l) {
190
+ try {
191
+ const y = await g.get(l.id);
192
+ await g.save(l.id, { ...y.values, enabled: !l.enabled }), h.success(l.enabled ? a("banner.switched-off") : a("banner.switched-on"));
193
+ } catch (y) {
194
+ h.danger(q(y));
195
+ } finally {
196
+ await d();
197
+ }
198
+ }
199
+ async function $(l) {
200
+ if (await ce({
201
+ title: a("banner.delete-title", { name: l.title }),
202
+ message: a("banner.delete-text"),
203
+ confirmText: a("banner.delete"),
204
+ cancelText: a("banner.cancel"),
205
+ tone: "danger"
206
+ }))
207
+ try {
208
+ await g.remove(l.id), h.success(a("banner.deleted")), D("changed");
209
+ } catch (r) {
210
+ h.danger(q(r));
211
+ } finally {
212
+ await d();
213
+ }
214
+ }
215
+ async function s(l) {
216
+ try {
217
+ await g.restore(l.id), h.success(a("banner.restored")), D("changed");
218
+ } catch (y) {
219
+ h.danger(q(y));
220
+ } finally {
221
+ await d();
222
+ }
223
+ }
224
+ function N(l) {
225
+ if (v.value)
226
+ return B.value ? [
227
+ {
228
+ key: "restore",
229
+ icon: "refresh",
230
+ label: a("banner.restore"),
231
+ run: () => {
232
+ s(l);
233
+ }
234
+ }
235
+ ] : [];
236
+ const y = {
237
+ key: "open",
238
+ icon: "edit",
239
+ label: a("banner.open"),
240
+ run: () => {
241
+ p.push(E(l));
242
+ }
243
+ };
244
+ return B.value ? [
245
+ y,
246
+ {
247
+ key: "toggle",
248
+ icon: l.enabled ? "eye-off" : "eye",
249
+ label: l.enabled ? a("banner.disable") : a("banner.enable"),
250
+ run: () => {
251
+ n(l);
252
+ }
253
+ },
254
+ {
255
+ key: "delete",
256
+ icon: "trash",
257
+ label: a("banner.delete"),
258
+ danger: !0,
259
+ run: () => {
260
+ $(l);
261
+ }
262
+ }
263
+ ] : [y];
264
+ }
265
+ const ve = w(
266
+ () => B.value && !v.value ? [{ key: "new", label: a("banner.new"), icon: "plus", primary: !0, run: F }] : []
267
+ );
268
+ return (l, y) => (o(), L("div", Ue, [
269
+ u(e(Se), {
270
+ level: 3,
271
+ back: !b.inline,
272
+ "back-label": e(a)("places.places"),
273
+ title: M.place.title,
274
+ actions: ve.value,
275
+ "collapse-below": 420,
276
+ onBack: y[0] || (y[0] = (r) => D("back"))
277
+ }, _e({ _: 2 }, [
278
+ M.place.declared ? {
279
+ name: "title-after",
280
+ fn: i(() => [
281
+ u(e(Be), {
282
+ content: e(a)("places.declared-help")
283
+ }, {
284
+ default: i(() => [
285
+ T("span", {
286
+ class: "wx-banner-place__lock",
287
+ tabindex: "0",
288
+ "aria-label": e(a)("places.declared")
289
+ }, [
290
+ u(e(j), {
291
+ name: "lock",
292
+ size: "sm"
293
+ })
294
+ ], 8, Le)
295
+ ]),
296
+ _: 1
297
+ }, 8, ["content"])
298
+ ]),
299
+ key: "0"
300
+ } : void 0
301
+ ]), 1032, ["back", "back-label", "title", "actions"]),
302
+ T("p", Re, [
303
+ T("span", null, z(e(a)("places.usage")), 1),
304
+ T("code", null, "banners('" + z(M.place.key) + "')", 1),
305
+ V.value ? (o(), L("span", Ee, "· " + z(V.value), 1)) : U("", !0)
306
+ ]),
307
+ u(e(Ve), {
308
+ modelValue: P.value,
309
+ "onUpdate:modelValue": y[1] || (y[1] = (r) => P.value = r),
310
+ class: "wx-banner-place__views",
311
+ size: "sm",
312
+ options: I.value,
313
+ "aria-label": e(a)("banner.all")
314
+ }, null, 8, ["modelValue", "options", "aria-label"]),
315
+ m.value && c.value.length === 0 ? (o(), k(e(ie), {
316
+ key: 0,
317
+ rows: 4
318
+ })) : c.value.length === 0 ? (o(), k(e(H), {
319
+ key: 1,
320
+ title: v.value ? e(a)("banner.empty-bin") : e(a)("banner.empty"),
321
+ description: v.value ? void 0 : e(a)("banner.empty-help")
322
+ }, null, 8, ["title", "description"])) : (o(), L(se, { key: 2 }, [
323
+ u(e(qe), {
324
+ modelValue: c.value,
325
+ "onUpdate:modelValue": y[2] || (y[2] = (r) => c.value = r),
326
+ class: K(["wx-banner-place__list", { "is-loading": m.value }]),
327
+ hoverable: "",
328
+ plain: "",
329
+ "item-key": "id",
330
+ handle: x.value ? "grip" : "row",
331
+ "item-label": (r) => r.title,
332
+ disabled: !x.value,
333
+ onMove: O
334
+ }, {
335
+ default: i(({ item: r }) => [
336
+ (o(), k(ke(v.value ? "div" : "router-link"), {
337
+ to: v.value ? void 0 : E(r),
338
+ class: K(["wx-banner-row", { "is-off": !r.enabled && !v.value }])
339
+ }, {
340
+ default: i(() => [
341
+ T("span", Fe, [
342
+ r.thumb ? (o(), k(e(Ie), {
343
+ key: 0,
344
+ fill: "",
345
+ items: _.value,
346
+ start: f.value.indexOf(r)
347
+ }, {
348
+ default: i(() => [
349
+ T("img", {
350
+ src: r.thumb,
351
+ alt: "",
352
+ loading: "lazy"
353
+ }, null, 8, Ne)
354
+ ]),
355
+ _: 2
356
+ }, 1032, ["items", "start"])) : (o(), k(e(j), {
357
+ key: 1,
358
+ name: "image",
359
+ size: "sm",
360
+ "aria-label": e(a)("banner.no-picture")
361
+ }, null, 8, ["aria-label"]))
362
+ ]),
363
+ T("span", Oe, [
364
+ T("span", Ae, z(r.title), 1),
365
+ r.video || !r.enabled && !v.value ? (o(), L("span", Ke, [
366
+ r.video ? (o(), k(e(ne), {
367
+ key: 0,
368
+ size: "sm",
369
+ type: "info"
370
+ }, {
371
+ default: i(() => [
372
+ R(z(e(a)("banner.video")), 1)
373
+ ]),
374
+ _: 1
375
+ })) : U("", !0),
376
+ !r.enabled && !v.value ? (o(), k(e(ne), {
377
+ key: 1,
378
+ dot: "",
379
+ size: "sm"
380
+ }, {
381
+ default: i(() => [
382
+ R(z(e(a)("banner.disabled")), 1)
383
+ ]),
384
+ _: 1
385
+ })) : U("", !0)
386
+ ])) : U("", !0)
387
+ ])
388
+ ]),
389
+ _: 2
390
+ }, 1032, ["to", "class"]))
391
+ ]),
392
+ actions: i(({ item: r }) => [
393
+ u(e(de), {
394
+ actions: N(r),
395
+ label: r.title
396
+ }, null, 8, ["actions", "label"])
397
+ ]),
398
+ _: 1
399
+ }, 8, ["modelValue", "class", "handle", "item-label", "disabled"]),
400
+ x.value ? (o(), k(e(Pe), {
401
+ key: 0,
402
+ class: "wx-banner-place__note",
403
+ type: "info",
404
+ description: e(a)("banner.order")
405
+ }, null, 8, ["description"])) : U("", !0)
406
+ ], 64))
407
+ ]));
408
+ }
409
+ }), He = /* @__PURE__ */ pe(je, [["__scopeId", "data-v-bc79af31"]]), Ge = {
410
+ key: 2,
411
+ class: "wx-banners__list"
412
+ }, Je = ["onClick"], Qe = { class: "wx-banners__name" }, Xe = /* @__PURE__ */ G({
413
+ __name: "BannersPage",
414
+ props: {
415
+ base: { default: "/banners" }
416
+ },
417
+ setup(M) {
418
+ const W = M, b = J(), D = X(b), S = re(), g = oe();
419
+ Y();
420
+ const t = Q("webx-banners"), p = ue(), a = C([]), q = C(!0), c = C(!1), m = C(!0), B = w(() => b.can("banners.manage")), P = $e(De), v = w(
421
+ () => b.state.manifest?.modules.find((n) => n.id === "banners")?.title ?? t("module.banners")
422
+ ), I = w(() => {
423
+ const n = S.query.place;
424
+ return typeof n == "string" && n !== "" ? n : null;
425
+ }), x = w(() => a.value.find((n) => n.key === I.value) ?? null);
426
+ async function V() {
427
+ q.value = !0;
428
+ try {
429
+ a.value = await D.places();
430
+ } catch (n) {
431
+ h.danger(p(n));
432
+ } finally {
433
+ q.value = !1;
434
+ }
435
+ }
436
+ V(), A([a, x, m], () => {
437
+ !m.value || a.value.length === 0 || x.value !== null || g.replace({ query: { ...S.query, place: a.value[0].key } });
438
+ }), A(x, (n) => {
439
+ n !== null && m.value && (c.value = !0);
440
+ }), I.value !== null && (c.value = !0);
441
+ function f(n) {
442
+ const $ = { ...S.query, place: n.key };
443
+ delete $.view, g.replace({ query: $ }), c.value = !0;
444
+ }
445
+ async function _() {
446
+ const n = await P({ place: null });
447
+ n && (h.success(t("places.created")), await V(), f(n));
448
+ }
449
+ async function d(n) {
450
+ await P({ place: n }) && (h.success(t("places.renamed")), await V());
451
+ }
452
+ async function E(n) {
453
+ if (await ce({
454
+ title: t("places.delete-title", { place: n.title }),
455
+ message: t("places.delete-text"),
456
+ confirmText: t("places.delete"),
457
+ cancelText: t("places.cancel"),
458
+ tone: "danger"
459
+ }))
460
+ try {
461
+ if (await D.removePlace(n.key), h.success(t("places.deleted")), I.value === n.key) {
462
+ const s = { ...S.query };
463
+ delete s.place, delete s.view, g.replace({ query: s }), c.value = !1;
464
+ }
465
+ } catch (s) {
466
+ h.danger(p(s));
467
+ } finally {
468
+ await V();
469
+ }
470
+ }
471
+ function F(n) {
472
+ return !B.value || n.declared ? [] : [
473
+ { key: "rename", icon: "edit", label: t("places.rename"), run: () => {
474
+ d(n);
475
+ } },
476
+ {
477
+ key: "delete",
478
+ icon: "trash",
479
+ // Said in the line itself, since a switched-off line cannot carry a tooltip: an empty
480
+ // place is the only kind that goes (decision 1).
481
+ label: n.count > 0 ? t("places.delete-empty-first") : t("places.delete"),
482
+ danger: !0,
483
+ disabled: n.count > 0,
484
+ run: () => {
485
+ E(n);
486
+ }
487
+ }
488
+ ];
489
+ }
490
+ const O = w(
491
+ () => B.value ? [{ key: "new-place", label: t("places.new"), icon: "plus", run: () => {
492
+ _();
493
+ } }] : []
494
+ );
495
+ return (n, $) => (o(), k(e(Me), {
496
+ title: v.value,
497
+ actions: O.value,
498
+ card: !1
499
+ }, {
500
+ default: i(() => [
501
+ u(e(Te), {
502
+ class: "wx-banners",
503
+ padding: "none"
504
+ }, {
505
+ default: i(() => [
506
+ u(e(ze), {
507
+ open: c.value,
508
+ "onUpdate:open": $[0] || ($[0] = (s) => c.value = s),
509
+ class: "wx-banners__panes",
510
+ "list-width": 300,
511
+ "detail-min": 440,
512
+ "detail-label": e(t)("places.places"),
513
+ onDetailInline: $[1] || ($[1] = (s) => m.value = s)
514
+ }, {
515
+ list: i(() => [
516
+ q.value && a.value.length === 0 ? (o(), k(e(ie), {
517
+ key: 0,
518
+ class: "wx-banners__loading",
519
+ rows: 3
520
+ })) : a.value.length === 0 ? (o(), k(e(H), {
521
+ key: 1,
522
+ title: e(t)("places.empty"),
523
+ description: e(t)("places.empty-help")
524
+ }, null, 8, ["title", "description"])) : (o(), L("ul", Ge, [
525
+ (o(!0), L(se, null, we(a.value, (s) => (o(), L("li", {
526
+ key: s.key,
527
+ class: "wx-banners__row"
528
+ }, [
529
+ T("button", {
530
+ type: "button",
531
+ class: K(["wx-banners__open", { "is-current": s.key === I.value }]),
532
+ onClick: (N) => f(s)
533
+ }, [
534
+ T("span", Qe, [
535
+ u(e(te), {
536
+ truncate: "",
537
+ weight: "medium"
538
+ }, {
539
+ default: i(() => [
540
+ R(z(s.title), 1)
541
+ ]),
542
+ _: 2
543
+ }, 1024),
544
+ s.declared ? (o(), k(e(j), {
545
+ key: 0,
546
+ class: "wx-banners__lock",
547
+ name: "lock",
548
+ size: "sm",
549
+ "aria-label": e(t)("places.declared")
550
+ }, null, 8, ["aria-label"])) : U("", !0),
551
+ u(e(Ce), {
552
+ class: "wx-banners__count",
553
+ type: "neutral",
554
+ value: s.count,
555
+ label: e(t)("places.count")
556
+ }, null, 8, ["value", "label"])
557
+ ]),
558
+ u(e(te), {
559
+ size: "sm",
560
+ tone: "muted",
561
+ mono: "",
562
+ truncate: ""
563
+ }, {
564
+ default: i(() => [
565
+ R("banners('" + z(s.key) + "')", 1)
566
+ ]),
567
+ _: 2
568
+ }, 1024)
569
+ ], 10, Je),
570
+ F(s).length > 0 ? (o(), k(e(de), {
571
+ key: 0,
572
+ actions: F(s),
573
+ label: s.title
574
+ }, null, 8, ["actions", "label"])) : U("", !0)
575
+ ]))), 128))
576
+ ]))
577
+ ]),
578
+ detail: i(({ inline: s, back: N }) => [
579
+ x.value ? (o(), k(He, {
580
+ key: x.value.key,
581
+ place: x.value,
582
+ base: W.base,
583
+ inline: s,
584
+ onBack: N,
585
+ onChanged: V
586
+ }, null, 8, ["place", "base", "inline", "onBack"])) : U("", !0)
587
+ ]),
588
+ empty: i(() => [
589
+ u(e(H), {
590
+ title: e(t)("places.choose"),
591
+ description: e(t)("places.choose-help")
592
+ }, null, 8, ["title", "description"])
593
+ ]),
594
+ _: 1
595
+ }, 8, ["open", "detail-label"])
596
+ ]),
597
+ _: 1
598
+ })
599
+ ]),
600
+ _: 1
601
+ }, 8, ["title", "actions"]));
602
+ }
603
+ }), na = /* @__PURE__ */ pe(Xe, [["__scopeId", "data-v-615232f0"]]);
604
+ export {
605
+ na as default
606
+ };
607
+ //# sourceMappingURL=BannersPage-D7hpUcBn.js.map