@webx-ui/module-menu 0.1.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/dist/index.js ADDED
@@ -0,0 +1,1004 @@
1
+ import { defineComponent as F, ref as D, useTemplateRef as _e, onMounted as ge, nextTick as we, openBlock as h, createBlock as g, unref as e, isRef as se, withCtx as r, createVNode as p, createElementVNode as q, withKeys as le, createTextVNode as V, toDisplayString as R, resolveComponent as ke, normalizeClass as Q, createSlots as xe, createCommentVNode as B, createElementBlock as O, Fragment as H, computed as S, watch as ae, renderList as Ce } from "vue";
2
+ import { useRoute as Ie, useRouter as $e } from "vue-router";
3
+ import { useModal as re, WxDialog as de, WxFormItem as E, WxInput as X, WxSpace as me, WxButton as P, WxSortableList as We, WxText as N, WxTooltip as ue, WxIcon as Y, useLocales as Me, WxSelect as ie, WxCheckbox as Ve, WxSwitch as Re, createModal as ce, WxAction as pe, WxSkeleton as fe, WxEmpty as Z, toast as M, confirm as ve, WxCard as Ue, WxListDetail as ze, WxIndicator as De } from "@webx-ui/core";
4
+ import { useAdmin as G, useTranslate as K, WxRowMenu as he, emptyLink as Te, WxLinkPicker as Le, useErrorText as ye, WxListScreen as Ne, WxDate as qe } from "@webx-ui/module-admin";
5
+ function te(d) {
6
+ const n = `${d.apiPath}/menus`, u = (t) => t.data;
7
+ return {
8
+ list: () => d.http.get(n).then(u),
9
+ create: (t) => d.http.post(n, t).then(u),
10
+ update: (t, l) => d.http.patch(`${n}/${encodeURIComponent(t)}`, l).then(u),
11
+ remove: (t) => d.http.delete(`${n}/${encodeURIComponent(t)}`).then(() => {
12
+ }),
13
+ items: (t) => d.http.get(`${n}/${encodeURIComponent(t)}/items`).then(u),
14
+ addItem: (t, l) => d.http.post(`${n}/${encodeURIComponent(t)}/items`, l).then(u),
15
+ saveItem: (t, l, a) => d.http.patch(`${n}/${encodeURIComponent(t)}/items/${l}`, a).then(u),
16
+ moveItem: (t, l, a, i) => d.http.post(`${n}/${encodeURIComponent(t)}/items/${l}/move`, {
17
+ parent_id: a,
18
+ index: i
19
+ }).then(() => {
20
+ }),
21
+ removeItem: (t, l) => d.http.delete(`${n}/${encodeURIComponent(t)}/items/${l}`).then((a) => a.data.deleted),
22
+ flush: (t) => d.http.post(`${n}/${encodeURIComponent(t)}/cache/flush`, {}).then(() => {
23
+ }),
24
+ flushAll: () => d.http.post(`${n}/cache/flush`, {}).then(() => {
25
+ })
26
+ };
27
+ }
28
+ const Be = {
29
+ module: {
30
+ title: "Menus"
31
+ },
32
+ menu: {
33
+ menus: "Menus",
34
+ "new-menu": "New menu",
35
+ "new-menu-title": "New menu",
36
+ "field-key": "Key",
37
+ "key-help": "What a template calls it by: menu('header').",
38
+ "field-name": "Name",
39
+ create: "Create",
40
+ cancel: "Cancel",
41
+ save: "Save",
42
+ rename: "Rename",
43
+ "rename-title": "Rename menu",
44
+ renamed: "Menu saved",
45
+ delete: "Delete",
46
+ "delete-menu-title": "Delete “:menu”?",
47
+ "delete-menu-text": "The menu goes, and every item in it. Nothing it points at is touched.",
48
+ deleted: "Menu deleted",
49
+ declared: "A template of this site asks for it",
50
+ "no-menus": "No menus yet.",
51
+ "no-menus-help": "A menu is declared in the configuration, or made here.",
52
+ "choose-menu": "Choose a menu",
53
+ "choose-menu-help": "Its items are arranged on the right.",
54
+ back: "Back",
55
+ "new-item": "New item",
56
+ "item-title": "Menu item",
57
+ "empty-tree": "Nothing in this menu yet.",
58
+ "empty-tree-help": "An item points at a page, at an address of your own, or at nothing.",
59
+ edit: "Edit",
60
+ duplicate: "Duplicate",
61
+ duplicated: "Item duplicated",
62
+ "delete-item-title": "Delete “:item”?",
63
+ "delete-item-text": "Only this item goes.",
64
+ "delete-item-branch": "Items that go with it: :count.",
65
+ "item-deleted": "Item deleted",
66
+ "item-saved": "Item saved",
67
+ "move-failed": "The item could not be moved.",
68
+ "untitled-item": "Untitled",
69
+ heading: "Heading",
70
+ "goes-nowhere": "Goes nowhere",
71
+ unavailable: "Not on the site",
72
+ hidden: "Hidden",
73
+ external: "An address off this site",
74
+ "new-tab": "Opens in a new tab",
75
+ "missing-target": "What this pointed at is gone",
76
+ "field-label": "Label",
77
+ "label-help": "Left empty, the item is called what the thing it points at is called.",
78
+ "field-where": "Where it goes",
79
+ "field-variant": "Look",
80
+ "field-heading": "A heading for the items under it",
81
+ "heading-help": "Drawn as a caption. It may still be a link.",
82
+ "field-visible": "Shown on the site",
83
+ "field-locales": "Languages",
84
+ "locales-all": "Every language",
85
+ "locales-help": "None chosen means every language.",
86
+ "cache-built": "Cache built",
87
+ "cache-empty": "Cache not built",
88
+ "cache-off": "Cache off",
89
+ flush: "Reset the cache of this menu",
90
+ "flush-all": "Reset every menu",
91
+ flushed: "Cache reset"
92
+ }
93
+ }, oe = /* @__PURE__ */ new WeakSet();
94
+ function j() {
95
+ try {
96
+ const { i18n: d } = G();
97
+ oe.has(d) || (d.defaults("webx-menu", Be), oe.add(d));
98
+ } catch {
99
+ }
100
+ }
101
+ const Se = /* @__PURE__ */ F({
102
+ name: "WxMenuCreateDialog",
103
+ __name: "MenuCreateDialog",
104
+ props: {
105
+ menu: { default: null }
106
+ },
107
+ setup(d) {
108
+ const n = d, { open: u, resolve: t, dismiss: l } = re(), a = G(), i = te(a);
109
+ j();
110
+ const o = K("webx-menu"), w = n.menu !== null, m = D(n.menu?.key ?? ""), v = D(n.menu?.title ?? ""), I = D(!1), f = D({}), b = _e("field");
111
+ ge(async () => {
112
+ await we(), b.value?.querySelector("input")?.focus();
113
+ });
114
+ async function z() {
115
+ if (!(v.value.trim() === "" || I.value)) {
116
+ I.value = !0, f.value = {};
117
+ try {
118
+ const $ = { key: m.value.trim(), title: v.value.trim() };
119
+ t(
120
+ w && n.menu !== null ? await i.update(n.menu.key, n.menu.can.rename ? $ : { title: $.title }) : await i.create($)
121
+ );
122
+ } catch ($) {
123
+ f.value = $.body?.errors ?? {};
124
+ } finally {
125
+ I.value = !1;
126
+ }
127
+ }
128
+ }
129
+ return ($, k) => (h(), g(e(de), {
130
+ open: e(u),
131
+ "onUpdate:open": k[3] || (k[3] = (T) => se(u) ? u.value = T : null),
132
+ title: w ? e(o)("menu.rename-title") : e(o)("menu.new-menu-title"),
133
+ width: 440
134
+ }, {
135
+ footer: r(() => [
136
+ p(e(me), { size: "sm" }, {
137
+ default: r(() => [
138
+ p(e(P), {
139
+ variant: "outline",
140
+ onClick: k[2] || (k[2] = (T) => e(l)())
141
+ }, {
142
+ default: r(() => [
143
+ V(R(e(o)("menu.cancel")), 1)
144
+ ]),
145
+ _: 1
146
+ }),
147
+ p(e(P), {
148
+ type: "primary",
149
+ loading: I.value,
150
+ disabled: v.value.trim() === "" || m.value.trim() === "",
151
+ onClick: z
152
+ }, {
153
+ default: r(() => [
154
+ V(R(w ? e(o)("menu.save") : e(o)("menu.create")), 1)
155
+ ]),
156
+ _: 1
157
+ }, 8, ["loading", "disabled"])
158
+ ]),
159
+ _: 1
160
+ })
161
+ ]),
162
+ default: r(() => [
163
+ p(e(E), {
164
+ label: e(o)("menu.field-name"),
165
+ error: f.value.title?.[0],
166
+ required: ""
167
+ }, {
168
+ default: r(() => [
169
+ q("div", {
170
+ ref_key: "field",
171
+ ref: b
172
+ }, [
173
+ p(e(X), {
174
+ modelValue: v.value,
175
+ "onUpdate:modelValue": k[0] || (k[0] = (T) => v.value = T),
176
+ "aria-label": e(o)("menu.field-name"),
177
+ onKeyup: le(z, ["enter"])
178
+ }, null, 8, ["modelValue", "aria-label"])
179
+ ], 512)
180
+ ]),
181
+ _: 1
182
+ }, 8, ["label", "error"]),
183
+ p(e(E), {
184
+ label: e(o)("menu.field-key"),
185
+ error: f.value.key?.[0],
186
+ help: e(o)("menu.key-help"),
187
+ required: ""
188
+ }, {
189
+ default: r(() => [
190
+ p(e(X), {
191
+ modelValue: m.value,
192
+ "onUpdate:modelValue": k[1] || (k[1] = (T) => m.value = T),
193
+ disabled: w && !n.menu?.can.rename,
194
+ "aria-label": e(o)("menu.field-key"),
195
+ onKeyup: le(z, ["enter"])
196
+ }, null, 8, ["modelValue", "disabled", "aria-label"])
197
+ ]),
198
+ _: 1
199
+ }, 8, ["label", "error", "help"])
200
+ ]),
201
+ _: 1
202
+ }, 8, ["open", "title"]));
203
+ }
204
+ }), Ae = ["disabled", "onClick"], Ee = { class: "wx-menu-item__line" }, Oe = /* @__PURE__ */ F({
205
+ name: "WxMenuBranch",
206
+ __name: "MenuBranch",
207
+ props: {
208
+ items: {},
209
+ parentId: { default: null },
210
+ disabled: { type: Boolean, default: !1 }
211
+ },
212
+ emits: ["reorder", "edit", "duplicate", "remove"],
213
+ setup(d, { emit: n }) {
214
+ const u = d, t = n, l = K("webx-menu");
215
+ function a(m) {
216
+ return m.label === "" ? l("menu.untitled-item") : m.label;
217
+ }
218
+ function i(m) {
219
+ return m.target === "none" ? l("menu.goes-nowhere") : m.target === "entity" && m.resolved === null ? l("menu.missing-target") : m.href ?? l("menu.goes-nowhere");
220
+ }
221
+ function o(m) {
222
+ return m.target === "url" && /^[a-z][a-z0-9+.-]*:/i.test(m.url ?? "");
223
+ }
224
+ function w(m) {
225
+ return u.disabled ? [] : [
226
+ { key: "edit", icon: "edit", label: l("menu.edit"), run: () => t("edit", m) },
227
+ {
228
+ key: "duplicate",
229
+ icon: "copy",
230
+ label: l("menu.duplicate"),
231
+ run: () => t("duplicate", m)
232
+ },
233
+ {
234
+ key: "delete",
235
+ icon: "trash",
236
+ label: l("menu.delete"),
237
+ danger: !0,
238
+ run: () => t("remove", m)
239
+ }
240
+ ];
241
+ }
242
+ return (m, v) => {
243
+ const I = ke("wx-menu-branch");
244
+ return h(), g(e(We), {
245
+ class: Q(["wx-menu-branch", { "is-nested": u.parentId !== null }]),
246
+ "model-value": u.items,
247
+ plain: "",
248
+ size: "sm",
249
+ group: "wx-menu-items",
250
+ "item-key": "id",
251
+ "item-label": a,
252
+ disabled: u.disabled,
253
+ "empty-text": "",
254
+ "onUpdate:modelValue": v[4] || (v[4] = (f) => t("reorder", u.parentId, f))
255
+ }, xe({
256
+ empty: r(() => [
257
+ v[5] || (v[5] = q("span", { class: "wx-menu-branch__drop" }, null, -1))
258
+ ]),
259
+ default: r(({ item: f }) => [
260
+ q("div", {
261
+ class: Q(["wx-menu-item", { "is-off": !f.visible || !f.available }])
262
+ }, [
263
+ q("button", {
264
+ type: "button",
265
+ class: "wx-menu-item__open",
266
+ disabled: u.disabled,
267
+ onClick: (b) => t("edit", f)
268
+ }, [
269
+ q("span", Ee, [
270
+ p(e(N), {
271
+ truncate: "",
272
+ weight: f.is_heading ? "semibold" : "medium"
273
+ }, {
274
+ default: r(() => [
275
+ V(R(a(f)), 1)
276
+ ]),
277
+ _: 2
278
+ }, 1032, ["weight"]),
279
+ o(f) ? (h(), g(e(ue), {
280
+ key: 0,
281
+ content: e(l)("menu.external")
282
+ }, {
283
+ default: r(() => [
284
+ p(e(Y), {
285
+ class: "wx-menu-item__mark",
286
+ name: "link",
287
+ label: e(l)("menu.external")
288
+ }, null, 8, ["label"])
289
+ ]),
290
+ _: 1
291
+ }, 8, ["content"])) : B("", !0),
292
+ f.new_tab ? (h(), g(e(ue), {
293
+ key: 1,
294
+ content: e(l)("menu.new-tab")
295
+ }, {
296
+ default: r(() => [
297
+ p(e(Y), {
298
+ class: "wx-menu-item__mark",
299
+ name: "external-link",
300
+ label: e(l)("menu.new-tab")
301
+ }, null, 8, ["label"])
302
+ ]),
303
+ _: 1
304
+ }, 8, ["content"])) : B("", !0)
305
+ ]),
306
+ p(e(N), {
307
+ size: "sm",
308
+ tone: "muted",
309
+ truncate: ""
310
+ }, {
311
+ default: r(() => [
312
+ f.is_heading ? (h(), O(H, { key: 0 }, [
313
+ V(R(e(l)("menu.heading")), 1)
314
+ ], 64)) : (h(), O(H, { key: 1 }, [
315
+ V(R(i(f)), 1)
316
+ ], 64))
317
+ ]),
318
+ _: 2
319
+ }, 1024)
320
+ ], 8, Ae),
321
+ f.visible ? f.available ? B("", !0) : (h(), g(e(N), {
322
+ key: 1,
323
+ class: "wx-menu-item__state",
324
+ size: "sm",
325
+ tone: "warning"
326
+ }, {
327
+ default: r(() => [
328
+ V(R(e(l)("menu.unavailable")), 1)
329
+ ]),
330
+ _: 1
331
+ })) : (h(), g(e(N), {
332
+ key: 0,
333
+ class: "wx-menu-item__state",
334
+ size: "sm",
335
+ tone: "muted"
336
+ }, {
337
+ default: r(() => [
338
+ V(R(e(l)("menu.hidden")), 1)
339
+ ]),
340
+ _: 1
341
+ }))
342
+ ], 2),
343
+ p(I, {
344
+ items: f.children,
345
+ "parent-id": f.id,
346
+ disabled: u.disabled,
347
+ onReorder: v[0] || (v[0] = (b, z) => t("reorder", b, z)),
348
+ onEdit: v[1] || (v[1] = (b) => t("edit", b)),
349
+ onDuplicate: v[2] || (v[2] = (b) => t("duplicate", b)),
350
+ onRemove: v[3] || (v[3] = (b) => t("remove", b))
351
+ }, null, 8, ["items", "parent-id", "disabled"])
352
+ ]),
353
+ _: 2
354
+ }, [
355
+ u.disabled ? void 0 : {
356
+ name: "actions",
357
+ fn: r(({ item: f }) => [
358
+ p(e(he), {
359
+ actions: w(f),
360
+ label: a(f)
361
+ }, null, 8, ["actions", "label"])
362
+ ]),
363
+ key: "0"
364
+ }
365
+ ]), 1032, ["class", "model-value", "disabled"]);
366
+ };
367
+ }
368
+ }), ne = (d, n) => {
369
+ const u = d.__vccOpts || d;
370
+ for (const [t, l] of n)
371
+ u[t] = l;
372
+ return u;
373
+ }, Pe = /* @__PURE__ */ ne(Oe, [["__scopeId", "data-v-4551b4d6"]]), Fe = /* @__PURE__ */ F({
374
+ name: "WxMenuItemDialog",
375
+ __name: "MenuItemDialog",
376
+ props: {
377
+ menu: {},
378
+ item: { default: null }
379
+ },
380
+ setup(d) {
381
+ const n = d, { open: u, resolve: t, dismiss: l } = re(), a = Me();
382
+ j();
383
+ const i = K("webx-menu"), o = D(n.item === null ? Te() : k(n.item)), w = D({ ...n.item?.title ?? {} }), m = D(n.item?.variant ?? n.menu.variants[0] ?? "link"), v = D(n.item?.is_heading ?? !1), I = D(n.item?.visible ?? !0), f = D([...n.item?.locales ?? []]), b = S(() => n.item?.resolved?.title ?? ""), z = S(
384
+ () => n.menu.variants.map((C) => ({ value: C, label: C }))
385
+ ), $ = S(
386
+ () => a.list.value.map((C) => ({ value: C.code, label: C.label ?? C.code }))
387
+ );
388
+ function k(C) {
389
+ return {
390
+ target: C.target,
391
+ entity_type: C.entity_type,
392
+ entity_id: C.entity_id,
393
+ url: C.url,
394
+ hash: C.hash,
395
+ new_tab: C.new_tab,
396
+ rel: C.rel
397
+ };
398
+ }
399
+ function T() {
400
+ t({
401
+ title: w.value,
402
+ link: o.value,
403
+ variant: m.value,
404
+ is_heading: v.value,
405
+ locales: f.value,
406
+ visible: I.value
407
+ });
408
+ }
409
+ return (C, x) => (h(), g(e(de), {
410
+ open: e(u),
411
+ "onUpdate:open": x[7] || (x[7] = (W) => se(u) ? u.value = W : null),
412
+ title: e(i)("menu.item-title"),
413
+ width: 520
414
+ }, {
415
+ footer: r(() => [
416
+ p(e(me), { size: "sm" }, {
417
+ default: r(() => [
418
+ p(e(P), {
419
+ variant: "outline",
420
+ onClick: x[6] || (x[6] = (W) => e(l)())
421
+ }, {
422
+ default: r(() => [
423
+ V(R(e(i)("menu.cancel")), 1)
424
+ ]),
425
+ _: 1
426
+ }),
427
+ p(e(P), {
428
+ type: "primary",
429
+ onClick: T
430
+ }, {
431
+ default: r(() => [
432
+ V(R(e(i)("menu.save")), 1)
433
+ ]),
434
+ _: 1
435
+ })
436
+ ]),
437
+ _: 1
438
+ })
439
+ ]),
440
+ default: r(() => [
441
+ p(e(E), {
442
+ label: e(i)("menu.field-where")
443
+ }, {
444
+ default: r(() => [
445
+ p(e(Le), {
446
+ modelValue: o.value,
447
+ "onUpdate:modelValue": x[0] || (x[0] = (W) => o.value = W)
448
+ }, null, 8, ["modelValue"])
449
+ ]),
450
+ _: 1
451
+ }, 8, ["label"]),
452
+ p(e(E), {
453
+ label: e(i)("menu.field-label"),
454
+ help: e(i)("menu.label-help")
455
+ }, {
456
+ default: r(() => [
457
+ p(e(X), {
458
+ modelValue: w.value,
459
+ "onUpdate:modelValue": x[1] || (x[1] = (W) => w.value = W),
460
+ localized: "",
461
+ placeholder: b.value,
462
+ "aria-label": e(i)("menu.field-label")
463
+ }, null, 8, ["modelValue", "placeholder", "aria-label"])
464
+ ]),
465
+ _: 1
466
+ }, 8, ["label", "help"]),
467
+ z.value.length > 1 ? (h(), g(e(E), {
468
+ key: 0,
469
+ label: e(i)("menu.field-variant")
470
+ }, {
471
+ default: r(() => [
472
+ p(e(ie), {
473
+ modelValue: m.value,
474
+ "onUpdate:modelValue": x[2] || (x[2] = (W) => m.value = W),
475
+ options: z.value,
476
+ "aria-label": e(i)("menu.field-variant")
477
+ }, null, 8, ["modelValue", "options", "aria-label"])
478
+ ]),
479
+ _: 1
480
+ }, 8, ["label"])) : B("", !0),
481
+ $.value.length > 1 ? (h(), g(e(E), {
482
+ key: 1,
483
+ label: e(i)("menu.field-locales"),
484
+ help: e(i)("menu.locales-help")
485
+ }, {
486
+ default: r(() => [
487
+ p(e(ie), {
488
+ modelValue: f.value,
489
+ "onUpdate:modelValue": x[3] || (x[3] = (W) => f.value = W),
490
+ options: $.value,
491
+ multiple: "",
492
+ clearable: "",
493
+ placeholder: e(i)("menu.locales-all"),
494
+ "aria-label": e(i)("menu.field-locales")
495
+ }, null, 8, ["modelValue", "options", "placeholder", "aria-label"])
496
+ ]),
497
+ _: 1
498
+ }, 8, ["label", "help"])) : B("", !0),
499
+ p(e(E), {
500
+ help: e(i)("menu.heading-help")
501
+ }, {
502
+ default: r(() => [
503
+ p(e(Ve), {
504
+ modelValue: v.value,
505
+ "onUpdate:modelValue": x[4] || (x[4] = (W) => v.value = W)
506
+ }, {
507
+ default: r(() => [
508
+ V(R(e(i)("menu.field-heading")), 1)
509
+ ]),
510
+ _: 1
511
+ }, 8, ["modelValue"])
512
+ ]),
513
+ _: 1
514
+ }, 8, ["help"]),
515
+ p(e(E), null, {
516
+ default: r(() => [
517
+ p(e(Re), {
518
+ modelValue: I.value,
519
+ "onUpdate:modelValue": x[5] || (x[5] = (W) => I.value = W),
520
+ label: e(i)("menu.field-visible")
521
+ }, null, 8, ["modelValue", "label"])
522
+ ]),
523
+ _: 1
524
+ })
525
+ ]),
526
+ _: 1
527
+ }, 8, ["open", "title"]));
528
+ }
529
+ });
530
+ function ee(d, n) {
531
+ for (const u of d) {
532
+ if (u.id === n) return u;
533
+ const t = ee(u.children, n);
534
+ if (t !== null) return t;
535
+ }
536
+ return null;
537
+ }
538
+ function be(d) {
539
+ return d.children.reduce((n, u) => n + 1 + be(u), 0);
540
+ }
541
+ function Ke(d, n) {
542
+ const u = n.find((t) => !d.includes(t));
543
+ if (u !== void 0) return u;
544
+ if (n.length !== d.length) return null;
545
+ for (const t of n) {
546
+ if (n.indexOf(t) === d.indexOf(t)) continue;
547
+ const l = n.filter((i) => i !== t), a = d.filter((i) => i !== t);
548
+ if (l.length === a.length && l.every((i, o) => i === a[o]))
549
+ return t;
550
+ }
551
+ return null;
552
+ }
553
+ const He = { class: "wx-menu-pane" }, Ge = { class: "wx-menu-pane__head" }, je = { class: "wx-menu-pane__name" }, Je = { class: "wx-menu-pane__body" }, Qe = /* @__PURE__ */ F({
554
+ name: "WxMenuTreePane",
555
+ __name: "MenuTreePane",
556
+ props: {
557
+ menu: {},
558
+ inline: { type: Boolean, default: !0 },
559
+ back: { type: Function, default: void 0 }
560
+ },
561
+ emits: ["changed"],
562
+ setup(d, { expose: n, emit: u }) {
563
+ const t = d, l = u, a = G(), i = te(a);
564
+ j();
565
+ const o = K("webx-menu"), w = ye(), m = D([]), v = D(!0), I = S(() => a.can("menu.manage")), f = ce(Fe);
566
+ async function b() {
567
+ v.value = !0;
568
+ try {
569
+ m.value = await i.items(t.menu.key);
570
+ } catch (s) {
571
+ M.danger(w(s));
572
+ } finally {
573
+ v.value = !1;
574
+ }
575
+ }
576
+ b();
577
+ function z(s) {
578
+ return s === null ? m.value : ee(m.value, s)?.children ?? [];
579
+ }
580
+ function $(s, _) {
581
+ if (s === null) {
582
+ m.value = _;
583
+ return;
584
+ }
585
+ const L = ee(m.value, s);
586
+ L !== null && (L.children = _);
587
+ }
588
+ async function k(s, _) {
589
+ const L = z(s).map((U) => U.id);
590
+ $(s, _);
591
+ const A = _.map((U) => U.id), c = Ke(L, A);
592
+ if (c !== null)
593
+ try {
594
+ await i.moveItem(t.menu.key, c, s, A.indexOf(c)), l("changed");
595
+ } catch (U) {
596
+ M.danger(w(U, o("menu.move-failed"))), await b();
597
+ }
598
+ }
599
+ async function T() {
600
+ const s = await f({ menu: t.menu, item: null });
601
+ if (s)
602
+ try {
603
+ await i.addItem(t.menu.key, s), M.success(o("menu.item-saved")), await b(), l("changed");
604
+ } catch (_) {
605
+ M.danger(w(_));
606
+ }
607
+ }
608
+ async function C(s) {
609
+ const _ = await f({ menu: t.menu, item: s });
610
+ if (_)
611
+ try {
612
+ await i.saveItem(t.menu.key, s.id, _), M.success(o("menu.item-saved")), await b(), l("changed");
613
+ } catch (L) {
614
+ M.danger(w(L));
615
+ }
616
+ }
617
+ async function x(s) {
618
+ try {
619
+ const _ = await i.addItem(t.menu.key, {
620
+ title: s.title,
621
+ link: {
622
+ target: s.target,
623
+ entity_type: s.entity_type,
624
+ entity_id: s.entity_id,
625
+ url: s.url,
626
+ hash: s.hash,
627
+ new_tab: s.new_tab,
628
+ rel: s.rel
629
+ },
630
+ variant: s.variant,
631
+ is_heading: s.is_heading,
632
+ locales: s.locales,
633
+ visible: s.visible,
634
+ parent_id: s.parent_id
635
+ }), L = z(s.parent_id);
636
+ await i.moveItem(
637
+ t.menu.key,
638
+ _.id,
639
+ s.parent_id,
640
+ L.findIndex((A) => A.id === s.id) + 1
641
+ ), M.success(o("menu.duplicated")), await b(), l("changed");
642
+ } catch (_) {
643
+ M.danger(w(_));
644
+ }
645
+ }
646
+ async function W(s) {
647
+ const _ = be(s);
648
+ if (await ve({
649
+ title: o("menu.delete-item-title", { item: s.label || o("menu.untitled-item") }),
650
+ message: _ === 0 ? o("menu.delete-item-text") : o("menu.delete-item-branch", { count: _ }),
651
+ confirmText: o("menu.delete"),
652
+ cancelText: o("menu.cancel"),
653
+ tone: "danger"
654
+ }))
655
+ try {
656
+ await i.removeItem(t.menu.key, s.id), M.success(o("menu.item-deleted")), await b(), l("changed");
657
+ } catch (A) {
658
+ M.danger(w(A));
659
+ }
660
+ }
661
+ return n({ reload: b }), (s, _) => (h(), O("div", He, [
662
+ q("header", Ge, [
663
+ t.inline ? B("", !0) : (h(), g(e(pe), {
664
+ key: 0,
665
+ icon: "arrow-left",
666
+ size: "sm",
667
+ title: e(o)("menu.back"),
668
+ onClick: _[0] || (_[0] = (L) => t.back?.())
669
+ }, null, 8, ["title"])),
670
+ q("div", je, [
671
+ p(e(N), {
672
+ weight: "semibold",
673
+ truncate: ""
674
+ }, {
675
+ default: r(() => [
676
+ V(R(t.menu.title), 1)
677
+ ]),
678
+ _: 1
679
+ }),
680
+ p(e(N), {
681
+ size: "sm",
682
+ tone: "muted",
683
+ mono: "",
684
+ truncate: ""
685
+ }, {
686
+ default: r(() => [
687
+ V(R(t.menu.key), 1)
688
+ ]),
689
+ _: 1
690
+ })
691
+ ]),
692
+ I.value ? (h(), g(e(P), {
693
+ key: 1,
694
+ variant: "outline",
695
+ size: "sm",
696
+ onClick: T
697
+ }, {
698
+ icon: r(() => [
699
+ p(e(Y), { name: "plus" })
700
+ ]),
701
+ default: r(() => [
702
+ V(" " + R(e(o)("menu.new-item")), 1)
703
+ ]),
704
+ _: 1
705
+ })) : B("", !0)
706
+ ]),
707
+ q("div", Je, [
708
+ v.value ? (h(), g(e(fe), {
709
+ key: 0,
710
+ rows: 5
711
+ })) : m.value.length === 0 ? (h(), g(e(Z), {
712
+ key: 1,
713
+ title: e(o)("menu.empty-tree"),
714
+ description: e(o)("menu.empty-tree-help")
715
+ }, null, 8, ["title", "description"])) : (h(), g(Pe, {
716
+ key: 2,
717
+ items: m.value,
718
+ disabled: !I.value,
719
+ onReorder: k,
720
+ onEdit: C,
721
+ onDuplicate: x,
722
+ onRemove: W
723
+ }, null, 8, ["items", "disabled"]))
724
+ ])
725
+ ]));
726
+ }
727
+ }), Xe = /* @__PURE__ */ ne(Qe, [["__scopeId", "data-v-7c72f6db"]]), Ye = {
728
+ key: 2,
729
+ class: "wx-menus__list"
730
+ }, Ze = ["onClick"], et = { class: "wx-menus__name" }, tt = { class: "wx-menus__cache" }, nt = /* @__PURE__ */ F({
731
+ __name: "MenusPage",
732
+ setup(d) {
733
+ const n = G(), u = te(n), t = Ie(), l = $e();
734
+ j();
735
+ const a = K("webx-menu"), i = ye(), o = D([]), w = D(!0), m = D(!1), v = D(!0), I = S(() => n.can("menu.manage")), f = ce(Se), b = S(
736
+ () => n.state.manifest?.modules.find((c) => c.id === "menu")?.title ?? a("module.title")
737
+ ), z = S(() => {
738
+ const c = t.query.menu;
739
+ return typeof c == "string" && c !== "" ? c : null;
740
+ }), $ = S(() => o.value.find((c) => c.key === z.value) ?? null);
741
+ async function k() {
742
+ w.value = !0;
743
+ try {
744
+ o.value = await u.list();
745
+ } catch (c) {
746
+ M.danger(i(c));
747
+ } finally {
748
+ w.value = !1;
749
+ }
750
+ }
751
+ k(), ae([o, $, v], () => {
752
+ !v.value || o.value.length === 0 || $.value !== null || l.replace({ query: { ...t.query, menu: o.value[0].key } });
753
+ }), ae($, (c) => {
754
+ c !== null && v.value && (m.value = !0);
755
+ });
756
+ function T(c) {
757
+ l.replace({ query: { ...t.query, menu: c.key } }), m.value = !0;
758
+ }
759
+ async function C() {
760
+ const c = await f({ menu: null });
761
+ c && (await k(), T(c));
762
+ }
763
+ async function x(c) {
764
+ const U = await f({ menu: c });
765
+ U && (M.success(a("menu.renamed")), z.value === c.key && U.key !== c.key && l.replace({ query: { ...t.query, menu: U.key } }), await k());
766
+ }
767
+ async function W(c) {
768
+ if (await ve({
769
+ title: a("menu.delete-menu-title", { menu: c.title }),
770
+ message: a("menu.delete-menu-text"),
771
+ confirmText: a("menu.delete"),
772
+ cancelText: a("menu.cancel"),
773
+ tone: "danger"
774
+ }))
775
+ try {
776
+ if (await u.remove(c.key), M.success(a("menu.deleted")), z.value === c.key) {
777
+ const y = { ...t.query };
778
+ delete y.menu, l.replace({ query: y }), m.value = !1;
779
+ }
780
+ await k();
781
+ } catch (y) {
782
+ M.danger(i(y));
783
+ }
784
+ }
785
+ async function s(c) {
786
+ try {
787
+ await u.flush(c.key), M.success(a("menu.flushed")), await k();
788
+ } catch (U) {
789
+ M.danger(i(U));
790
+ }
791
+ }
792
+ async function _() {
793
+ try {
794
+ await u.flushAll(), M.success(a("menu.flushed")), await k();
795
+ } catch (c) {
796
+ M.danger(i(c));
797
+ }
798
+ }
799
+ function L(c) {
800
+ return I.value ? [
801
+ { key: "rename", icon: "edit", label: a("menu.rename"), run: () => {
802
+ x(c);
803
+ } },
804
+ { key: "flush", icon: "refresh", label: a("menu.flush"), run: () => {
805
+ s(c);
806
+ } },
807
+ ...c.can.delete ? [
808
+ {
809
+ key: "delete",
810
+ icon: "trash",
811
+ label: a("menu.delete"),
812
+ danger: !0,
813
+ run: () => {
814
+ W(c);
815
+ }
816
+ }
817
+ ] : []
818
+ ] : [];
819
+ }
820
+ const A = S(() => I.value ? [
821
+ {
822
+ key: "flush-all",
823
+ label: a("menu.flush-all"),
824
+ icon: "refresh",
825
+ menu: !0,
826
+ run: () => {
827
+ _();
828
+ }
829
+ },
830
+ {
831
+ key: "new-menu",
832
+ label: a("menu.new-menu"),
833
+ icon: "plus",
834
+ primary: !0,
835
+ run: () => {
836
+ C();
837
+ }
838
+ }
839
+ ] : []);
840
+ return (c, U) => (h(), g(e(Ne), {
841
+ title: b.value,
842
+ actions: A.value,
843
+ card: !1
844
+ }, {
845
+ default: r(() => [
846
+ p(e(Ue), {
847
+ class: "wx-menus",
848
+ padding: "none"
849
+ }, {
850
+ default: r(() => [
851
+ p(e(ze), {
852
+ open: m.value,
853
+ "onUpdate:open": U[0] || (U[0] = (y) => m.value = y),
854
+ class: "wx-menus__panes",
855
+ "list-width": 320,
856
+ "detail-min": 420,
857
+ "detail-label": e(a)("menu.menus"),
858
+ onDetailInline: U[1] || (U[1] = (y) => v.value = y)
859
+ }, {
860
+ list: r(() => [
861
+ w.value ? (h(), g(e(fe), {
862
+ key: 0,
863
+ class: "wx-menus__loading",
864
+ rows: 4
865
+ })) : o.value.length === 0 ? (h(), g(e(Z), {
866
+ key: 1,
867
+ title: e(a)("menu.no-menus"),
868
+ description: e(a)("menu.no-menus-help")
869
+ }, null, 8, ["title", "description"])) : (h(), O("ul", Ye, [
870
+ (h(!0), O(H, null, Ce(o.value, (y) => (h(), O("li", {
871
+ key: y.key,
872
+ class: "wx-menus__row"
873
+ }, [
874
+ q("button", {
875
+ type: "button",
876
+ class: Q(["wx-menus__open", { "is-current": y.key === z.value }]),
877
+ onClick: (J) => T(y)
878
+ }, [
879
+ q("span", et, [
880
+ p(e(N), {
881
+ truncate: "",
882
+ weight: "medium"
883
+ }, {
884
+ default: r(() => [
885
+ V(R(y.title), 1)
886
+ ]),
887
+ _: 2
888
+ }, 1024),
889
+ p(e(De), {
890
+ class: "wx-menus__count",
891
+ type: "neutral",
892
+ value: y.items_count,
893
+ label: e(a)("menu.menus")
894
+ }, null, 8, ["value", "label"])
895
+ ]),
896
+ p(e(N), {
897
+ size: "sm",
898
+ tone: "muted",
899
+ mono: "",
900
+ truncate: ""
901
+ }, {
902
+ default: r(() => [
903
+ V(R(y.key), 1)
904
+ ]),
905
+ _: 2
906
+ }, 1024),
907
+ q("span", tt, [
908
+ y.cache.enabled ? y.cache.built_at !== null ? (h(), O(H, { key: 1 }, [
909
+ p(e(N), {
910
+ size: "sm",
911
+ tone: "muted"
912
+ }, {
913
+ default: r(() => [
914
+ V(R(e(a)("menu.cache-built")), 1)
915
+ ]),
916
+ _: 1
917
+ }),
918
+ p(e(qe), {
919
+ value: y.cache.built_at
920
+ }, null, 8, ["value"])
921
+ ], 64)) : (h(), g(e(N), {
922
+ key: 2,
923
+ size: "sm",
924
+ tone: "muted"
925
+ }, {
926
+ default: r(() => [
927
+ V(R(e(a)("menu.cache-empty")), 1)
928
+ ]),
929
+ _: 1
930
+ })) : (h(), g(e(N), {
931
+ key: 0,
932
+ size: "sm",
933
+ tone: "muted"
934
+ }, {
935
+ default: r(() => [
936
+ V(R(e(a)("menu.cache-off")), 1)
937
+ ]),
938
+ _: 1
939
+ }))
940
+ ])
941
+ ], 10, Ze),
942
+ I.value && y.cache.enabled ? (h(), g(e(pe), {
943
+ key: 0,
944
+ class: "wx-menus__flush",
945
+ icon: "refresh",
946
+ size: "sm",
947
+ title: e(a)("menu.flush"),
948
+ onClick: (J) => s(y)
949
+ }, null, 8, ["title", "onClick"])) : B("", !0),
950
+ I.value ? (h(), g(e(he), {
951
+ key: 1,
952
+ actions: L(y),
953
+ label: y.title
954
+ }, null, 8, ["actions", "label"])) : B("", !0)
955
+ ]))), 128))
956
+ ]))
957
+ ]),
958
+ detail: r(({ inline: y, back: J }) => [
959
+ $.value ? (h(), g(Xe, {
960
+ key: $.value.key,
961
+ menu: $.value,
962
+ inline: y,
963
+ back: J,
964
+ onChanged: k
965
+ }, null, 8, ["menu", "inline", "back"])) : B("", !0)
966
+ ]),
967
+ empty: r(() => [
968
+ p(e(Z), {
969
+ title: e(a)("menu.choose-menu"),
970
+ description: e(a)("menu.choose-menu-help")
971
+ }, null, 8, ["title", "description"])
972
+ ]),
973
+ _: 1
974
+ }, 8, ["open", "detail-label"])
975
+ ]),
976
+ _: 1
977
+ })
978
+ ]),
979
+ _: 1
980
+ }, 8, ["title", "actions"]));
981
+ }
982
+ }), lt = /* @__PURE__ */ ne(nt, [["__scopeId", "data-v-63e1d3fa"]]);
983
+ function st(d = {}) {
984
+ const n = d.path ?? "/menus";
985
+ return {
986
+ id: "menu",
987
+ path: n,
988
+ routes: [{ path: n, name: "webx.menus", component: lt }]
989
+ };
990
+ }
991
+ export {
992
+ Pe as WxMenuBranch,
993
+ Se as WxMenuCreateDialog,
994
+ Fe as WxMenuItemDialog,
995
+ Xe as WxMenuTreePane,
996
+ lt as WxMenusPage,
997
+ be as countBranch,
998
+ te as createMenusApi,
999
+ ee as findItem,
1000
+ st as menu,
1001
+ Be as menuMessages,
1002
+ Ke as movedId
1003
+ };
1004
+ //# sourceMappingURL=index.js.map