@webx-ui/module-admin 0.3.0 → 0.4.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 CHANGED
@@ -1,64 +1,93 @@
1
- import { inject as C, reactive as T, computed as A, defineComponent as O, resolveComponent as v, openBlock as _, createBlock as U, unref as d, withCtx as g, createElementBlock as x, Fragment as j, renderList as z, ref as M, createVNode as w, createTextVNode as R, toDisplayString as N, renderSlot as L, createCommentVNode as G, isRef as J, createApp as Q, h as k } from "vue";
2
- import { useRouter as Y, useRoute as Z, createRouter as ee, createWebHistory as te } from "vue-router";
3
- import { useResponsiveShell as ne, WxToaster as ae, WebxUI as oe, localesKey as se } from "@webx-ui/core";
4
- const D = /* @__PURE__ */ Symbol("webx-admin");
5
- function H() {
6
- const e = C(D, null);
1
+ import { inject as R, reactive as C, computed as k, defineComponent as M, resolveComponent as y, openBlock as w, createBlock as S, unref as d, withCtx as x, createElementBlock as _, Fragment as U, renderList as P, ref as T, createVNode as b, createTextVNode as I, toDisplayString as W, renderSlot as $, createCommentVNode as J, isRef as Q, createApp as Y, h as A, useModel as Z, watch as ee, mergeModels as D } from "vue";
2
+ import { useRouter as te, useRoute as ne, createRouter as ae, createWebHistory as le } from "vue-router";
3
+ import { useResponsiveShell as oe, WxToaster as se, WebxUI as re, localesKey as ie, WxAlert as ce, WxSkeleton as ue } from "@webx-ui/core";
4
+ import { WxScreenRenderer as de } from "@webx-ui/schema";
5
+ const F = /* @__PURE__ */ Symbol("webx-admin");
6
+ function N() {
7
+ const e = R(F, null);
7
8
  if (e === null)
8
9
  throw new Error("useAdmin() was called outside a panel created by createAdmin().");
9
10
  return e;
10
11
  }
11
- function le(e) {
12
- const t = T({
12
+ function fe(e) {
13
+ const n = C({
13
14
  status: "loading",
14
15
  manifest: null,
15
16
  user: null,
16
17
  error: null
17
- }), n = A(() => {
18
- const s = t.manifest;
19
- if (s === null)
18
+ }), o = k(() => {
19
+ const t = n.manifest;
20
+ if (t === null)
20
21
  return [];
21
- const o = [];
22
- for (const l of s.modules) {
23
- const a = e.modules.find((i) => i.id === l.id);
24
- if (a === void 0)
22
+ const a = [];
23
+ for (const c of t.modules) {
24
+ const s = e.modules.find((h) => h.id === c.id);
25
+ if (s === void 0)
25
26
  continue;
26
- const r = a.path ?? a.routes?.[0]?.path;
27
- r !== void 0 && o.push({
28
- id: l.id,
29
- title: l.title,
30
- icon: l.icon,
31
- path: r
27
+ const v = s.path ?? s.routes?.[0]?.path;
28
+ v !== void 0 && a.push({
29
+ id: c.id,
30
+ title: c.title,
31
+ icon: c.icon,
32
+ path: v,
33
+ group: c.group ?? null
32
34
  });
33
35
  }
34
- return o;
35
- });
36
- let c = null;
37
- async function u() {
38
- t.status = "loading", t.error = null;
36
+ return a;
37
+ }), u = k(() => {
38
+ const t = n.manifest?.groups ?? [], a = [], c = /* @__PURE__ */ new Map();
39
+ for (const s of o.value)
40
+ if (s.group !== null && t.some((v) => v.id === s.group)) {
41
+ const v = c.get(s.group) ?? [];
42
+ v.push(s), c.set(s.group, v);
43
+ } else
44
+ a.push(s);
45
+ return {
46
+ top: a,
47
+ groups: t.filter((s) => c.has(s.id)).map((s) => ({
48
+ id: s.id,
49
+ title: s.title,
50
+ entries: c.get(s.id) ?? []
51
+ }))
52
+ };
53
+ }), f = {};
54
+ for (const t of e.modules)
55
+ Object.assign(f, t.types);
56
+ Object.assign(f, e.types);
57
+ const m = /* @__PURE__ */ new Map();
58
+ async function p(t) {
59
+ const a = `${e.i18n.state.locale}:${t}`;
60
+ let c = m.get(a);
61
+ return c === void 0 && (c = e.http.get(`${e.apiPath}/screens/${t}`).then((s) => s.data.root).catch((s) => {
62
+ throw m.delete(a), s;
63
+ }), m.set(a, c)), c;
64
+ }
65
+ let r = null;
66
+ async function i() {
67
+ n.status = "loading", n.error = null;
39
68
  try {
40
- if (c !== null && (t.user = await c(), t.user === null)) {
41
- t.manifest = null, t.status = "unauthenticated";
69
+ if (r !== null && (n.user = await r(), n.user === null)) {
70
+ n.manifest = null, n.status = "unauthenticated";
42
71
  return;
43
72
  }
44
- const s = await e.loadManifest();
45
- t.manifest = s, e.i18n.state.contentLocales = s.locales ?? [], e.i18n.state.panelLocales = s.panelLocales ?? e.i18n.state.panelLocales, s.locale !== void 0 && s.locale !== e.i18n.state.locale && await f(s.locale), t.status = "ready";
46
- } catch (s) {
47
- if (ie(s)) {
48
- t.manifest = null, t.user = null, t.status = "unauthenticated";
73
+ const t = await e.loadManifest();
74
+ n.manifest = t, e.i18n.state.contentLocales = t.locales ?? [], e.i18n.state.panelLocales = t.panelLocales ?? e.i18n.state.panelLocales, t.locale !== void 0 && t.locale !== e.i18n.state.locale && await l(t.locale), n.status = "ready";
75
+ } catch (t) {
76
+ if (pe(t)) {
77
+ n.manifest = null, n.user = null, n.status = "unauthenticated";
49
78
  return;
50
79
  }
51
- t.error = s instanceof Error ? s.message : String(s), t.status = "error";
80
+ n.error = t instanceof Error ? t.message : String(t), n.status = "error";
52
81
  }
53
82
  }
54
- async function f(s) {
83
+ async function l(t) {
55
84
  if (e.loadDictionary === void 0) {
56
- e.i18n.state.locale = s;
85
+ e.i18n.state.locale = t;
57
86
  return;
58
87
  }
59
- if (await e.loadDictionary(s), t.manifest !== null)
88
+ if (await e.loadDictionary(t), n.manifest !== null)
60
89
  try {
61
- t.manifest = await e.loadManifest();
90
+ n.manifest = await e.loadManifest();
62
91
  } catch {
63
92
  }
64
93
  }
@@ -66,187 +95,209 @@ function le(e) {
66
95
  http: e.http,
67
96
  basePath: e.basePath,
68
97
  apiPath: e.apiPath,
69
- state: t,
98
+ state: n,
70
99
  i18n: e.i18n,
71
100
  modules: e.modules,
72
- nav: n,
73
- reload: u,
74
- setLocale: f,
75
- setUser(s) {
76
- t.user = s;
101
+ nav: o,
102
+ groups: u,
103
+ types: f,
104
+ reload: i,
105
+ setLocale: l,
106
+ setUser(t) {
107
+ n.user = t;
108
+ },
109
+ useSessionLoader(t) {
110
+ r = t;
77
111
  },
78
- useSessionLoader(s) {
79
- c = s;
112
+ can(t) {
113
+ const a = n.user;
114
+ return a === null ? !1 : a.isSuper || a.permissions.includes(t);
80
115
  },
81
- can(s) {
82
- const o = t.user;
83
- return o === null ? !1 : o.isSuper || o.permissions.includes(s);
116
+ loadScreen: p,
117
+ screenPatch(t) {
118
+ return e.screens?.[t] ?? [];
84
119
  }
85
120
  };
86
121
  }
87
- function re(e, t) {
88
- e.provide(D, t);
122
+ function me(e, n) {
123
+ e.provide(F, n);
89
124
  }
90
- function ie(e) {
125
+ function pe(e) {
91
126
  return typeof e == "object" && e !== null && "status" in e && e.status === 401;
92
127
  }
93
- const $ = /* @__PURE__ */ Symbol("webx-i18n");
94
- function Re() {
95
- const e = C($, null);
128
+ const O = /* @__PURE__ */ Symbol("webx-i18n");
129
+ function De() {
130
+ const e = R(O, null);
96
131
  if (e === null)
97
132
  throw new Error("useI18n() was called outside a panel created by createAdmin().");
98
133
  return e;
99
134
  }
100
- function F(e) {
101
- const t = C($, null);
102
- return t === null ? V().scope(e) : t.scope(e);
135
+ function j(e) {
136
+ const n = R(O, null);
137
+ return n === null ? X().scope(e) : n.scope(e);
103
138
  }
104
- function ce(e, t) {
105
- e.provide($, t);
139
+ function he(e, n) {
140
+ e.provide(O, n);
106
141
  }
107
- function V(e = {}) {
108
- const t = e.fallback ?? "en", n = T({
109
- locale: e.locale ?? t,
110
- fallback: t,
142
+ function X(e = {}) {
143
+ const n = e.fallback ?? "en", o = C({
144
+ locale: e.locale ?? n,
145
+ fallback: n,
111
146
  panelLocales: [],
112
147
  contentLocales: []
113
- }), c = {}, u = T({ value: {} });
114
- function f(o, l, a) {
115
- let r = o[l]?.[a[0] ?? ""];
116
- for (const i of a.slice(1)) {
117
- if (typeof r != "object" || r === null)
148
+ }), u = {}, f = C({ value: {} });
149
+ function m(r, i, l) {
150
+ let t = r[i]?.[l[0] ?? ""];
151
+ for (const a of l.slice(1)) {
152
+ if (typeof t != "object" || t === null)
118
153
  return null;
119
- r = r[i];
154
+ t = t[a];
120
155
  }
121
- return typeof r == "string" ? r : null;
156
+ return typeof t == "string" ? t : null;
122
157
  }
123
- function s(o, l, a) {
124
- const [r, i] = l.includes("::") ? l.split("::", 2) : [o, l], m = i.split("."), y = f(u.value, r, m) ?? f(c, r, m) ?? // Not an empty string: a key on screen is ugly, but it says which key, and a blank
158
+ function p(r, i, l) {
159
+ const [t, a] = i.includes("::") ? i.split("::", 2) : [r, i], c = a.split("."), s = m(f.value, t, c) ?? m(u, t, c) ?? // Not an empty string: a key on screen is ugly, but it says which key, and a blank
125
160
  // label says nothing to anybody trying to fix it.
126
- l;
127
- return a === void 0 ? y : ue(y, a);
161
+ i;
162
+ return l === void 0 ? s : ve(s, l);
128
163
  }
129
164
  return {
130
- state: n,
131
- defaults(o, l) {
132
- c[o] = { ...c[o], ...l };
165
+ state: o,
166
+ defaults(r, i) {
167
+ u[r] = { ...u[r], ...i };
133
168
  },
134
- load(o, l, a) {
135
- u.value = o ?? {}, n.locale = l ?? n.locale, a !== void 0 && (n.fallback = a);
169
+ load(r, i, l) {
170
+ f.value = r ?? {}, o.locale = i ?? o.locale, l !== void 0 && (o.fallback = l);
136
171
  },
137
- scope(o) {
138
- return (l, a) => s(o, l, a);
172
+ scope(r) {
173
+ return (i, l) => p(r, i, l);
139
174
  },
140
- t: (o, l) => s("", o, l)
175
+ t: (r, i) => p("", r, i)
141
176
  };
142
177
  }
143
- function ue(e, t) {
144
- let n = e;
145
- for (const [c, u] of Object.entries(t))
146
- n = n.replaceAll(`:${c}`, String(u));
147
- return n;
178
+ function ve(e, n) {
179
+ let o = e;
180
+ for (const [u, f] of Object.entries(n))
181
+ o = o.replaceAll(`:${u}`, String(f));
182
+ return o;
148
183
  }
149
- const de = /* @__PURE__ */ O({
184
+ const we = /* @__PURE__ */ M({
150
185
  __name: "AdminNav",
151
186
  props: {
152
187
  collapsed: { type: Boolean }
153
188
  },
154
189
  emits: ["select"],
155
- setup(e, { emit: t }) {
156
- const n = t, c = H(), u = F("webx-admin"), f = Y(), s = Z(), o = A({
157
- get: () => c.nav.value.find((a) => s.path.startsWith(a.path))?.id ?? "",
158
- set: (l) => {
159
- const a = c.nav.value.find((r) => r.id === l);
160
- a !== void 0 && f.push(a.path);
190
+ setup(e, { emit: n }) {
191
+ const o = n, u = N(), f = j("webx-admin"), m = te(), p = ne(), r = k({
192
+ get: () => u.nav.value.find((l) => p.path.startsWith(l.path))?.id ?? "",
193
+ set: (i) => {
194
+ const l = u.nav.value.find((t) => t.id === i);
195
+ l !== void 0 && m.push(l.path);
161
196
  }
162
197
  });
163
- return (l, a) => {
164
- const r = v("wx-menu-item"), i = v("wx-menu");
165
- return _(), U(i, {
166
- modelValue: o.value,
167
- "onUpdate:modelValue": a[0] || (a[0] = (m) => o.value = m),
198
+ return (i, l) => {
199
+ const t = y("wx-menu-item"), a = y("wx-submenu"), c = y("wx-menu");
200
+ return w(), S(c, {
201
+ modelValue: r.value,
202
+ "onUpdate:modelValue": l[0] || (l[0] = (s) => r.value = s),
168
203
  collapsed: e.collapsed,
169
- label: d(u)("nav.sections"),
170
- onSelect: a[1] || (a[1] = (m) => n("select"))
204
+ label: d(f)("nav.sections"),
205
+ onSelect: l[1] || (l[1] = (s) => o("select"))
171
206
  }, {
172
- default: g(() => [
173
- (_(!0), x(j, null, z(d(c).nav.value, (m) => (_(), U(r, {
174
- key: m.id,
175
- value: m.id,
176
- icon: m.icon ?? void 0,
177
- label: m.title
178
- }, null, 8, ["value", "icon", "label"]))), 128))
207
+ default: x(() => [
208
+ (w(!0), _(U, null, P(d(u).groups.value.top, (s) => (w(), S(t, {
209
+ key: s.id,
210
+ value: s.id,
211
+ icon: s.icon ?? void 0,
212
+ label: s.title
213
+ }, null, 8, ["value", "icon", "label"]))), 128)),
214
+ (w(!0), _(U, null, P(d(u).groups.value.groups, (s) => (w(), S(a, {
215
+ key: s.id,
216
+ value: `group:${s.id}`,
217
+ title: s.title,
218
+ icon: "gear"
219
+ }, {
220
+ default: x(() => [
221
+ (w(!0), _(U, null, P(s.entries, (v) => (w(), S(t, {
222
+ key: v.id,
223
+ value: v.id,
224
+ icon: v.icon ?? void 0,
225
+ label: v.title
226
+ }, null, 8, ["value", "icon", "label"]))), 128))
227
+ ]),
228
+ _: 2
229
+ }, 1032, ["value", "title"]))), 128))
179
230
  ]),
180
231
  _: 1
181
232
  }, 8, ["modelValue", "collapsed", "label"]);
182
233
  };
183
234
  }
184
- }), fe = {
235
+ }), ge = {
185
236
  key: 0,
186
237
  class: "wx-root wx-admin-plain"
187
- }, me = {
238
+ }, ye = {
188
239
  key: 1,
189
240
  class: "wx-root wx-admin-plain"
190
- }, pe = {
241
+ }, be = {
191
242
  key: 2,
192
243
  class: "wx-root wx-admin-plain"
193
- }, he = /* @__PURE__ */ O({
244
+ }, xe = /* @__PURE__ */ M({
194
245
  __name: "AdminShell",
195
246
  setup(e) {
196
- const t = H(), n = F("webx-admin"), c = M(null), { layout: u, collapsed: f, showAside: s, drawerOpen: o, toggle: l, close: a } = ne(c, {
247
+ const n = N(), o = j("webx-admin"), u = T(null), { layout: f, collapsed: m, showAside: p, drawerOpen: r, toggle: i, close: l } = oe(u, {
197
248
  persist: "webx-admin-shell"
198
249
  });
199
- return (r, i) => {
200
- const m = v("router-view"), y = v("wx-loading"), b = v("wx-button"), p = v("wx-result"), h = v("wx-action"), S = v("wx-text"), K = v("wx-header"), W = v("wx-aside"), q = v("wx-main"), P = v("wx-container"), B = v("wx-drawer");
201
- return _(), x(j, null, [
202
- w(d(ae)),
203
- d(t).state.status === "unauthenticated" ? (_(), x("div", fe, [
204
- w(m)
205
- ])) : d(t).state.status === "loading" ? (_(), x("div", me, [
206
- w(y, {
207
- label: d(n)("shell.loading")
250
+ return (t, a) => {
251
+ const c = y("router-view"), s = y("wx-loading"), v = y("wx-button"), h = y("wx-result"), g = y("wx-action"), E = y("wx-text"), K = y("wx-header"), q = y("wx-aside"), B = y("wx-main"), V = y("wx-container"), G = y("wx-drawer");
252
+ return w(), _(U, null, [
253
+ b(d(se)),
254
+ d(n).state.status === "unauthenticated" ? (w(), _("div", ge, [
255
+ b(c)
256
+ ])) : d(n).state.status === "loading" ? (w(), _("div", ye, [
257
+ b(s, {
258
+ label: d(o)("shell.loading")
208
259
  }, null, 8, ["label"])
209
- ])) : d(t).state.status === "error" ? (_(), x("div", pe, [
210
- w(p, {
260
+ ])) : d(n).state.status === "error" ? (w(), _("div", be, [
261
+ b(h, {
211
262
  status: "error",
212
- title: d(n)("shell.error-title"),
213
- description: d(t).state.error
263
+ title: d(o)("shell.error-title"),
264
+ description: d(n).state.error
214
265
  }, {
215
- default: g(() => [
216
- w(b, {
266
+ default: x(() => [
267
+ b(v, {
217
268
  type: "primary",
218
- onClick: i[0] || (i[0] = (E) => d(t).reload())
269
+ onClick: a[0] || (a[0] = (L) => d(n).reload())
219
270
  }, {
220
- default: g(() => [
221
- R(N(d(n)("shell.retry")), 1)
271
+ default: x(() => [
272
+ I(W(d(o)("shell.retry")), 1)
222
273
  ]),
223
274
  _: 1
224
275
  })
225
276
  ]),
226
277
  _: 1
227
278
  }, 8, ["title", "description"])
228
- ])) : (_(), x("div", {
279
+ ])) : (w(), _("div", {
229
280
  key: 3,
230
281
  ref_key: "shellEl",
231
- ref: c,
282
+ ref: u,
232
283
  class: "wx-root wx-admin"
233
284
  }, [
234
- w(P, { viewport: "" }, {
235
- default: g(() => [
236
- w(K, null, {
237
- end: g(() => [
238
- L(r.$slots, "user", {}, void 0, !0)
285
+ b(V, { viewport: "" }, {
286
+ default: x(() => [
287
+ b(K, null, {
288
+ end: x(() => [
289
+ $(t.$slots, "user", {}, void 0, !0)
239
290
  ]),
240
- default: g(() => [
241
- w(h, {
242
- icon: d(u) === "drawer" ? "menu" : "sidebar",
243
- title: d(u) === "drawer" ? d(n)("nav.menu") : d(n)("nav.collapse"),
244
- onClick: d(l)
291
+ default: x(() => [
292
+ b(g, {
293
+ icon: d(f) === "drawer" ? "menu" : "sidebar",
294
+ title: d(f) === "drawer" ? d(o)("nav.menu") : d(o)("nav.collapse"),
295
+ onClick: d(i)
245
296
  }, null, 8, ["icon", "title", "onClick"]),
246
- L(r.$slots, "brand", {}, () => [
247
- w(S, { weight: "semibold" }, {
248
- default: g(() => [
249
- R(N(d(t).state.manifest?.title), 1)
297
+ $(t.$slots, "brand", {}, () => [
298
+ b(E, { weight: "semibold" }, {
299
+ default: x(() => [
300
+ I(W(d(n).state.manifest?.title), 1)
250
301
  ]),
251
302
  _: 1
252
303
  })
@@ -254,26 +305,26 @@ const de = /* @__PURE__ */ O({
254
305
  ]),
255
306
  _: 3
256
307
  }),
257
- w(P, { direction: "horizontal" }, {
258
- default: g(() => [
259
- d(s) ? (_(), U(W, {
308
+ b(V, { direction: "horizontal" }, {
309
+ default: x(() => [
310
+ d(p) ? (w(), S(q, {
260
311
  key: 0,
261
- collapsed: d(f),
312
+ collapsed: d(m),
262
313
  width: 220,
263
314
  scroll: ""
264
315
  }, {
265
- default: g(() => [
266
- L(r.$slots, "nav", { collapsed: d(f) }, void 0, !0)
316
+ default: x(() => [
317
+ $(t.$slots, "nav", { collapsed: d(m) }, void 0, !0)
267
318
  ]),
268
319
  _: 3
269
- }, 8, ["collapsed"])) : G("", !0),
270
- w(q, {
320
+ }, 8, ["collapsed"])) : J("", !0),
321
+ b(B, {
271
322
  padding: "md",
272
323
  scroll: "",
273
324
  class: "wx-admin__screen"
274
325
  }, {
275
- default: g(() => [
276
- w(m)
326
+ default: x(() => [
327
+ b(c)
277
328
  ]),
278
329
  _: 1
279
330
  })
@@ -283,19 +334,19 @@ const de = /* @__PURE__ */ O({
283
334
  ]),
284
335
  _: 3
285
336
  }),
286
- w(B, {
287
- open: d(o),
288
- "onUpdate:open": i[2] || (i[2] = (E) => J(o) ? o.value = E : null),
289
- title: d(n)("nav.menu"),
337
+ b(G, {
338
+ open: d(r),
339
+ "onUpdate:open": a[2] || (a[2] = (L) => Q(r) ? r.value = L : null),
340
+ title: d(o)("nav.menu"),
290
341
  side: "left",
291
342
  size: 260,
292
343
  closable: ""
293
344
  }, {
294
- default: g(() => [
295
- L(r.$slots, "nav", {
345
+ default: x(() => [
346
+ $(t.$slots, "nav", {
296
347
  collapsed: !1,
297
- onSelect: i[1] || (i[1] = //@ts-ignore
298
- (...E) => d(a) && d(a)(...E))
348
+ onSelect: a[1] || (a[1] = //@ts-ignore
349
+ (...L) => d(l) && d(l)(...L))
299
350
  }, void 0, !0)
300
351
  ]),
301
352
  _: 3
@@ -304,15 +355,15 @@ const de = /* @__PURE__ */ O({
304
355
  ], 64);
305
356
  };
306
357
  }
307
- }), we = (e, t) => {
308
- const n = e.__vccOpts || e;
309
- for (const [c, u] of t)
310
- n[c] = u;
311
- return n;
312
- }, ve = /* @__PURE__ */ we(he, [["__scopeId", "data-v-9ef35d4d"]]);
313
- class ge extends Error {
314
- constructor(t, n, c = {}, u = null, f = null) {
315
- super(t), this.status = n, this.errors = c, this.retryAfter = u, this.body = f, this.name = "HttpError";
358
+ }), _e = (e, n) => {
359
+ const o = e.__vccOpts || e;
360
+ for (const [u, f] of n)
361
+ o[u] = f;
362
+ return o;
363
+ }, Se = /* @__PURE__ */ _e(xe, [["__scopeId", "data-v-9ef35d4d"]]);
364
+ class ke extends Error {
365
+ constructor(n, o, u = {}, f = null, m = null) {
366
+ super(n), this.status = o, this.errors = u, this.retryAfter = f, this.body = m, this.name = "HttpError";
316
367
  }
317
368
  status;
318
369
  errors;
@@ -329,86 +380,86 @@ class ge extends Error {
329
380
  return this.status === 429;
330
381
  }
331
382
  }
332
- const ye = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
333
- function _e(e = {}) {
334
- const t = (e.baseUrl ?? "").replace(/\/$/, ""), n = e.csrfUrl ?? "/sanctum/csrf-cookie", c = e.fetch ?? globalThis.fetch.bind(globalThis), u = e.onUnauthenticated, f = e.headers;
335
- let s = !1;
336
- async function o(a = !1) {
337
- s && !a && I("XSRF-TOKEN") !== null || (await c(n, { credentials: "same-origin" }), s = !0);
383
+ const Ee = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
384
+ function Le(e = {}) {
385
+ const n = (e.baseUrl ?? "").replace(/\/$/, ""), o = e.csrfUrl ?? "/sanctum/csrf-cookie", u = e.fetch ?? globalThis.fetch.bind(globalThis), f = e.onUnauthenticated, m = e.headers;
386
+ let p = !1;
387
+ async function r(l = !1) {
388
+ p && !l && H("XSRF-TOKEN") !== null || (await u(o, { credentials: "same-origin" }), p = !0);
338
389
  }
339
- async function l(a, r, i, m = {}, y = !1) {
340
- const b = ye.has(a);
341
- b && await o();
342
- const p = {
390
+ async function i(l, t, a, c = {}, s = !1) {
391
+ const v = Ee.has(l);
392
+ v && await r();
393
+ const h = {
343
394
  Accept: "application/json",
344
395
  "X-Requested-With": "XMLHttpRequest",
345
396
  // Standing headers first, so a caller can still override one for a single request.
346
- ...f?.(),
347
- ...m.headers
397
+ ...m?.(),
398
+ ...c.headers
348
399
  };
349
- if (b) {
350
- const S = I("XSRF-TOKEN");
351
- S !== null && (p["X-XSRF-TOKEN"] = S);
400
+ if (v) {
401
+ const E = H("XSRF-TOKEN");
402
+ E !== null && (h["X-XSRF-TOKEN"] = E);
352
403
  }
353
- i !== void 0 && (p["Content-Type"] = "application/json");
354
- const h = await c(xe(t, r, m.query), {
355
- method: a,
404
+ a !== void 0 && (h["Content-Type"] = "application/json");
405
+ const g = await u(Ae(n, t, c.query), {
406
+ method: l,
356
407
  credentials: "same-origin",
357
- headers: p,
358
- signal: m.signal,
359
- body: i === void 0 ? void 0 : JSON.stringify(i)
408
+ headers: h,
409
+ signal: c.signal,
410
+ body: a === void 0 ? void 0 : JSON.stringify(a)
360
411
  });
361
- if (h.status === 419 && b && !y)
362
- return await o(!0), l(a, r, i, m, !0);
363
- if (h.status === 401 && u?.(), !h.ok)
364
- throw await be(h);
365
- if (h.status !== 204)
366
- return await h.json();
412
+ if (g.status === 419 && v && !s)
413
+ return await r(!0), i(l, t, a, c, !0);
414
+ if (g.status === 401 && f?.(), !g.ok)
415
+ throw await $e(g);
416
+ if (g.status !== 204)
417
+ return await g.json();
367
418
  }
368
419
  return {
369
- get: (a, r) => l("GET", a, void 0, r),
370
- post: (a, r, i) => l("POST", a, r, i),
371
- put: (a, r, i) => l("PUT", a, r, i),
372
- patch: (a, r, i) => l("PATCH", a, r, i),
373
- delete: (a, r) => l("DELETE", a, void 0, r)
420
+ get: (l, t) => i("GET", l, void 0, t),
421
+ post: (l, t, a) => i("POST", l, t, a),
422
+ put: (l, t, a) => i("PUT", l, t, a),
423
+ patch: (l, t, a) => i("PATCH", l, t, a),
424
+ delete: (l, t) => i("DELETE", l, void 0, t)
374
425
  };
375
426
  }
376
- async function be(e) {
377
- let t = null;
427
+ async function $e(e) {
428
+ let n = null;
378
429
  try {
379
- t = await e.json();
430
+ n = await e.json();
380
431
  } catch {
381
432
  }
382
- const n = t ?? {}, c = typeof n.message == "string" && n.message !== "" ? n.message : e.statusText || `Request failed with ${e.status}`, u = n.errors !== null && typeof n.errors == "object" ? n.errors : {}, f = e.headers.get("Retry-After"), s = f === null ? null : Number.parseInt(f, 10);
383
- return new ge(
384
- c,
385
- e.status,
433
+ const o = n ?? {}, u = typeof o.message == "string" && o.message !== "" ? o.message : e.statusText || `Request failed with ${e.status}`, f = o.errors !== null && typeof o.errors == "object" ? o.errors : {}, m = e.headers.get("Retry-After"), p = m === null ? null : Number.parseInt(m, 10);
434
+ return new ke(
386
435
  u,
387
- Number.isFinite(s) ? s : null,
388
- t
436
+ e.status,
437
+ f,
438
+ Number.isFinite(p) ? p : null,
439
+ n
389
440
  );
390
441
  }
391
- function xe(e, t, n) {
392
- const u = /^https?:\/\//i.test(t) ? t : `${e}/${t.replace(/^\//, "")}`;
393
- if (n === void 0)
394
- return u;
395
- const f = new URLSearchParams();
396
- for (const [o, l] of Object.entries(n))
397
- l != null && f.set(o, String(l));
398
- const s = f.toString();
399
- return s === "" ? u : `${u}${u.includes("?") ? "&" : "?"}${s}`;
442
+ function Ae(e, n, o) {
443
+ const f = /^https?:\/\//i.test(n) ? n : `${e}/${n.replace(/^\//, "")}`;
444
+ if (o === void 0)
445
+ return f;
446
+ const m = new URLSearchParams();
447
+ for (const [r, i] of Object.entries(o))
448
+ i != null && m.set(r, String(i));
449
+ const p = m.toString();
450
+ return p === "" ? f : `${f}${f.includes("?") ? "&" : "?"}${p}`;
400
451
  }
401
- function I(e) {
452
+ function H(e) {
402
453
  if (typeof document > "u")
403
454
  return null;
404
- for (const t of document.cookie.split(";")) {
405
- const [n, ...c] = t.trim().split("=");
406
- if (n === e)
407
- return decodeURIComponent(c.join("="));
455
+ for (const n of document.cookie.split(";")) {
456
+ const [o, ...u] = n.trim().split("=");
457
+ if (o === e)
458
+ return decodeURIComponent(u.join("="));
408
459
  }
409
460
  return null;
410
461
  }
411
- const Se = {
462
+ const Ue = {
412
463
  shell: {
413
464
  loading: "Loading the panel…",
414
465
  "error-title": "The panel could not start",
@@ -422,119 +473,176 @@ const Se = {
422
473
  collapse: "Collapse the menu",
423
474
  language: "Language"
424
475
  }
425
- }, X = "webx.locale";
426
- function Ne(e = {}) {
427
- const t = e.manifestUrl ?? Ue() ?? "/api/cms/manifest", n = e.apiPath ?? t.replace(/\/manifest\/?$/, ""), c = e.basePath ?? "/cms", u = e.modules ?? [], f = [...e.routes ?? []];
428
- for (const p of u)
429
- f.push(...p.routes ?? []);
430
- const s = ee({
431
- history: te(c),
432
- routes: f
433
- }), o = V({ locale: e.locale ?? Le() }), l = e.http ?? _e({
476
+ }, z = "webx.locale";
477
+ function He(e = {}) {
478
+ const n = e.manifestUrl ?? Ne() ?? "/api/cms/manifest", o = e.apiPath ?? n.replace(/\/manifest\/?$/, ""), u = e.basePath ?? "/cms", f = e.modules ?? [], m = [...e.routes ?? []];
479
+ for (const h of f)
480
+ m.push(...h.routes ?? []);
481
+ const p = ae({
482
+ history: le(u),
483
+ routes: m
484
+ }), r = X({ locale: e.locale ?? Pe() }), i = e.http ?? Le({
434
485
  baseUrl: "",
435
486
  onUnauthenticated: () => {
436
- r.setUser(null), r.state.status = "unauthenticated";
487
+ t.setUser(null), t.state.status = "unauthenticated";
437
488
  },
438
489
  // Every request says which language the panel is currently showing. It decides what
439
490
  // the server writes its own messages in — a 422 under a field — for anybody who has
440
491
  // not stored a preference yet, which is everybody until they choose one. Without it,
441
492
  // signing in on a Russian sign-in screen lands in an English panel.
442
- headers: () => ({ "X-Webx-Locale": o.state.locale })
493
+ headers: () => ({ "X-Webx-Locale": r.state.locale })
443
494
  });
444
- o.defaults("webx-admin", Se);
445
- async function a(p) {
446
- const h = await l.get(`${n}/translations/${p}`);
447
- o.load(h.data.namespaces, h.data.locale, h.data.fallback), ke(h.data.locale), Te(h.data.locale, o.state.panelLocales);
495
+ r.defaults("webx-admin", Ue);
496
+ async function l(h) {
497
+ const g = await i.get(`${o}/translations/${h}`);
498
+ r.load(g.data.namespaces, g.data.locale, g.data.fallback), Ce(g.data.locale), Me(g.data.locale, r.state.panelLocales);
448
499
  }
449
- const r = le({
450
- http: l,
451
- basePath: c,
452
- apiPath: n,
453
- modules: u,
454
- i18n: o,
455
- loadDictionary: a,
456
- loadManifest: async () => (await l.get(t)).data
457
- }), i = Q(Ee(e));
458
- i.use(oe), re(i, r), ce(i, o);
459
- const m = M("");
460
- i.provide(se, {
461
- list: A(
462
- () => o.state.contentLocales.map((p) => ({
463
- code: p.code,
464
- label: p.code.toUpperCase()
500
+ const t = fe({
501
+ http: i,
502
+ basePath: u,
503
+ apiPath: o,
504
+ modules: f,
505
+ i18n: r,
506
+ loadDictionary: l,
507
+ types: e.types,
508
+ screens: e.screens,
509
+ loadManifest: async () => (await i.get(n)).data
510
+ }), a = Y(Te(e));
511
+ a.use(re), me(a, t), he(a, r);
512
+ const c = T("");
513
+ a.provide(ie, {
514
+ list: k(
515
+ () => r.state.contentLocales.map((h) => ({
516
+ code: h.code,
517
+ label: h.code.toUpperCase()
465
518
  }))
466
519
  ),
467
- active: A({
468
- get: () => m.value || (o.state.contentLocales[0]?.code ?? ""),
469
- set: (p) => {
470
- m.value = p;
520
+ active: k({
521
+ get: () => c.value || (r.state.contentLocales[0]?.code ?? ""),
522
+ set: (h) => {
523
+ c.value = h;
471
524
  }
472
525
  })
473
526
  });
474
- const y = {
475
- app: i,
476
- router: s,
477
- context: r,
478
- i18n: o,
527
+ const s = {
528
+ app: a,
529
+ router: p,
530
+ context: t,
531
+ i18n: r,
479
532
  async mount() {
480
- await Promise.all([b(), a(o.state.locale)]).catch(() => {
481
- }), i.mount(e.el ?? "#webx-app"), await r.reload();
533
+ await Promise.all([v(), l(r.state.locale)]).catch(() => {
534
+ }), a.mount(e.el ?? "#webx-app"), await t.reload();
482
535
  }
483
536
  };
484
- async function b() {
485
- const p = await l.get(`${n}/locales`);
486
- o.state.panelLocales = p.data.panel, o.state.contentLocales = p.data.content;
537
+ async function v() {
538
+ const h = await i.get(`${o}/locales`);
539
+ r.state.panelLocales = h.data.panel, r.state.contentLocales = h.data.content;
487
540
  }
488
- for (const p of e.plugins ?? [])
489
- p.install(y);
490
- return i.use(s), y;
541
+ for (const h of e.plugins ?? [])
542
+ h.install(s);
543
+ return a.use(p), s;
491
544
  }
492
- function Ee(e) {
493
- const t = {
545
+ function Te(e) {
546
+ const n = {
494
547
  // The menu is the panel's own: it is the manifest, drawn.
495
- nav: (n) => k(de, { collapsed: n.collapsed === !0 })
548
+ nav: (o) => A(we, { collapsed: o.collapsed === !0 })
496
549
  };
497
- return e.brand !== void 0 && (t.brand = () => k(e.brand)), e.userMenu !== void 0 && (t.user = () => k(e.userMenu)), { render: () => k(ve, null, t) };
550
+ return e.brand !== void 0 && (n.brand = () => A(e.brand)), e.userMenu !== void 0 && (n.user = () => A(e.userMenu)), { render: () => A(Se, null, n) };
498
551
  }
499
- function Le() {
500
- const e = Ae(X);
552
+ function Pe() {
553
+ const e = Re(z);
501
554
  return e !== null ? e : typeof document < "u" && document.documentElement.lang !== "" ? document.documentElement.lang : typeof navigator > "u" ? "en" : navigator.language;
502
555
  }
503
- function ke(e) {
556
+ function Ce(e) {
504
557
  try {
505
- localStorage.setItem(X, e);
558
+ localStorage.setItem(z, e);
506
559
  } catch {
507
560
  }
508
561
  }
509
- function Ae(e) {
562
+ function Re(e) {
510
563
  try {
511
564
  return localStorage.getItem(e);
512
565
  } catch {
513
566
  return null;
514
567
  }
515
568
  }
516
- function Te(e, t) {
517
- typeof document > "u" || (document.documentElement.lang = e, document.documentElement.dir = t.find((n) => n.code === e)?.direction ?? "ltr");
569
+ function Me(e, n) {
570
+ typeof document > "u" || (document.documentElement.lang = e, document.documentElement.dir = n.find((o) => o.code === e)?.direction ?? "ltr");
518
571
  }
519
- function Ue() {
572
+ function Ne() {
520
573
  return typeof document > "u" ? null : document.querySelector('meta[name="webx-manifest"]')?.getAttribute("content") ?? null;
521
574
  }
575
+ const Oe = { class: "wx-screen-host" }, Fe = /* @__PURE__ */ M({
576
+ __name: "Screen",
577
+ props: /* @__PURE__ */ D({
578
+ name: {},
579
+ errors: { default: void 0 },
580
+ disabled: { type: Boolean, default: !1 },
581
+ labelPosition: { default: void 0 },
582
+ labelWidth: { default: void 0 },
583
+ size: { default: void 0 }
584
+ }, {
585
+ modelValue: { default: () => ({}) },
586
+ modelModifiers: {}
587
+ }),
588
+ emits: /* @__PURE__ */ D(["loaded"], ["update:modelValue"]),
589
+ setup(e, { expose: n, emit: o }) {
590
+ const u = e, f = o, m = Z(e, "modelValue"), p = N(), r = j("webx-admin"), i = T(null), l = T(null);
591
+ async function t() {
592
+ i.value = null, l.value = null;
593
+ try {
594
+ const a = await p.loadScreen(u.name);
595
+ i.value = a, f("loaded", a);
596
+ } catch (a) {
597
+ l.value = a instanceof Error ? a.message : String(a);
598
+ }
599
+ }
600
+ return ee([() => u.name, () => p.i18n.state.locale], () => {
601
+ t();
602
+ }, { immediate: !0 }), n({ reload: t }), (a, c) => (w(), _("div", Oe, [
603
+ l.value ? (w(), S(d(ce), {
604
+ key: 0,
605
+ type: "danger",
606
+ title: d(r)("shell.error-title"),
607
+ description: l.value
608
+ }, null, 8, ["title", "description"])) : i.value === null ? (w(), S(d(ue), {
609
+ key: 1,
610
+ rows: 4
611
+ })) : (w(), S(d(de), {
612
+ key: 2,
613
+ modelValue: m.value,
614
+ "onUpdate:modelValue": c[0] || (c[0] = (s) => m.value = s),
615
+ root: i.value,
616
+ patch: d(p).screenPatch(e.name),
617
+ types: d(p).types,
618
+ errors: e.errors,
619
+ translate: d(p).i18n.t,
620
+ can: d(p).can,
621
+ disabled: e.disabled,
622
+ "label-position": e.labelPosition,
623
+ "label-width": e.labelWidth,
624
+ size: e.size
625
+ }, null, 8, ["modelValue", "root", "patch", "types", "errors", "translate", "can", "disabled", "label-position", "label-width", "size"]))
626
+ ]));
627
+ }
628
+ });
522
629
  export {
523
- de as AdminNav,
524
- ve as AdminShell,
525
- ge as HttpError,
526
- D as adminKey,
527
- Se as adminMessages,
528
- Ne as createAdmin,
529
- le as createAdminContext,
530
- _e as createHttp,
531
- V as createI18n,
532
- $ as i18nKey,
533
- re as provideAdmin,
534
- ce as provideI18n,
535
- I as readCookie,
536
- H as useAdmin,
537
- Re as useI18n,
538
- F as useTranslate
630
+ we as AdminNav,
631
+ Se as AdminShell,
632
+ ke as HttpError,
633
+ Fe as WxScreen,
634
+ F as adminKey,
635
+ Ue as adminMessages,
636
+ He as createAdmin,
637
+ fe as createAdminContext,
638
+ Le as createHttp,
639
+ X as createI18n,
640
+ O as i18nKey,
641
+ me as provideAdmin,
642
+ he as provideI18n,
643
+ H as readCookie,
644
+ N as useAdmin,
645
+ De as useI18n,
646
+ j as useTranslate
539
647
  };
540
648
  //# sourceMappingURL=index.js.map