@webx-ui/module-auth 0.5.4 → 0.6.1

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,36 +1,43 @@
1
- import { inject as me, defineComponent as O, computed as F, ref as g, useTemplateRef as le, onBeforeUnmount as Fe, resolveComponent as z, openBlock as k, createBlock as U, withCtx as l, createVNode as n, withModifiers as ze, createCommentVNode as M, createElementVNode as E, createTextVNode as S, toDisplayString as $, watch as Q, unref as e, isRef as ve, createElementBlock as j, resolveDynamicComponent as Be, createSlots as ne, Fragment as te, renderList as pe, h as fe } from "vue";
2
- import { useTranslate as R, HttpError as Te, useAdmin as H, useI18n as he, useErrorText as be, WxDate as Me, WxRowMenu as ue, WxListScreen as Pe } from "@webx-ui/module-admin";
3
- import { useModal as we, WxDialog as ye, WxFormItem as K, WxInput as ee, WxSelect as G, WxSpace as N, WxCheckbox as de, WxText as oe, WxButton as q, toast as J, WxTable as Ee, WxBadge as ae, WxAvatar as Ne, createModal as ge, confirm as Oe } from "@webx-ui/core";
4
- const _e = /* @__PURE__ */ Symbol("webx-auth");
5
- function xe() {
6
- const a = me(_e, null);
1
+ import { inject as te, defineComponent as R, computed as P, ref as g, useTemplateRef as oe, onBeforeUnmount as ze, resolveComponent as B, openBlock as L, createBlock as S, withCtx as l, createVNode as t, withModifiers as Be, createCommentVNode as T, createElementVNode as N, createTextVNode as F, toDisplayString as $, watch as Z, unref as e, isRef as se, createElementBlock as O, resolveDynamicComponent as ge, createSlots as ne, Fragment as le, renderList as _e, h as xe, normalizeClass as Te } from "vue";
2
+ import { useTranslate as I, HttpError as Me, useAdmin as q, useI18n as ke, useErrorText as re, WxDate as Ne, WxRowMenu as he, WxListScreen as Ee } from "@webx-ui/module-admin";
3
+ import { useModal as ie, WxDialog as ue, WxFormItem as M, WxInput as E, WxSelect as X, WxSpace as Y, WxCheckbox as be, WxText as de, WxButton as D, toast as j, WxTable as Oe, WxBadge as ae, WxAvatar as De, createModal as ce, confirm as Re } from "@webx-ui/core";
4
+ const Ve = /* @__PURE__ */ Symbol("webx-auth");
5
+ function me() {
6
+ const a = te(Ve, null);
7
7
  if (a === null)
8
8
  throw new Error("useAuth() was called outside a panel that installed the auth plugin.");
9
9
  return a;
10
10
  }
11
- function Re(a) {
11
+ function Ie(a) {
12
12
  const i = `${a.apiPath}/auth`;
13
13
  return {
14
14
  async me() {
15
15
  try {
16
16
  return (await a.http.get(`${i}/me`)).data;
17
- } catch (o) {
18
- if (De(o))
17
+ } catch (s) {
18
+ if (Ye(s))
19
19
  return null;
20
- throw o;
20
+ throw s;
21
21
  }
22
22
  },
23
- async login(o) {
24
- const t = await a.http.post(`${i}/login`, {
25
- email: o.email,
26
- password: o.password,
27
- remember: o.remember ?? !1
23
+ async login(s) {
24
+ const o = await a.http.post(`${i}/login`, {
25
+ email: s.email,
26
+ password: s.password,
27
+ remember: s.remember ?? !1
28
28
  });
29
- return a.setUser(t.data), await a.reload(), t.data;
29
+ return a.setUser(o.data), await a.reload(), o.data;
30
30
  },
31
- async setLocale(o) {
32
- const t = await a.http.put(`${i}/locale`, { locale: o });
33
- a.setUser(t.data), await a.setLocale(o);
31
+ async setLocale(s) {
32
+ const o = await a.http.put(`${i}/locale`, { locale: s });
33
+ a.setUser(o.data), await a.setLocale(s);
34
+ },
35
+ async updateProfile(s) {
36
+ const o = await a.http.put(
37
+ `${i}/me`,
38
+ s
39
+ );
40
+ return a.setUser(o.data), o.data;
34
41
  },
35
42
  async logout() {
36
43
  try {
@@ -41,14 +48,14 @@ function Re(a) {
41
48
  }
42
49
  };
43
50
  }
44
- const ke = /* @__PURE__ */ Symbol("webx-auth-avatar");
45
- function Ie(a, i, o = null) {
46
- a.provide(_e, i), a.provide(ke, o);
51
+ const Ae = /* @__PURE__ */ Symbol("webx-auth-avatar"), Le = /* @__PURE__ */ Symbol("webx-auth-avatar-field");
52
+ function Ke(a, i, s = null, o = null) {
53
+ a.provide(Ve, i), a.provide(Ae, s), a.provide(Le, o);
47
54
  }
48
- function De(a) {
55
+ function Ye(a) {
49
56
  return typeof a == "object" && a !== null && "status" in a && a.status === 401;
50
57
  }
51
- const Ke = ["title", "aria-label", "aria-pressed"], je = /* @__PURE__ */ O({
58
+ const je = ["title", "aria-label", "aria-pressed"], qe = /* @__PURE__ */ R({
52
59
  __name: "LoginCard",
53
60
  props: {
54
61
  emailLabel: { default: void 0 },
@@ -63,171 +70,171 @@ const Ke = ["title", "aria-label", "aria-pressed"], je = /* @__PURE__ */ O({
63
70
  autofocus: { type: Boolean, default: !0 }
64
71
  },
65
72
  emits: ["success"],
66
- setup(a, { expose: i, emit: o }) {
67
- const t = a, r = o, x = xe(), m = R("webx-auth"), u = F(() => ({
68
- email: t.emailLabel ?? m("card.email"),
69
- password: t.passwordLabel ?? m("card.password"),
70
- remember: t.rememberLabel ?? m("card.remember"),
71
- submit: t.submitLabel ?? m("card.submit"),
72
- capsLock: t.capsLockWarning ?? m("card.caps-lock"),
73
- reveal: t.revealLabel ?? m("card.reveal"),
74
- hide: t.hideLabel ?? m("card.hide")
75
- })), p = g(""), L = g(""), V = g(!1), c = g(!1), f = g(!1), s = g(!1), _ = g(""), A = g({}), W = g(0), T = le("emailField");
76
- let C = null;
77
- Fe(I);
78
- const B = F(() => W.value > 0), b = F(
79
- () => t.throttleMessage === void 0 ? m("card.throttled", { seconds: W.value }) : t.throttleMessage.replace(":seconds", String(W.value))
73
+ setup(a, { expose: i, emit: s }) {
74
+ const o = a, u = s, k = me(), m = I("webx-auth"), n = P(() => ({
75
+ email: o.emailLabel ?? m("card.email"),
76
+ password: o.passwordLabel ?? m("card.password"),
77
+ remember: o.rememberLabel ?? m("card.remember"),
78
+ submit: o.submitLabel ?? m("card.submit"),
79
+ capsLock: o.capsLockWarning ?? m("card.caps-lock"),
80
+ reveal: o.revealLabel ?? m("card.reveal"),
81
+ hide: o.hideLabel ?? m("card.hide")
82
+ })), p = g(""), C = g(""), V = g(!1), d = g(!1), w = g(!1), r = g(!1), b = g(""), _ = g({}), f = g(0), U = oe("emailField");
83
+ let W = null;
84
+ ze(H);
85
+ const z = P(() => f.value > 0), h = P(
86
+ () => o.throttleMessage === void 0 ? m("card.throttled", { seconds: f.value }) : o.throttleMessage.replace(":seconds", String(f.value))
80
87
  );
81
- async function v() {
82
- if (!(c.value || B.value)) {
83
- c.value = !0, _.value = "", A.value = {};
88
+ async function c() {
89
+ if (!(d.value || z.value)) {
90
+ d.value = !0, b.value = "", _.value = {};
84
91
  try {
85
- await x.login({
92
+ await k.login({
86
93
  email: p.value,
87
- password: L.value,
94
+ password: C.value,
88
95
  remember: V.value
89
- }), L.value = "", r("success");
90
- } catch (h) {
91
- w(h);
96
+ }), C.value = "", u("success");
97
+ } catch (y) {
98
+ x(y);
92
99
  } finally {
93
- c.value = !1;
100
+ d.value = !1;
94
101
  }
95
102
  }
96
103
  }
97
- function w(h) {
98
- if (!(h instanceof Te)) {
99
- _.value = h instanceof Error ? h.message : String(h);
104
+ function x(y) {
105
+ if (!(y instanceof Me)) {
106
+ b.value = y instanceof Error ? y.message : String(y);
100
107
  return;
101
108
  }
102
- if (h.isValidation) {
103
- A.value = h.errors;
109
+ if (y.isValidation) {
110
+ _.value = y.errors;
104
111
  return;
105
112
  }
106
- if (h.isThrottled) {
107
- Y(h.retryAfter ?? 60);
113
+ if (y.isThrottled) {
114
+ Q(y.retryAfter ?? 60);
108
115
  return;
109
116
  }
110
- _.value = h.message;
117
+ b.value = y.message;
111
118
  }
112
- function Y(h) {
113
- I(), W.value = h, C = setInterval(() => {
114
- W.value -= 1, W.value <= 0 && I();
119
+ function Q(y) {
120
+ H(), f.value = y, W = setInterval(() => {
121
+ f.value -= 1, f.value <= 0 && H();
115
122
  }, 1e3);
116
123
  }
117
- function I() {
118
- C !== null && (clearInterval(C), C = null), W.value = 0;
124
+ function H() {
125
+ W !== null && (clearInterval(W), W = null), f.value = 0;
119
126
  }
120
- function y(h) {
121
- s.value = h.getModifierState("CapsLock");
127
+ function A(y) {
128
+ r.value = y.getModifierState("CapsLock");
122
129
  }
123
- return i({ focus: () => T.value?.focus() }), (h, d) => {
124
- const D = z("wx-alert"), Z = z("wx-icon"), ie = z("wx-input"), re = z("wx-form-item"), $e = z("wx-checkbox"), Se = z("wx-button"), Ue = z("wx-form"), We = z("wx-card");
125
- return k(), U(We, {
130
+ return i({ focus: () => U.value?.focus() }), (y, v) => {
131
+ const G = B("wx-alert"), ee = B("wx-icon"), fe = B("wx-input"), we = B("wx-form-item"), Fe = B("wx-checkbox"), Se = B("wx-button"), We = B("wx-form"), Pe = B("wx-card");
132
+ return L(), S(Pe, {
126
133
  class: "wx-login",
127
134
  padding: 24
128
135
  }, {
129
136
  default: l(() => [
130
- n(Ue, {
131
- errors: A.value,
132
- disabled: c.value,
137
+ t(We, {
138
+ errors: _.value,
139
+ disabled: d.value,
133
140
  gap: "md",
134
- onSubmit: ze(v, ["prevent"])
141
+ onSubmit: Be(c, ["prevent"])
135
142
  }, {
136
143
  default: l(() => [
137
- _.value !== "" ? (k(), U(D, {
144
+ b.value !== "" ? (L(), S(G, {
138
145
  key: 0,
139
146
  type: "danger",
140
147
  variant: "soft",
141
148
  live: "",
142
- description: _.value,
149
+ description: b.value,
143
150
  class: "wx-login__message"
144
- }, null, 8, ["description"])) : B.value ? (k(), U(D, {
151
+ }, null, 8, ["description"])) : z.value ? (L(), S(G, {
145
152
  key: 1,
146
153
  type: "warning",
147
154
  variant: "soft",
148
155
  live: "",
149
- description: b.value,
156
+ description: h.value,
150
157
  class: "wx-login__message"
151
- }, null, 8, ["description"])) : M("", !0),
152
- n(re, { name: "email" }, {
158
+ }, null, 8, ["description"])) : T("", !0),
159
+ t(we, { name: "email" }, {
153
160
  default: l(() => [
154
- n(ie, {
161
+ t(fe, {
155
162
  ref_key: "emailField",
156
- ref: T,
163
+ ref: U,
157
164
  modelValue: p.value,
158
- "onUpdate:modelValue": d[0] || (d[0] = (P) => p.value = P),
165
+ "onUpdate:modelValue": v[0] || (v[0] = (K) => p.value = K),
159
166
  type: "email",
160
- placeholder: u.value.email,
161
- "aria-label": u.value.email,
167
+ placeholder: n.value.email,
168
+ "aria-label": n.value.email,
162
169
  autocomplete: "username",
163
170
  autofocus: a.autofocus,
164
171
  inputmode: "email",
165
172
  size: "lg"
166
173
  }, {
167
174
  prefix: l(() => [
168
- n(Z, { name: "mail" })
175
+ t(ee, { name: "mail" })
169
176
  ]),
170
177
  _: 1
171
178
  }, 8, ["modelValue", "placeholder", "aria-label", "autofocus"])
172
179
  ]),
173
180
  _: 1
174
181
  }),
175
- n(re, {
182
+ t(we, {
176
183
  name: "password",
177
- help: s.value ? u.value.capsLock : void 0
184
+ help: r.value ? n.value.capsLock : void 0
178
185
  }, {
179
186
  default: l(() => [
180
- n(ie, {
181
- modelValue: L.value,
182
- "onUpdate:modelValue": d[2] || (d[2] = (P) => L.value = P),
183
- type: f.value ? "text" : "password",
184
- placeholder: u.value.password,
185
- "aria-label": u.value.password,
187
+ t(fe, {
188
+ modelValue: C.value,
189
+ "onUpdate:modelValue": v[2] || (v[2] = (K) => C.value = K),
190
+ type: w.value ? "text" : "password",
191
+ placeholder: n.value.password,
192
+ "aria-label": n.value.password,
186
193
  autocomplete: "current-password",
187
194
  size: "lg",
188
- onKeydown: y,
189
- onKeyup: y
195
+ onKeydown: A,
196
+ onKeyup: A
190
197
  }, {
191
198
  prefix: l(() => [
192
- n(Z, { name: "lock" })
199
+ t(ee, { name: "lock" })
193
200
  ]),
194
201
  suffix: l(() => [
195
- E("button", {
202
+ N("button", {
196
203
  type: "button",
197
204
  class: "wx-login__reveal",
198
- title: f.value ? u.value.hide : u.value.reveal,
199
- "aria-label": f.value ? u.value.hide : u.value.reveal,
200
- "aria-pressed": f.value,
205
+ title: w.value ? n.value.hide : n.value.reveal,
206
+ "aria-label": w.value ? n.value.hide : n.value.reveal,
207
+ "aria-pressed": w.value,
201
208
  tabindex: "-1",
202
- onClick: d[1] || (d[1] = (P) => f.value = !f.value)
209
+ onClick: v[1] || (v[1] = (K) => w.value = !w.value)
203
210
  }, [
204
- n(Z, {
205
- name: f.value ? "eye-off" : "eye"
211
+ t(ee, {
212
+ name: w.value ? "eye-off" : "eye"
206
213
  }, null, 8, ["name"])
207
- ], 8, Ke)
214
+ ], 8, je)
208
215
  ]),
209
216
  _: 1
210
217
  }, 8, ["modelValue", "type", "placeholder", "aria-label"])
211
218
  ]),
212
219
  _: 1
213
220
  }, 8, ["help"]),
214
- a.remember ? (k(), U($e, {
221
+ a.remember ? (L(), S(Fe, {
215
222
  key: 2,
216
223
  modelValue: V.value,
217
- "onUpdate:modelValue": d[3] || (d[3] = (P) => V.value = P),
218
- label: u.value.remember,
224
+ "onUpdate:modelValue": v[3] || (v[3] = (K) => V.value = K),
225
+ label: n.value.remember,
219
226
  class: "wx-login__remember"
220
- }, null, 8, ["modelValue", "label"])) : M("", !0),
221
- n(Se, {
227
+ }, null, 8, ["modelValue", "label"])) : T("", !0),
228
+ t(Se, {
222
229
  type: "primary",
223
230
  "native-type": "submit",
224
231
  size: "lg",
225
232
  block: "",
226
- loading: c.value,
227
- disabled: B.value
233
+ loading: d.value,
234
+ disabled: z.value
228
235
  }, {
229
236
  default: l(() => [
230
- S($(u.value.submit), 1)
237
+ F($(n.value.submit), 1)
231
238
  ]),
232
239
  _: 1
233
240
  }, 8, ["loading", "disabled"])
@@ -239,12 +246,12 @@ const Ke = ["title", "aria-label", "aria-pressed"], je = /* @__PURE__ */ O({
239
246
  });
240
247
  };
241
248
  }
242
- }), Ve = (a, i) => {
243
- const o = a.__vccOpts || a;
244
- for (const [t, r] of i)
245
- o[t] = r;
246
- return o;
247
- }, qe = /* @__PURE__ */ Ve(je, [["__scopeId", "data-v-3c206e31"]]), Ae = {
249
+ }), ve = (a, i) => {
250
+ const s = a.__vccOpts || a;
251
+ for (const [o, u] of i)
252
+ s[o] = u;
253
+ return s;
254
+ }, He = /* @__PURE__ */ ve(qe, [["__scopeId", "data-v-3c206e31"]]), $e = {
248
255
  card: {
249
256
  email: "Email",
250
257
  password: "Password",
@@ -302,52 +309,67 @@ const Ke = ["title", "aria-label", "aria-pressed"], je = /* @__PURE__ */ O({
302
309
  "not-yourself": "You cannot do that to your own account.",
303
310
  "last-super": "There has to be one super administrator left."
304
311
  },
312
+ // Somebody editing themselves, which is a shorter list than an administrator editing them.
313
+ profile: {
314
+ title: "Your profile",
315
+ menu: "Edit your profile",
316
+ name: "Name",
317
+ avatar: "Photo",
318
+ password: "New password",
319
+ "password-hint": "At least 12 characters. Leave blank to keep the current one.",
320
+ "current-password": "Current password",
321
+ "current-password-hint": "Asked for before the password is changed.",
322
+ "wrong-password": "That is not the current password.",
323
+ saved: "Your profile is saved.",
324
+ save: "Save",
325
+ cancel: "Cancel"
326
+ },
305
327
  menu: {
306
328
  "sign-out": "Sign out",
307
329
  language: "Interface language"
308
330
  }
309
331
  };
310
- function se(a) {
311
- const i = `${a.apiPath}/auth`, o = (t) => t.data;
332
+ function pe(a) {
333
+ const i = `${a.apiPath}/auth`, s = (o) => o.data;
312
334
  return {
313
- list: (t = {}) => a.http.get(`${i}/admins`, {
335
+ list: (o = {}) => a.http.get(`${i}/admins`, {
314
336
  query: {
315
- q: t.q || void 0,
316
- role: t.role ?? void 0,
317
- active: t.active ?? void 0,
318
- sort: t.sort,
319
- page: t.page,
320
- per_page: t.per_page
337
+ q: o.q || void 0,
338
+ role: o.role ?? void 0,
339
+ active: o.active ?? void 0,
340
+ sort: o.sort,
341
+ page: o.page,
342
+ per_page: o.per_page
321
343
  }
322
- }).then((r) => ({ ...r.meta, data: r.data })),
323
- get: (t) => a.http.get(`${i}/admins/${t}`).then(o),
324
- create: (t) => a.http.post(`${i}/admins`, t).then(o),
325
- update: (t, r) => a.http.patch(`${i}/admins/${t}`, r).then(o),
326
- remove: (t) => a.http.delete(`${i}/admins/${t}`),
327
- roles: () => a.http.get(`${i}/roles`).then(o)
344
+ }).then((u) => ({ ...u.meta, data: u.data })),
345
+ get: (o) => a.http.get(`${i}/admins/${o}`).then(s),
346
+ create: (o) => a.http.post(`${i}/admins`, o).then(s),
347
+ update: (o, u) => a.http.patch(`${i}/admins/${o}`, u).then(s),
348
+ remove: (o) => a.http.delete(`${i}/admins/${o}`),
349
+ roles: () => a.http.get(`${i}/roles`).then(s)
328
350
  };
329
351
  }
330
- const ce = /* @__PURE__ */ new WeakSet();
331
- function X() {
352
+ const ye = /* @__PURE__ */ new WeakSet();
353
+ function J() {
332
354
  try {
333
- const { i18n: a } = H();
334
- ce.has(a) || (a.defaults("webx-auth", Ae), ce.add(a));
355
+ const { i18n: a } = q();
356
+ ye.has(a) || (a.defaults("webx-auth", $e), ye.add(a));
335
357
  } catch {
336
358
  }
337
359
  }
338
- const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge = {
360
+ const Ge = { class: "wx-admin-form" }, Je = { class: "wx-admin-form__grid" }, Qe = {
339
361
  key: 0,
340
362
  class: "wx-admin-form__aside"
341
- }, Je = { class: "wx-admin-form__fields" }, Qe = /* @__PURE__ */ O({
363
+ }, Xe = { class: "wx-admin-form__fields" }, Ze = /* @__PURE__ */ R({
342
364
  __name: "AdminDialog",
343
365
  props: {
344
366
  admin: { default: null },
345
367
  avatarField: { default: void 0 }
346
368
  },
347
369
  setup(a) {
348
- const i = a, { resolve: o, dismiss: t, open: r } = we(), x = H(), m = se(x), u = he();
349
- X();
350
- const p = R("webx-auth"), L = be(), V = g([]), c = g(!1), f = g({}), s = g({
370
+ const i = a, { resolve: s, dismiss: o, open: u } = ie(), k = q(), m = pe(k), n = ke();
371
+ J();
372
+ const p = I("webx-auth"), C = re(), V = g([]), d = g(!1), w = g({}), r = g({
351
373
  name: "",
352
374
  email: "",
353
375
  password: "",
@@ -356,81 +378,81 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
356
378
  is_super: !1,
357
379
  locale: null,
358
380
  roles: []
359
- }), _ = F({
360
- get: () => s.value.avatar ? { path: s.value.avatar } : null,
361
- set: (b) => {
362
- s.value.avatar = b?.path ?? null;
381
+ }), b = P({
382
+ get: () => r.value.avatar ? { path: r.value.avatar } : null,
383
+ set: (h) => {
384
+ r.value.avatar = h?.path ?? null;
363
385
  }
364
- }), A = F(() => i.admin !== null), W = F(() => V.value.map((b) => ({ value: b.id, label: b.name }))), T = F(() => [
386
+ }), _ = P(() => i.admin !== null), f = P(() => V.value.map((h) => ({ value: h.id, label: h.name }))), U = P(() => [
365
387
  { value: "auto", label: p("admins.locale-auto") },
366
- ...u.state.panelLocales.map((b) => ({ value: b.code, label: b.nativeName }))
388
+ ...n.state.panelLocales.map((h) => ({ value: h.code, label: h.nativeName }))
367
389
  ]);
368
- m.roles().then((b) => V.value = b), Q(
390
+ m.roles().then((h) => V.value = h), Z(
369
391
  () => i.admin,
370
- (b) => {
371
- s.value = {
372
- name: b?.name ?? "",
373
- email: b?.email ?? "",
392
+ (h) => {
393
+ r.value = {
394
+ name: h?.name ?? "",
395
+ email: h?.email ?? "",
374
396
  password: "",
375
- avatar: b?.avatar ?? null,
376
- is_active: b?.is_active ?? !0,
377
- is_super: b?.is_super ?? !1,
378
- locale: b?.locale ?? "auto",
379
- roles: b?.roles.map((v) => v.id) ?? []
380
- }, f.value = {};
397
+ avatar: h?.avatar ?? null,
398
+ is_active: h?.is_active ?? !0,
399
+ is_super: h?.is_super ?? !1,
400
+ locale: h?.locale ?? "auto",
401
+ roles: h?.roles.map((c) => c.id) ?? []
402
+ }, w.value = {};
381
403
  },
382
404
  { immediate: !0 }
383
405
  );
384
- function C(b) {
385
- return f.value[b]?.[0];
406
+ function W(h) {
407
+ return w.value[h]?.[0];
386
408
  }
387
- async function B() {
388
- c.value = !0, f.value = {};
389
- const b = {
390
- name: s.value.name,
391
- email: s.value.email,
392
- avatar: s.value.avatar,
393
- is_active: s.value.is_active,
394
- is_super: s.value.is_super,
395
- locale: s.value.locale === "auto" ? null : s.value.locale,
396
- roles: s.value.roles ?? []
409
+ async function z() {
410
+ d.value = !0, w.value = {};
411
+ const h = {
412
+ name: r.value.name,
413
+ email: r.value.email,
414
+ avatar: r.value.avatar,
415
+ is_active: r.value.is_active,
416
+ is_super: r.value.is_super,
417
+ locale: r.value.locale === "auto" ? null : r.value.locale,
418
+ roles: r.value.roles ?? []
397
419
  };
398
- s.value.password && (b.password = s.value.password);
420
+ r.value.password && (h.password = r.value.password);
399
421
  try {
400
- const v = i.admin ? await m.update(i.admin.id, b) : await m.create(b);
401
- J.success(p(A.value ? "admins.updated" : "admins.created")), o(v);
402
- } catch (v) {
403
- const w = v.body;
404
- w?.errors ? f.value = w.errors : J.danger(L(v));
422
+ const c = i.admin ? await m.update(i.admin.id, h) : await m.create(h);
423
+ j.success(p(_.value ? "admins.updated" : "admins.created")), s(c);
424
+ } catch (c) {
425
+ const x = c.body;
426
+ x?.errors ? w.value = x.errors : j.danger(C(c));
405
427
  } finally {
406
- c.value = !1;
428
+ d.value = !1;
407
429
  }
408
430
  }
409
- return (b, v) => (k(), U(e(ye), {
410
- open: e(r),
411
- "onUpdate:open": v[9] || (v[9] = (w) => ve(r) ? r.value = w : null),
412
- title: A.value ? e(p)("admins.edit-short") : e(p)("admins.new-short"),
431
+ return (h, c) => (L(), S(e(ue), {
432
+ open: e(u),
433
+ "onUpdate:open": c[9] || (c[9] = (x) => se(u) ? u.value = x : null),
434
+ title: _.value ? e(p)("admins.edit-short") : e(p)("admins.new-short"),
413
435
  width: 720
414
436
  }, {
415
437
  footer: l(() => [
416
- n(e(N), { size: "sm" }, {
438
+ t(e(Y), { size: "sm" }, {
417
439
  default: l(() => [
418
- n(e(q), {
440
+ t(e(D), {
419
441
  variant: "outline",
420
- onClick: v[8] || (v[8] = (w) => e(t)())
442
+ onClick: c[8] || (c[8] = (x) => e(o)())
421
443
  }, {
422
444
  default: l(() => [
423
- S($(e(p)("admins.cancel")), 1)
445
+ F($(e(p)("admins.cancel")), 1)
424
446
  ]),
425
447
  _: 1
426
448
  }),
427
- n(e(q), {
449
+ t(e(D), {
428
450
  type: "primary",
429
- loading: c.value,
430
- onClick: B
451
+ loading: d.value,
452
+ onClick: z
431
453
  }, {
432
454
  default: l(() => [
433
- S($(e(p)("admins.save")), 1)
455
+ F($(e(p)("admins.save")), 1)
434
456
  ]),
435
457
  _: 1
436
458
  }, 8, ["loading"])
@@ -439,39 +461,39 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
439
461
  })
440
462
  ]),
441
463
  default: l(() => [
442
- E("div", He, [
443
- E("div", Ye, [
444
- a.avatarField ? (k(), j("div", Ge, [
445
- (k(), U(Be(a.avatarField), {
446
- modelValue: _.value,
447
- "onUpdate:modelValue": v[0] || (v[0] = (w) => _.value = w),
464
+ N("div", Ge, [
465
+ N("div", Je, [
466
+ a.avatarField ? (L(), O("div", Qe, [
467
+ (L(), S(ge(a.avatarField), {
468
+ modelValue: b.value,
469
+ "onUpdate:modelValue": c[0] || (c[0] = (x) => b.value = x),
448
470
  label: e(p)("admins.avatar"),
449
471
  aspect: "1/1",
450
472
  captions: !1
451
473
  }, null, 8, ["modelValue", "label"]))
452
- ])) : M("", !0),
453
- E("div", Je, [
454
- n(e(K), {
474
+ ])) : T("", !0),
475
+ N("div", Xe, [
476
+ t(e(M), {
455
477
  label: e(p)("admins.name"),
456
- error: C("name")
478
+ error: W("name")
457
479
  }, {
458
480
  default: l(() => [
459
- n(e(ee), {
460
- modelValue: s.value.name,
461
- "onUpdate:modelValue": v[1] || (v[1] = (w) => s.value.name = w),
481
+ t(e(E), {
482
+ modelValue: r.value.name,
483
+ "onUpdate:modelValue": c[1] || (c[1] = (x) => r.value.name = x),
462
484
  name: "name"
463
485
  }, null, 8, ["modelValue"])
464
486
  ]),
465
487
  _: 1
466
488
  }, 8, ["label", "error"]),
467
- n(e(K), {
489
+ t(e(M), {
468
490
  label: e(p)("admins.email"),
469
- error: C("email")
491
+ error: W("email")
470
492
  }, {
471
493
  default: l(() => [
472
- n(e(ee), {
473
- modelValue: s.value.email,
474
- "onUpdate:modelValue": v[2] || (v[2] = (w) => s.value.email = w),
494
+ t(e(E), {
495
+ modelValue: r.value.email,
496
+ "onUpdate:modelValue": c[2] || (c[2] = (x) => r.value.email = x),
475
497
  type: "email",
476
498
  name: "email",
477
499
  autocomplete: "off"
@@ -479,15 +501,15 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
479
501
  ]),
480
502
  _: 1
481
503
  }, 8, ["label", "error"]),
482
- n(e(K), {
504
+ t(e(M), {
483
505
  label: e(p)("admins.password"),
484
- error: C("password"),
485
- help: A.value ? e(p)("admins.password-keep") : e(p)("admins.password-hint")
506
+ error: W("password"),
507
+ help: _.value ? e(p)("admins.password-keep") : e(p)("admins.password-hint")
486
508
  }, {
487
509
  default: l(() => [
488
- n(e(ee), {
489
- modelValue: s.value.password,
490
- "onUpdate:modelValue": v[3] || (v[3] = (w) => s.value.password = w),
510
+ t(e(E), {
511
+ modelValue: r.value.password,
512
+ "onUpdate:modelValue": c[3] || (c[3] = (x) => r.value.password = x),
491
513
  type: "password",
492
514
  name: "password",
493
515
  autocomplete: "new-password"
@@ -495,53 +517,53 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
495
517
  ]),
496
518
  _: 1
497
519
  }, 8, ["label", "error", "help"]),
498
- n(e(K), {
520
+ t(e(M), {
499
521
  label: e(p)("admins.roles"),
500
- error: C("roles")
522
+ error: W("roles")
501
523
  }, {
502
524
  default: l(() => [
503
- n(e(G), {
504
- modelValue: s.value.roles,
505
- "onUpdate:modelValue": v[4] || (v[4] = (w) => s.value.roles = w),
506
- options: W.value,
525
+ t(e(X), {
526
+ modelValue: r.value.roles,
527
+ "onUpdate:modelValue": c[4] || (c[4] = (x) => r.value.roles = x),
528
+ options: f.value,
507
529
  multiple: ""
508
530
  }, null, 8, ["modelValue", "options"])
509
531
  ]),
510
532
  _: 1
511
533
  }, 8, ["label", "error"]),
512
- n(e(K), {
534
+ t(e(M), {
513
535
  label: e(p)("admins.locale")
514
536
  }, {
515
537
  default: l(() => [
516
- n(e(G), {
517
- modelValue: s.value.locale,
518
- "onUpdate:modelValue": v[5] || (v[5] = (w) => s.value.locale = w),
519
- options: T.value
538
+ t(e(X), {
539
+ modelValue: r.value.locale,
540
+ "onUpdate:modelValue": c[5] || (c[5] = (x) => r.value.locale = x),
541
+ options: U.value
520
542
  }, null, 8, ["modelValue", "options"])
521
543
  ]),
522
544
  _: 1
523
545
  }, 8, ["label"]),
524
- n(e(N), { size: "md" }, {
546
+ t(e(Y), { size: "md" }, {
525
547
  default: l(() => [
526
- n(e(de), {
527
- modelValue: s.value.is_active,
528
- "onUpdate:modelValue": v[6] || (v[6] = (w) => s.value.is_active = w),
548
+ t(e(be), {
549
+ modelValue: r.value.is_active,
550
+ "onUpdate:modelValue": c[6] || (c[6] = (x) => r.value.is_active = x),
529
551
  label: e(p)("admins.active")
530
552
  }, null, 8, ["modelValue", "label"]),
531
- n(e(de), {
532
- modelValue: s.value.is_super,
533
- "onUpdate:modelValue": v[7] || (v[7] = (w) => s.value.is_super = w),
553
+ t(e(be), {
554
+ modelValue: r.value.is_super,
555
+ "onUpdate:modelValue": c[7] || (c[7] = (x) => r.value.is_super = x),
534
556
  label: e(p)("admins.super")
535
557
  }, null, 8, ["modelValue", "label"])
536
558
  ]),
537
559
  _: 1
538
560
  }),
539
- n(e(oe), {
561
+ t(e(de), {
540
562
  size: "sm",
541
563
  tone: "muted"
542
564
  }, {
543
565
  default: l(() => [
544
- S($(e(p)("admins.super-hint")), 1)
566
+ F($(e(p)("admins.super-hint")), 1)
545
567
  ]),
546
568
  _: 1
547
569
  })
@@ -552,7 +574,7 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
552
574
  _: 1
553
575
  }, 8, ["open", "title"]));
554
576
  }
555
- }), Xe = { class: "wx-admin-list" }, Le = /* @__PURE__ */ O({
577
+ }), ea = { class: "wx-admin-list" }, Ce = /* @__PURE__ */ R({
556
578
  __name: "AdminList",
557
579
  props: {
558
580
  picking: { type: Boolean, default: !1 },
@@ -562,26 +584,26 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
562
584
  resolveAvatar: { type: Function, default: void 0 }
563
585
  },
564
586
  emits: ["open", "chosen", "selection", "remove"],
565
- setup(a, { expose: i, emit: o }) {
566
- const t = a, r = o, x = H(), m = se(x);
567
- X();
568
- const u = R("webx-auth"), p = g(null), L = g([]), V = g(!1), c = g("all"), f = g("any"), s = g([]), _ = g({});
569
- let A = { page: 1, perPage: 20, sort: null, search: "" };
570
- const W = F(() => [
571
- { value: "all", label: u("admins.all-roles") },
572
- ...L.value.map((y) => ({ value: y.slug, label: y.name }))
573
- ]), T = F(() => [
574
- { value: "any", label: u("admins.any-state") },
575
- { value: "yes", label: u("admins.only-active") },
576
- { value: "no", label: u("admins.only-inactive") }
577
- ]), C = F(() => [
578
- { key: "name", label: u("admins.name"), sortable: !0 },
579
- { key: "email", label: u("admins.email"), sortable: !0, hideBelow: 560 },
580
- { key: "roles", label: u("admins.roles"), hideBelow: 760 },
581
- { key: "is_active", label: u("admins.active"), align: "center", hideBelow: 660 },
587
+ setup(a, { expose: i, emit: s }) {
588
+ const o = a, u = s, k = q(), m = pe(k);
589
+ J();
590
+ const n = I("webx-auth"), p = g(null), C = g([]), V = g(!1), d = g("all"), w = g("any"), r = g([]), b = g({});
591
+ let _ = { page: 1, perPage: 20, sort: null, search: "" };
592
+ const f = P(() => [
593
+ { value: "all", label: n("admins.all-roles") },
594
+ ...C.value.map((A) => ({ value: A.slug, label: A.name }))
595
+ ]), U = P(() => [
596
+ { value: "any", label: n("admins.any-state") },
597
+ { value: "yes", label: n("admins.only-active") },
598
+ { value: "no", label: n("admins.only-inactive") }
599
+ ]), W = P(() => [
600
+ { key: "name", label: n("admins.name"), sortable: !0 },
601
+ { key: "email", label: n("admins.email"), sortable: !0, hideBelow: 560 },
602
+ { key: "roles", label: n("admins.roles"), hideBelow: 760 },
603
+ { key: "is_active", label: n("admins.active"), align: "center", hideBelow: 660 },
582
604
  {
583
605
  key: "last_login_at",
584
- label: u("admins.last-login"),
606
+ label: n("admins.last-login"),
585
607
  sortable: !0,
586
608
  hideBelow: 900,
587
609
  // The first thing to go when a row becomes a card: it is a date somebody scans down a
@@ -593,156 +615,156 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
593
615
  label: "",
594
616
  width: 56,
595
617
  align: "right",
596
- hidden: !t.removable,
618
+ hidden: !o.removable,
597
619
  // A card puts them along its top instead, through the `card-actions` slot.
598
620
  hideOnCards: !0
599
621
  }
600
622
  ]);
601
- m.roles().then((y) => L.value = y), Q([c, f], () => B(A));
602
- async function B(y) {
603
- A = y, V.value = !0;
623
+ m.roles().then((A) => C.value = A), Z([d, w], () => z(_));
624
+ async function z(A) {
625
+ _ = A, V.value = !0;
604
626
  try {
605
627
  p.value = await m.list({
606
- q: y.search,
607
- role: c.value === "all" ? null : c.value,
608
- active: f.value === "any" ? null : f.value,
609
- sort: y.sort ? `${y.sort.order === "desc" ? "-" : ""}${y.sort.key}` : "name",
610
- page: y.page,
611
- per_page: y.perPage
612
- }), b();
628
+ q: A.search,
629
+ role: d.value === "all" ? null : d.value,
630
+ active: w.value === "any" ? null : w.value,
631
+ sort: A.sort ? `${A.sort.order === "desc" ? "-" : ""}${A.sort.key}` : "name",
632
+ page: A.page,
633
+ per_page: A.perPage
634
+ }), h();
613
635
  } finally {
614
636
  V.value = !1;
615
637
  }
616
638
  }
617
- async function b() {
618
- const y = t.resolveAvatar;
619
- if (y)
620
- for (const h of p.value?.data ?? []) {
621
- if (!h.avatar || _.value[h.avatar]) continue;
622
- const d = await y(h.avatar);
623
- d && (_.value = { ..._.value, [h.avatar]: d });
639
+ async function h() {
640
+ const A = o.resolveAvatar;
641
+ if (A)
642
+ for (const y of p.value?.data ?? []) {
643
+ if (!y.avatar || b.value[y.avatar]) continue;
644
+ const v = await A(y.avatar);
645
+ v && (b.value = { ...b.value, [y.avatar]: v });
624
646
  }
625
647
  }
626
- function v(y) {
648
+ function c(A) {
627
649
  return [
628
650
  {
629
651
  key: "delete",
630
652
  icon: "trash",
631
- label: u("admins.delete"),
653
+ label: n("admins.delete"),
632
654
  danger: !0,
633
- run: () => r("remove", y)
655
+ run: () => u("remove", A)
634
656
  }
635
657
  ];
636
658
  }
637
- function w(y) {
638
- if (t.picking) {
639
- r("chosen", [y]);
659
+ function x(A) {
660
+ if (o.picking) {
661
+ u("chosen", [A]);
640
662
  return;
641
663
  }
642
- r("open", y);
664
+ u("open", A);
643
665
  }
644
- const Y = F(() => !(t.picking && t.multiple));
645
- function I(y, h) {
646
- s.value = h, r("selection", h);
666
+ const Q = P(() => !(o.picking && o.multiple));
667
+ function H(A, y) {
668
+ r.value = y, u("selection", y);
647
669
  }
648
- return i({ reload: () => B(A), chosen: () => s.value }), (y, h) => (k(), j("div", Xe, [
649
- n(e(Ee), {
670
+ return i({ reload: () => z(_), chosen: () => r.value }), (A, y) => (L(), O("div", ea, [
671
+ t(e(Oe), {
650
672
  data: p.value,
651
- columns: C.value,
673
+ columns: W.value,
652
674
  "row-key": "id",
653
675
  searchable: "",
654
- clickable: Y.value,
655
- hover: Y.value,
676
+ clickable: Q.value,
677
+ hover: Q.value,
656
678
  flush: "",
657
679
  loading: V.value,
658
- "search-placeholder": e(u)("admins.search"),
659
- "empty-text": e(u)("admins.empty"),
680
+ "search-placeholder": e(n)("admins.search"),
681
+ "empty-text": e(n)("admins.empty"),
660
682
  selectable: a.picking && a.multiple,
661
- onRowClick: w,
662
- onStateChange: B,
663
- onSelectionChange: I
683
+ onRowClick: x,
684
+ onStateChange: z,
685
+ onSelectionChange: H
664
686
  }, ne({
665
- "cell-name": l(({ row: d }) => [
666
- n(e(N), {
687
+ "cell-name": l(({ row: v }) => [
688
+ t(e(Y), {
667
689
  size: "sm",
668
690
  align: "center"
669
691
  }, {
670
692
  default: l(() => [
671
- n(e(Ne), {
672
- name: d.name,
673
- src: d.avatar ? _.value[d.avatar] : void 0,
693
+ t(e(De), {
694
+ name: v.name,
695
+ src: v.avatar ? b.value[v.avatar] : void 0,
674
696
  size: "sm"
675
697
  }, null, 8, ["name", "src"]),
676
- E("span", null, $(d.name), 1),
677
- d.is_super ? (k(), U(e(ae), {
698
+ N("span", null, $(v.name), 1),
699
+ v.is_super ? (L(), S(e(ae), {
678
700
  key: 0,
679
701
  type: "warning"
680
702
  }, {
681
703
  default: l(() => [
682
- S($(e(u)("admins.super")), 1)
704
+ F($(e(n)("admins.super")), 1)
683
705
  ]),
684
706
  _: 1
685
- })) : M("", !0)
707
+ })) : T("", !0)
686
708
  ]),
687
709
  _: 2
688
710
  }, 1024)
689
711
  ]),
690
- "cell-roles": l(({ row: d }) => [
691
- d.roles.length > 0 ? (k(), U(e(N), {
712
+ "cell-roles": l(({ row: v }) => [
713
+ v.roles.length > 0 ? (L(), S(e(Y), {
692
714
  key: 0,
693
715
  size: "xs",
694
716
  wrap: ""
695
717
  }, {
696
718
  default: l(() => [
697
- (k(!0), j(te, null, pe(d.roles, (D) => (k(), U(e(ae), {
698
- key: D.id
719
+ (L(!0), O(le, null, _e(v.roles, (G) => (L(), S(e(ae), {
720
+ key: G.id
699
721
  }, {
700
722
  default: l(() => [
701
- S($(D.name), 1)
723
+ F($(G.name), 1)
702
724
  ]),
703
725
  _: 2
704
726
  }, 1024))), 128))
705
727
  ]),
706
728
  _: 2
707
- }, 1024)) : (k(), U(e(oe), {
729
+ }, 1024)) : (L(), S(e(de), {
708
730
  key: 1,
709
731
  size: "sm",
710
732
  tone: "muted"
711
733
  }, {
712
734
  default: l(() => [
713
- S($(e(u)("admins.no-roles")), 1)
735
+ F($(e(n)("admins.no-roles")), 1)
714
736
  ]),
715
737
  _: 1
716
738
  }))
717
739
  ]),
718
- "cell-is_active": l(({ row: d }) => [
719
- n(e(ae), {
720
- type: d.is_active ? "success" : "default",
740
+ "cell-is_active": l(({ row: v }) => [
741
+ t(e(ae), {
742
+ type: v.is_active ? "success" : "default",
721
743
  dot: ""
722
744
  }, {
723
745
  default: l(() => [
724
- S($(d.is_active ? e(u)("admins.active") : e(u)("admins.only-inactive")), 1)
746
+ F($(v.is_active ? e(n)("admins.active") : e(n)("admins.only-inactive")), 1)
725
747
  ]),
726
748
  _: 2
727
749
  }, 1032, ["type"])
728
750
  ]),
729
- "card-actions": l(({ row: d }) => [
730
- a.removable ? (k(), U(e(ue), {
751
+ "card-actions": l(({ row: v }) => [
752
+ a.removable ? (L(), S(e(he), {
731
753
  key: 0,
732
- actions: v(d),
733
- label: d.name
734
- }, null, 8, ["actions", "label"])) : M("", !0)
754
+ actions: c(v),
755
+ label: v.name
756
+ }, null, 8, ["actions", "label"])) : T("", !0)
735
757
  ]),
736
- "cell-actions": l(({ row: d }) => [
737
- n(e(ue), {
738
- actions: v(d),
739
- label: d.name
758
+ "cell-actions": l(({ row: v }) => [
759
+ t(e(he), {
760
+ actions: c(v),
761
+ label: v.name
740
762
  }, null, 8, ["actions", "label"])
741
763
  ]),
742
- "cell-last_login_at": l(({ row: d }) => [
743
- n(e(Me), {
744
- value: d.last_login_at,
745
- tone: d.last_login_at ? "default" : "muted"
764
+ "cell-last_login_at": l(({ row: v }) => [
765
+ t(e(Ne), {
766
+ value: v.last_login_at,
767
+ tone: v.last_login_at ? "default" : "muted"
746
768
  }, null, 8, ["value", "tone"])
747
769
  ]),
748
770
  _: 2
@@ -750,19 +772,19 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
750
772
  a.filters ? {
751
773
  name: "actions",
752
774
  fn: l(() => [
753
- n(e(N), { size: "sm" }, {
775
+ t(e(Y), { size: "sm" }, {
754
776
  default: l(() => [
755
- n(e(G), {
756
- modelValue: c.value,
757
- "onUpdate:modelValue": h[0] || (h[0] = (d) => c.value = d),
758
- options: W.value,
777
+ t(e(X), {
778
+ modelValue: d.value,
779
+ "onUpdate:modelValue": y[0] || (y[0] = (v) => d.value = v),
780
+ options: f.value,
759
781
  size: "sm",
760
782
  style: { width: "180px" }
761
783
  }, null, 8, ["modelValue", "options"]),
762
- n(e(G), {
763
- modelValue: f.value,
764
- "onUpdate:modelValue": h[1] || (h[1] = (d) => f.value = d),
765
- options: T.value,
784
+ t(e(X), {
785
+ modelValue: w.value,
786
+ "onUpdate:modelValue": y[1] || (y[1] = (v) => w.value = v),
787
+ options: U.value,
766
788
  size: "sm",
767
789
  style: { width: "180px" }
768
790
  }, null, 8, ["modelValue", "options"])
@@ -775,58 +797,58 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
775
797
  ]), 1032, ["data", "columns", "clickable", "hover", "loading", "search-placeholder", "empty-text", "selectable"])
776
798
  ]));
777
799
  }
778
- }), Ze = /* @__PURE__ */ O({
800
+ }), aa = /* @__PURE__ */ R({
779
801
  __name: "AdminsPage",
780
802
  props: {
781
803
  avatarField: { default: void 0 },
782
804
  resolveAvatar: { type: Function, default: void 0 }
783
805
  },
784
806
  setup(a) {
785
- const i = a, o = H(), t = se(o);
786
- X();
787
- const r = R("webx-auth"), x = be(), m = le("list"), u = g(null), p = ge(Qe), L = o.can("admins.manage"), V = F(
788
- () => o.state.manifest?.modules.find((s) => s.id === "admins")?.title ?? r("admins.title")
807
+ const i = a, s = q(), o = pe(s);
808
+ J();
809
+ const u = I("webx-auth"), k = re(), m = oe("list"), n = g(null), p = ce(Ze), C = s.can("admins.manage"), V = P(
810
+ () => s.state.manifest?.modules.find((r) => r.id === "admins")?.title ?? u("admins.title")
789
811
  );
790
- async function c(s) {
791
- u.value = s, await p({ admin: s, avatarField: i.avatarField }) && m.value?.reload();
812
+ async function d(r) {
813
+ n.value = r, await p({ admin: r, avatarField: i.avatarField }) && m.value?.reload();
792
814
  }
793
- async function f(s) {
794
- if (await Oe({
795
- title: r("admins.delete-title", { name: s.name }),
796
- message: r("admins.delete-text"),
797
- confirmText: r("admins.delete"),
798
- cancelText: r("admins.cancel"),
815
+ async function w(r) {
816
+ if (await Re({
817
+ title: u("admins.delete-title", { name: r.name }),
818
+ message: u("admins.delete-text"),
819
+ confirmText: u("admins.delete"),
820
+ cancelText: u("admins.cancel"),
799
821
  tone: "danger"
800
822
  }))
801
823
  try {
802
- await t.remove(s.id), J.success(r("admins.deleted")), m.value?.reload();
803
- } catch (A) {
804
- J.danger(x(A));
824
+ await o.remove(r.id), j.success(u("admins.deleted")), m.value?.reload();
825
+ } catch (_) {
826
+ j.danger(k(_));
805
827
  }
806
828
  }
807
- return (s, _) => (k(), U(e(Pe), { title: V.value }, ne({
829
+ return (r, b) => (L(), S(e(Ee), { title: V.value }, ne({
808
830
  default: l(() => [
809
- n(Le, {
831
+ t(Ce, {
810
832
  ref_key: "list",
811
833
  ref: m,
812
- removable: e(L),
834
+ removable: e(C),
813
835
  "resolve-avatar": i.resolveAvatar,
814
- onOpen: c,
815
- onRemove: f
836
+ onOpen: d,
837
+ onRemove: w
816
838
  }, null, 8, ["removable", "resolve-avatar"])
817
839
  ]),
818
840
  _: 2
819
841
  }, [
820
- e(L) ? {
842
+ e(C) ? {
821
843
  name: "actions",
822
844
  fn: l(() => [
823
- n(e(q), {
845
+ t(e(D), {
824
846
  type: "primary",
825
847
  icon: "add",
826
- onClick: _[0] || (_[0] = (A) => c(null))
848
+ onClick: b[0] || (b[0] = (_) => d(null))
827
849
  }, {
828
850
  default: l(() => [
829
- S($(e(r)("admins.new-short")), 1)
851
+ F($(e(u)("admins.new-short")), 1)
830
852
  ]),
831
853
  _: 1
832
854
  })
@@ -836,7 +858,7 @@ const He = { class: "wx-admin-form" }, Ye = { class: "wx-admin-form__grid" }, Ge
836
858
  ]), 1032, ["title"]));
837
859
  }
838
860
  });
839
- function sa(a = {}) {
861
+ function fa(a = {}) {
840
862
  const i = a.path ?? "/admins";
841
863
  return {
842
864
  id: "admins",
@@ -846,7 +868,7 @@ function sa(a = {}) {
846
868
  path: i,
847
869
  name: "webx.admins",
848
870
  component: {
849
- render: () => fe(Ze, {
871
+ render: () => xe(aa, {
850
872
  avatarField: a.avatarField,
851
873
  resolveAvatar: a.resolveAvatar
852
874
  })
@@ -855,7 +877,7 @@ function sa(a = {}) {
855
877
  ]
856
878
  };
857
879
  }
858
- const ea = /* @__PURE__ */ O({
880
+ const ta = /* @__PURE__ */ R({
859
881
  __name: "AdminPicker",
860
882
  props: {
861
883
  multiple: { type: Boolean, default: !1 },
@@ -863,30 +885,30 @@ const ea = /* @__PURE__ */ O({
863
885
  resolveAvatar: { type: Function, default: void 0 }
864
886
  },
865
887
  setup(a) {
866
- const i = a, { open: o, resolve: t, dismiss: r } = we();
867
- X();
868
- const x = R("webx-auth"), m = le("list"), u = g(0);
888
+ const i = a, { open: s, resolve: o, dismiss: u } = ie();
889
+ J();
890
+ const k = I("webx-auth"), m = oe("list"), n = g(0);
869
891
  function p(V) {
870
- t(V);
892
+ o(V);
871
893
  }
872
- function L(V) {
873
- u.value = V.length;
894
+ function C(V) {
895
+ n.value = V.length;
874
896
  }
875
- return (V, c) => (k(), U(e(ye), {
876
- open: e(o),
877
- "onUpdate:open": c[2] || (c[2] = (f) => ve(o) ? o.value = f : null),
878
- title: a.title ?? e(x)(a.multiple ? "admins.select-many" : "admins.select-one"),
897
+ return (V, d) => (L(), S(e(ue), {
898
+ open: e(s),
899
+ "onUpdate:open": d[2] || (d[2] = (w) => se(s) ? s.value = w : null),
900
+ title: a.title ?? e(k)(a.multiple ? "admins.select-many" : "admins.select-one"),
879
901
  width: 880
880
902
  }, ne({
881
903
  default: l(() => [
882
- n(Le, {
904
+ t(Ce, {
883
905
  ref_key: "list",
884
906
  ref: m,
885
907
  picking: "",
886
908
  multiple: a.multiple,
887
909
  "resolve-avatar": i.resolveAvatar,
888
910
  onChosen: p,
889
- onSelection: L
911
+ onSelection: C
890
912
  }, null, 8, ["multiple", "resolve-avatar"])
891
913
  ]),
892
914
  _: 2
@@ -894,36 +916,36 @@ const ea = /* @__PURE__ */ O({
894
916
  a.multiple ? {
895
917
  name: "footer",
896
918
  fn: l(() => [
897
- n(e(N), {
919
+ t(e(Y), {
898
920
  size: "sm",
899
921
  align: "center"
900
922
  }, {
901
923
  default: l(() => [
902
- n(e(oe), {
924
+ t(e(de), {
903
925
  size: "sm",
904
926
  tone: "muted"
905
927
  }, {
906
928
  default: l(() => [
907
- S($(e(x)("admins.chosen", { count: u.value })), 1)
929
+ F($(e(k)("admins.chosen", { count: n.value })), 1)
908
930
  ]),
909
931
  _: 1
910
932
  }),
911
- n(e(q), {
933
+ t(e(D), {
912
934
  variant: "outline",
913
- onClick: c[0] || (c[0] = (f) => e(r)())
935
+ onClick: d[0] || (d[0] = (w) => e(u)())
914
936
  }, {
915
937
  default: l(() => [
916
- S($(e(x)("admins.cancel")), 1)
938
+ F($(e(k)("admins.cancel")), 1)
917
939
  ]),
918
940
  _: 1
919
941
  }),
920
- n(e(q), {
942
+ t(e(D), {
921
943
  type: "primary",
922
- disabled: u.value === 0,
923
- onClick: c[1] || (c[1] = (f) => e(t)(m.value?.chosen() ?? []))
944
+ disabled: n.value === 0,
945
+ onClick: d[1] || (d[1] = (w) => e(o)(m.value?.chosen() ?? []))
924
946
  }, {
925
947
  default: l(() => [
926
- S($(e(x)("admins.save")), 1)
948
+ F($(e(k)("admins.save")), 1)
927
949
  ]),
928
950
  _: 1
929
951
  }, 8, ["disabled"])
@@ -935,131 +957,294 @@ const ea = /* @__PURE__ */ O({
935
957
  } : void 0
936
958
  ]), 1032, ["open", "title"]));
937
959
  }
938
- }), Ce = ge(ea);
939
- async function ia(a = {}) {
940
- return (await Ce({ ...a, multiple: !1 }))?.[0];
960
+ }), Ue = ce(ta);
961
+ async function wa(a = {}) {
962
+ return (await Ue({ ...a, multiple: !1 }))?.[0];
941
963
  }
942
- function ra(a = {}) {
943
- return Ce({ ...a, multiple: !0 });
964
+ function ha(a = {}) {
965
+ return Ue({ ...a, multiple: !0 });
944
966
  }
945
- const aa = ["title"], ta = /* @__PURE__ */ O({
967
+ const la = { class: "wx-profile-host" }, oa = { class: "wx-profile" }, sa = {
968
+ key: 0,
969
+ class: "wx-profile__aside"
970
+ }, na = { class: "wx-profile__fields" }, ra = /* @__PURE__ */ R({
971
+ __name: "ProfileDialog",
972
+ props: {
973
+ avatarField: { default: void 0 }
974
+ },
975
+ setup(a) {
976
+ const i = a, { resolve: s, dismiss: o, open: u } = ie(), k = q(), m = me();
977
+ J();
978
+ const n = I("webx-auth"), p = re(), C = g(!1), V = g({}), d = g({
979
+ name: k.state.user?.name ?? "",
980
+ avatar: k.state.user?.avatar ?? null,
981
+ password: "",
982
+ current_password: ""
983
+ }), w = g(d.value.avatar ? { path: d.value.avatar } : null);
984
+ function r(_) {
985
+ return V.value[_]?.[0];
986
+ }
987
+ async function b() {
988
+ C.value = !0, V.value = {};
989
+ try {
990
+ await m.updateProfile({
991
+ name: d.value.name,
992
+ avatar: w.value?.path ?? null,
993
+ // Blank is left out entirely rather than sent as an empty string: the server reads a
994
+ // filled password as "change it", and an empty one would be a change to nothing.
995
+ ...d.value.password ? { password: d.value.password, current_password: d.value.current_password } : {}
996
+ }), j.success(n("profile.saved")), s(!0);
997
+ } catch (_) {
998
+ const f = _.body;
999
+ f?.errors ? V.value = f.errors : j.danger(p(_));
1000
+ } finally {
1001
+ C.value = !1;
1002
+ }
1003
+ }
1004
+ return (_, f) => (L(), S(e(ue), {
1005
+ open: e(u),
1006
+ "onUpdate:open": f[5] || (f[5] = (U) => se(u) ? u.value = U : null),
1007
+ title: e(n)("profile.title"),
1008
+ width: 560
1009
+ }, {
1010
+ footer: l(() => [
1011
+ t(e(D), {
1012
+ onClick: f[4] || (f[4] = (U) => e(o)())
1013
+ }, {
1014
+ default: l(() => [
1015
+ F($(e(n)("profile.cancel")), 1)
1016
+ ]),
1017
+ _: 1
1018
+ }),
1019
+ t(e(D), {
1020
+ type: "primary",
1021
+ loading: C.value,
1022
+ onClick: b
1023
+ }, {
1024
+ default: l(() => [
1025
+ F($(e(n)("profile.save")), 1)
1026
+ ]),
1027
+ _: 1
1028
+ }, 8, ["loading"])
1029
+ ]),
1030
+ default: l(() => [
1031
+ N("div", la, [
1032
+ N("div", oa, [
1033
+ i.avatarField ? (L(), O("div", sa, [
1034
+ (L(), S(ge(i.avatarField), {
1035
+ modelValue: w.value,
1036
+ "onUpdate:modelValue": f[0] || (f[0] = (U) => w.value = U),
1037
+ label: e(n)("profile.avatar"),
1038
+ aspect: "1/1",
1039
+ captions: !1
1040
+ }, null, 8, ["modelValue", "label"]))
1041
+ ])) : T("", !0),
1042
+ N("div", na, [
1043
+ t(e(M), {
1044
+ label: e(n)("profile.name"),
1045
+ error: r("name")
1046
+ }, {
1047
+ default: l(() => [
1048
+ t(e(E), {
1049
+ modelValue: d.value.name,
1050
+ "onUpdate:modelValue": f[1] || (f[1] = (U) => d.value.name = U),
1051
+ name: "name"
1052
+ }, null, 8, ["modelValue"])
1053
+ ]),
1054
+ _: 1
1055
+ }, 8, ["label", "error"]),
1056
+ t(e(M), {
1057
+ label: e(n)("admins.email")
1058
+ }, {
1059
+ default: l(() => [
1060
+ t(e(E), {
1061
+ "model-value": e(k).state.user?.email ?? "",
1062
+ readonly: ""
1063
+ }, null, 8, ["model-value"])
1064
+ ]),
1065
+ _: 1
1066
+ }, 8, ["label"]),
1067
+ t(e(M), {
1068
+ label: e(n)("profile.password"),
1069
+ help: e(n)("profile.password-hint"),
1070
+ error: r("password")
1071
+ }, {
1072
+ default: l(() => [
1073
+ t(e(E), {
1074
+ modelValue: d.value.password,
1075
+ "onUpdate:modelValue": f[2] || (f[2] = (U) => d.value.password = U),
1076
+ type: "password",
1077
+ autocomplete: "new-password"
1078
+ }, null, 8, ["modelValue"])
1079
+ ]),
1080
+ _: 1
1081
+ }, 8, ["label", "help", "error"]),
1082
+ d.value.password ? (L(), S(e(M), {
1083
+ key: 0,
1084
+ label: e(n)("profile.current-password"),
1085
+ help: e(n)("profile.current-password-hint"),
1086
+ error: r("current_password")
1087
+ }, {
1088
+ default: l(() => [
1089
+ t(e(E), {
1090
+ modelValue: d.value.current_password,
1091
+ "onUpdate:modelValue": f[3] || (f[3] = (U) => d.value.current_password = U),
1092
+ type: "password",
1093
+ autocomplete: "current-password"
1094
+ }, null, 8, ["modelValue"])
1095
+ ]),
1096
+ _: 1
1097
+ }, 8, ["label", "help", "error"])) : T("", !0)
1098
+ ])
1099
+ ])
1100
+ ])
1101
+ ]),
1102
+ _: 1
1103
+ }, 8, ["open", "title"]));
1104
+ }
1105
+ }), ia = /* @__PURE__ */ ve(ra, [["__scopeId", "data-v-9583a67a"]]), ua = ["title"], da = {
1106
+ key: 0,
1107
+ class: "wx-user-menu__name"
1108
+ }, ca = /* @__PURE__ */ R({
946
1109
  __name: "UserMenu",
947
1110
  props: {
948
1111
  signOutLabel: { default: void 0 },
949
- resolveAvatar: { type: Function, default: void 0 }
1112
+ resolveAvatar: { type: Function, default: void 0 },
1113
+ avatarField: { default: void 0 },
1114
+ expanded: { type: Boolean, default: !1 }
950
1115
  },
951
1116
  setup(a) {
952
- const i = a, o = H(), t = xe(), r = he(), x = R("webx-auth"), m = F(() => o.state.user), u = F(
953
- () => r.state.panelLocales.length > 1 ? r.state.panelLocales : []
954
- ), p = me(ke, null), L = g(void 0);
955
- Q(
1117
+ const i = a, s = q(), o = me(), u = ke(), k = I("webx-auth"), m = P(() => s.state.user), n = P(
1118
+ () => u.state.panelLocales.length > 1 ? u.state.panelLocales : []
1119
+ ), p = te(Ae, null), C = te(Le, null), V = g(void 0);
1120
+ Z(
956
1121
  () => typeof m.value?.avatar == "string" ? m.value.avatar : null,
957
- async (c) => {
958
- const f = i.resolveAvatar ?? p;
959
- if (c === null || c === "" || f === null) {
960
- L.value = void 0;
1122
+ async (b) => {
1123
+ const _ = i.resolveAvatar ?? p;
1124
+ if (b === null || b === "" || _ === null) {
1125
+ V.value = void 0;
961
1126
  return;
962
1127
  }
963
- const s = await f(c);
964
- m.value?.avatar === c && (L.value = s ?? void 0);
1128
+ const f = await _(b);
1129
+ m.value?.avatar === b && (V.value = f ?? void 0);
965
1130
  },
966
1131
  { immediate: !0 }
967
1132
  );
968
- async function V(c) {
969
- c !== r.state.locale && await t.setLocale(c);
1133
+ const d = ce(ia);
1134
+ function w() {
1135
+ setTimeout(
1136
+ () => {
1137
+ d({ avatarField: i.avatarField ?? C ?? void 0 });
1138
+ },
1139
+ 0
1140
+ );
970
1141
  }
971
- return (c, f) => {
972
- const s = z("wx-avatar"), _ = z("wx-text"), A = z("wx-dropdown-item"), W = z("wx-divider"), T = z("wx-dropdown");
973
- return m.value !== null ? (k(), U(T, { key: 0 }, {
1142
+ async function r(b) {
1143
+ b !== u.state.locale && await o.setLocale(b);
1144
+ }
1145
+ return (b, _) => {
1146
+ const f = B("wx-avatar"), U = B("wx-text"), W = B("wx-dropdown-item"), z = B("wx-divider"), h = B("wx-dropdown");
1147
+ return m.value !== null ? (L(), S(h, { key: 0 }, {
974
1148
  trigger: l(() => [
975
- E("button", {
1149
+ N("button", {
976
1150
  type: "button",
977
- class: "wx-user-menu__trigger",
1151
+ class: Te(["wx-user-menu__trigger", { "wx-user-menu__trigger--named": a.expanded }]),
978
1152
  title: m.value.name
979
1153
  }, [
980
- n(s, {
1154
+ t(f, {
981
1155
  name: m.value.name,
982
- src: L.value,
1156
+ src: V.value,
983
1157
  size: "lg"
984
- }, null, 8, ["name", "src"])
985
- ], 8, aa)
1158
+ }, null, 8, ["name", "src"]),
1159
+ a.expanded ? (L(), O("span", da, $(m.value.name), 1)) : T("", !0)
1160
+ ], 10, ua)
986
1161
  ]),
987
1162
  default: l(() => [
988
- n(A, { disabled: "" }, {
1163
+ t(W, { disabled: "" }, {
989
1164
  default: l(() => [
990
- n(_, { size: "sm" }, {
1165
+ t(U, { size: "sm" }, {
991
1166
  default: l(() => [
992
- S($(m.value.email), 1)
1167
+ F($(m.value.email), 1)
993
1168
  ]),
994
1169
  _: 1
995
1170
  })
996
1171
  ]),
997
1172
  _: 1
998
1173
  }),
999
- u.value.length > 0 ? (k(), j(te, { key: 0 }, [
1000
- n(W, { spacing: "sm" }),
1001
- n(A, { disabled: "" }, {
1174
+ t(z, { spacing: "sm" }),
1175
+ t(W, {
1176
+ icon: "user",
1177
+ onClick: w
1178
+ }, {
1179
+ default: l(() => [
1180
+ F($(e(k)("profile.menu")), 1)
1181
+ ]),
1182
+ _: 1
1183
+ }),
1184
+ n.value.length > 0 ? (L(), O(le, { key: 0 }, [
1185
+ t(z, { spacing: "sm" }),
1186
+ t(W, { disabled: "" }, {
1002
1187
  default: l(() => [
1003
- n(_, {
1188
+ t(U, {
1004
1189
  size: "sm",
1005
1190
  tone: "muted"
1006
1191
  }, {
1007
1192
  default: l(() => [
1008
- S($(e(x)("menu.language")), 1)
1193
+ F($(e(k)("menu.language")), 1)
1009
1194
  ]),
1010
1195
  _: 1
1011
1196
  })
1012
1197
  ]),
1013
1198
  _: 1
1014
1199
  }),
1015
- (k(!0), j(te, null, pe(u.value, (C) => (k(), U(A, {
1016
- key: C.code,
1017
- icon: C.code === e(r).state.locale ? "check" : void 0,
1018
- onClick: (B) => V(C.code)
1200
+ (L(!0), O(le, null, _e(n.value, (c) => (L(), S(W, {
1201
+ key: c.code,
1202
+ icon: c.code === e(u).state.locale ? "check" : void 0,
1203
+ onClick: (x) => r(c.code)
1019
1204
  }, {
1020
1205
  default: l(() => [
1021
- S($(C.nativeName), 1)
1206
+ F($(c.nativeName), 1)
1022
1207
  ]),
1023
1208
  _: 2
1024
1209
  }, 1032, ["icon", "onClick"]))), 128)),
1025
- n(W, { spacing: "sm" })
1026
- ], 64)) : M("", !0),
1027
- n(A, {
1210
+ t(z, { spacing: "sm" })
1211
+ ], 64)) : T("", !0),
1212
+ t(W, {
1028
1213
  icon: "logout",
1029
- onClick: f[0] || (f[0] = (C) => e(t).logout())
1214
+ onClick: _[0] || (_[0] = (c) => e(o).logout())
1030
1215
  }, {
1031
1216
  default: l(() => [
1032
- S($(a.signOutLabel ?? e(x)("menu.sign-out")), 1)
1217
+ F($(a.signOutLabel ?? e(k)("menu.sign-out")), 1)
1033
1218
  ]),
1034
1219
  _: 1
1035
1220
  })
1036
1221
  ]),
1037
1222
  _: 1
1038
- })) : M("", !0);
1223
+ })) : T("", !0);
1039
1224
  };
1040
1225
  }
1041
- }), ua = /* @__PURE__ */ Ve(ta, [["__scopeId", "data-v-d9c92170"]]);
1042
- function da(a = {}) {
1226
+ }), ba = /* @__PURE__ */ ve(ca, [["__scopeId", "data-v-d51d13e4"]]);
1227
+ function ya(a = {}) {
1043
1228
  const i = a.path ?? "/login";
1044
1229
  return {
1045
- install(o) {
1046
- const t = Re(o.context);
1047
- o.i18n.defaults("webx-auth", Ae), Ie(o.app, t, a.resolveAvatar ?? null), o.context.useSessionLoader(() => t.me()), o.router.addRoute({
1230
+ install(s) {
1231
+ const o = Ie(s.context);
1232
+ s.i18n.defaults("webx-auth", $e), Ke(s.app, o, a.resolveAvatar ?? null, a.avatarField ?? null), s.context.useSessionLoader(() => o.me()), s.router.addRoute({
1048
1233
  path: i,
1049
1234
  name: "webx.login",
1050
1235
  meta: { public: !0 },
1051
- component: { render: () => fe(qe, { ...a.card }) }
1052
- }), o.router.beforeEach((r) => r.meta.public === !0 || o.context.state.status !== "unauthenticated" ? !0 : { path: i, query: r.fullPath === "/" ? {} : { next: r.fullPath } }), Q(
1053
- () => o.context.state.status,
1054
- (r) => {
1055
- const x = o.router.currentRoute.value;
1056
- if (r === "unauthenticated" && x.path !== i) {
1057
- o.router.replace({ path: i, query: { next: x.fullPath } });
1236
+ component: { render: () => xe(He, { ...a.card }) }
1237
+ }), s.router.beforeEach((u) => u.meta.public === !0 || s.context.state.status !== "unauthenticated" ? !0 : { path: i, query: u.fullPath === "/" ? {} : { next: u.fullPath } }), Z(
1238
+ () => s.context.state.status,
1239
+ (u) => {
1240
+ const k = s.router.currentRoute.value;
1241
+ if (u === "unauthenticated" && k.path !== i) {
1242
+ s.router.replace({ path: i, query: { next: k.fullPath } });
1058
1243
  return;
1059
1244
  }
1060
- if (r === "ready" && x.path === i) {
1061
- const m = x.query.next;
1062
- o.router.replace(typeof m == "string" ? m : "/");
1245
+ if (u === "ready" && k.path === i) {
1246
+ const m = k.query.next;
1247
+ s.router.replace(typeof m == "string" ? m : "/");
1063
1248
  }
1064
1249
  }
1065
1250
  );
@@ -1067,20 +1252,22 @@ function da(a = {}) {
1067
1252
  };
1068
1253
  }
1069
1254
  export {
1070
- Le as WxAdminList,
1071
- Ze as WxAdminsPage,
1072
- qe as WxLoginCard,
1073
- ua as WxUserMenu,
1074
- sa as admins,
1075
- da as auth,
1076
- _e as authKey,
1077
- Ae as authMessages,
1078
- ke as avatarResolverKey,
1079
- se as createAdminsApi,
1080
- Re as createAuthSession,
1081
- Ie as provideAuth,
1082
- ia as selectAdmin,
1083
- ra as selectAdmins,
1084
- xe as useAuth
1255
+ Ce as WxAdminList,
1256
+ aa as WxAdminsPage,
1257
+ He as WxLoginCard,
1258
+ ia as WxProfileDialog,
1259
+ ba as WxUserMenu,
1260
+ fa as admins,
1261
+ ya as auth,
1262
+ Ve as authKey,
1263
+ $e as authMessages,
1264
+ Le as avatarFieldKey,
1265
+ Ae as avatarResolverKey,
1266
+ pe as createAdminsApi,
1267
+ Ie as createAuthSession,
1268
+ Ke as provideAuth,
1269
+ wa as selectAdmin,
1270
+ ha as selectAdmins,
1271
+ me as useAuth
1085
1272
  };
1086
1273
  //# sourceMappingURL=index.js.map