admin-ui-starter-kit 0.4.4 → 0.4.5

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.
@@ -1,10 +1,10 @@
1
1
  import { useStrings as e } from "../../lib/strings.js";
2
2
  import { n as t, r as n, t as r } from "../../_shared/overlays-CJs_syAu.js";
3
- import { createContext as i, useContext as a, useEffect as o, useRef as s, useSyncExternalStore as c } from "react";
4
- import { jsx as l } from "react/jsx-runtime";
3
+ import { createContext as i, createElement as a, useContext as o, useEffect as s, useId as c, useMemo as l, useRef as u, useSyncExternalStore as d } from "react";
4
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
5
5
  //#region src/services/actions/actions.types.ts
6
- var u = "__global__", d = Object.freeze({}), f = 0;
7
- function p(e, t = {}) {
6
+ var m = "__global__", h = Object.freeze({}), g = 0;
7
+ function _(e, t = {}) {
8
8
  return {
9
9
  ...t,
10
10
  status: e,
@@ -13,16 +13,16 @@ function p(e, t = {}) {
13
13
  isSuccess: e === "succeeded",
14
14
  isError: e === "failed",
15
15
  error: t.error ?? null,
16
- errors: t.errors ?? d
16
+ errors: t.errors ?? h
17
17
  };
18
18
  }
19
- function m(e, t) {
19
+ function v(e, t) {
20
20
  return e ? t ? {
21
21
  ...e,
22
22
  ...t
23
23
  } : e : t;
24
24
  }
25
- function h(e, t, n, r) {
25
+ function y(e, t, n, r) {
26
26
  return Object.freeze({
27
27
  version: e,
28
28
  registrations: Object.freeze([...t]),
@@ -30,25 +30,48 @@ function h(e, t, n, r) {
30
30
  active: r ? Object.freeze({ ...r }) : null
31
31
  });
32
32
  }
33
- function g(e) {
34
- return e?.trim() || u;
33
+ function b(e) {
34
+ return e?.trim() || m;
35
35
  }
36
- function _(e, t) {
36
+ function x(e, t) {
37
37
  return `${e}:${t}`;
38
38
  }
39
- function v(e) {
39
+ function S(e) {
40
40
  return e.surfaces ?? ["page"];
41
41
  }
42
- function y(e, t, n) {
42
+ function C(e, t, n) {
43
43
  return e === void 0 ? n : typeof e == "function" ? e(t) : e;
44
44
  }
45
- function b(e) {
45
+ function w(e) {
46
46
  return e.searchLabel ? e.searchLabel : typeof e.label == "string" ? e.label : e.id;
47
47
  }
48
- function x(e) {
49
- if (!e || typeof e != "object") return d;
48
+ function T(e) {
49
+ return e ? Array.isArray(e) ? e : [e] : [];
50
+ }
51
+ function E(e) {
52
+ return !e || typeof e != "object" || Array.isArray(e) ? !1 : Object.values(e).every((e) => typeof e == "string" || Array.isArray(e) && e.every((e) => typeof e == "string"));
53
+ }
54
+ function D(e, t) {
55
+ if (typeof e == "string") return { message: e };
56
+ if (e && typeof e == "object") {
57
+ if ("fieldErrors" in e || "message" in e) {
58
+ let n = e;
59
+ return {
60
+ fieldErrors: n.fieldErrors ?? k(t),
61
+ message: typeof n.message == "string" ? n.message : void 0
62
+ };
63
+ }
64
+ if (E(e)) return { fieldErrors: e };
65
+ }
66
+ return { fieldErrors: k(t) };
67
+ }
68
+ function O(e, t) {
69
+ return typeof e == "function" ? e(t) : e;
70
+ }
71
+ function k(e) {
72
+ if (!e || typeof e != "object") return h;
50
73
  let t = e.errors;
51
- if (!t || typeof t != "object" || Array.isArray(t)) return d;
74
+ if (!t || typeof t != "object" || Array.isArray(t)) return h;
52
75
  let n = {};
53
76
  for (let [e, r] of Object.entries(t)) {
54
77
  if (typeof r == "string") {
@@ -57,19 +80,37 @@ function x(e) {
57
80
  }
58
81
  Array.isArray(r) && r.every((e) => typeof e == "string") && (n[e] = r);
59
82
  }
60
- return Object.keys(n).length > 0 ? n : d;
83
+ return Object.keys(n).length > 0 ? n : h;
61
84
  }
62
- function S(e, t) {
85
+ function A(e, t) {
63
86
  if (e !== void 0) return typeof e == "function" ? e(t) ?? void 0 : e;
64
87
  }
65
- var C = class {
88
+ function j(e, t) {
89
+ return {
90
+ method: e.method,
91
+ url: O(e.url, t),
92
+ route: O(e.route, t),
93
+ params: O(e.params, t),
94
+ data: O(e.data, t),
95
+ headers: O(e.headers, t),
96
+ options: O(e.options, t)
97
+ };
98
+ }
99
+ function M(e, t, n) {
100
+ let r = n?.(e, t);
101
+ return D(r, e);
102
+ }
103
+ var N = class {
66
104
  registrations = [];
67
105
  runStates = {};
68
106
  active = null;
69
107
  version = 0;
70
- snapshot = h(0, [], {}, null);
108
+ snapshot = y(0, [], {}, null);
71
109
  listeners = /* @__PURE__ */ new Set();
72
110
  feedback;
111
+ guards;
112
+ errorParser;
113
+ requestRunner;
73
114
  abortControllers = /* @__PURE__ */ new Map();
74
115
  runTokens = /* @__PURE__ */ new Map();
75
116
  subscribe = (e) => (this.listeners.add(e), () => this.listeners.delete(e));
@@ -77,17 +118,21 @@ var C = class {
77
118
  setFeedback(e) {
78
119
  this.feedback = e;
79
120
  }
121
+ setOptions(e) {
122
+ let t = this.feedback !== e.feedback || this.guards !== e.guards || this.errorParser !== e.parseErrors || this.requestRunner !== e.requestRunner;
123
+ this.feedback = e.feedback, this.guards = e.guards, this.errorParser = e.parseErrors, this.requestRunner = e.requestRunner, t && this.publish();
124
+ }
80
125
  registerActions(e, t = {}) {
81
126
  if (e.length === 0) return () => void 0;
82
127
  let n = {
83
- id: `registration-${f++}`,
84
- scope: g(t.scope),
128
+ id: `registration-${g++}`,
129
+ scope: b(t.scope),
85
130
  order: this.registrations.length,
86
131
  actions: e
87
132
  };
88
133
  return this.registrations = [...this.registrations, n], this.publish(), () => {
89
134
  this.registrations = this.registrations.filter((e) => e.id !== n.id);
90
- let e = n.actions.map((e) => _(n.id, e.id));
135
+ let e = n.actions.map((e) => x(n.id, e.id));
91
136
  for (let t of e) this.abortAction(t), delete this.runStates[t];
92
137
  this.active && e.includes(this.active.key) && (this.active = null), this.publish();
93
138
  };
@@ -95,7 +140,7 @@ var C = class {
95
140
  selectSurfaceActions(e) {
96
141
  let t = this.getEntriesForScope(e.scope, e.includeGlobal), n = [];
97
142
  for (let r of t) {
98
- if (!v(r.action).includes(e.surface)) continue;
143
+ if (!S(r.action).includes(e.surface)) continue;
99
144
  let t = this.resolveEntry(r, {
100
145
  surface: e.surface,
101
146
  payload: e.payload,
@@ -143,12 +188,13 @@ var C = class {
143
188
  scope: r.registration.scope,
144
189
  payload: t,
145
190
  metadata: n
146
- }, this.setRunState(e, p("idle", {
191
+ }, this.setRunState(e, _("idle", {
147
192
  error: null,
148
- errors: d,
193
+ errors: h,
194
+ message: void 0,
149
195
  payload: t,
150
196
  values: void 0,
151
- metadata: m(r.action.metadata, n)
197
+ metadata: v(r.action.metadata, n)
152
198
  }), !1), this.publish();
153
199
  }
154
200
  }
@@ -179,15 +225,16 @@ var C = class {
179
225
  this.runTokens.set(e, r);
180
226
  let i = new AbortController();
181
227
  this.abortControllers.set(e, i);
182
- let a = m(n.action.metadata, t.metadata), o = Date.now(), s = this.createRunContext(n, {
228
+ let a = v(n.action.metadata, t.metadata), o = Date.now(), s = this.createRunContext(n, {
183
229
  payload: t.payload,
184
230
  values: t.values,
185
231
  metadata: a,
186
232
  signal: i.signal
187
233
  });
188
- this.setRunState(e, p("running", {
234
+ this.setRunState(e, _("running", {
189
235
  error: null,
190
- errors: d,
236
+ errors: h,
237
+ message: void 0,
191
238
  payload: t.payload,
192
239
  values: t.values,
193
240
  metadata: a,
@@ -195,9 +242,16 @@ var C = class {
195
242
  })), this.emitLifecycle("started", n, s, e);
196
243
  let c, l, u = n.action;
197
244
  try {
198
- return u.run && (c = await u.run(s)), this.isCurrentRun(e, r) ? (this.setRunState(e, p("succeeded", {
245
+ if (u.run) c = await u.run(s);
246
+ else if (u.request) {
247
+ let e = u.requestRunner ?? this.requestRunner;
248
+ if (!e) throw Error(`Action request runner is not configured: ${u.id}`);
249
+ c = await e(j(u.request, s), s);
250
+ }
251
+ return this.isCurrentRun(e, r) ? (this.setRunState(e, _("succeeded", {
199
252
  error: null,
200
- errors: d,
253
+ errors: h,
254
+ message: void 0,
201
255
  result: c,
202
256
  payload: t.payload,
203
257
  values: t.values,
@@ -208,16 +262,23 @@ var C = class {
208
262
  } catch (i) {
209
263
  if (!this.isCurrentRun(e, r)) return;
210
264
  l = i;
211
- let c = x(i);
212
- throw this.setRunState(e, p("failed", {
265
+ let c = M(i, {
266
+ ...s,
267
+ error: i
268
+ }, u.parseErrors ?? this.errorParser), d = c.fieldErrors ?? h;
269
+ throw this.setRunState(e, _("failed", {
213
270
  error: i,
214
- errors: c,
271
+ errors: d,
272
+ message: c.message,
215
273
  payload: t.payload,
216
274
  values: t.values,
217
275
  metadata: a,
218
276
  startedAt: o,
219
277
  completedAt: Date.now()
220
- })), this.emitLifecycle("failed", n, s, e, { error: i }), i;
278
+ })), this.emitLifecycle("failed", n, s, e, {
279
+ error: i,
280
+ message: c.message
281
+ }), i;
221
282
  } finally {
222
283
  this.isCurrentRun(e, r) && (this.abortControllers.delete(e), this.emitLifecycle("settled", n, s, e, {
223
284
  result: c,
@@ -226,11 +287,11 @@ var C = class {
226
287
  }
227
288
  }
228
289
  getEntriesForScope(e, t = !0) {
229
- let n = e ? g(e) : u, r = [];
290
+ let n = e ? b(e) : m, r = [];
230
291
  for (let e of this.snapshot.registrations) {
231
- let i = e.scope === u;
292
+ let i = e.scope === m;
232
293
  if (!(i && !t) && !(!i && e.scope !== n)) for (let t of e.actions) r.push({
233
- key: _(e.id, t.id),
294
+ key: x(e.id, t.id),
234
295
  registration: e,
235
296
  action: t
236
297
  });
@@ -238,19 +299,19 @@ var C = class {
238
299
  return r;
239
300
  }
240
301
  resolveEntry(e, t) {
241
- let n = m(e.action.metadata, t.metadata), r = {
302
+ let n = v(e.action.metadata, t.metadata), r = {
242
303
  actionId: e.action.id,
243
304
  scope: e.registration.scope,
244
305
  surface: t.surface,
245
306
  payload: t.payload,
246
307
  metadata: n
247
- }, i = this.getRunState(e.key), a = y(e.action.visible, r, !0), o = y(e.action.disabled, r, !1), s = e.action;
308
+ }, i = this.getRunState(e.key), a = this.isEntryVisible(e, r), o = C(e.action.disabled, r, !1), s = e.action;
248
309
  return {
249
310
  key: e.key,
250
311
  id: e.action.id,
251
312
  scope: e.registration.scope,
252
313
  label: e.action.label,
253
- searchLabel: b(e.action),
314
+ searchLabel: w(e.action),
254
315
  icon: e.action.icon,
255
316
  group: e.action.group,
256
317
  placement: e.action.placement ?? "auto",
@@ -265,6 +326,7 @@ var C = class {
265
326
  isError: i.isError,
266
327
  error: i.error,
267
328
  errors: i.errors,
329
+ message: i.message,
268
330
  result: i.result,
269
331
  runState: i,
270
332
  payload: t.payload,
@@ -273,11 +335,11 @@ var C = class {
273
335
  startedAt: i.startedAt,
274
336
  completedAt: i.completedAt,
275
337
  definition: s,
276
- open: (n, r) => this.openAction(e.key, n ?? t.payload, m(t.metadata, r)),
338
+ open: (n, r) => this.openAction(e.key, n ?? t.payload, v(t.metadata, r)),
277
339
  execute: (n, r, i) => this.executeAction(e.key, {
278
340
  payload: r ?? t.payload,
279
341
  values: n,
280
- metadata: m(t.metadata, i)
342
+ metadata: v(t.metadata, i)
281
343
  }),
282
344
  close: () => this.closeActive(),
283
345
  submit: (e) => this.submitActive(e)
@@ -299,9 +361,19 @@ var C = class {
299
361
  actionId: e.action.id,
300
362
  scope: e.registration.scope,
301
363
  payload: t,
302
- metadata: m(e.action.metadata, n)
364
+ metadata: v(e.action.metadata, n)
303
365
  };
304
- return y(e.action.disabled, r, !1);
366
+ return this.isEntryVisible(e, r) ? C(e.action.disabled, r, !1) : !0;
367
+ }
368
+ isEntryVisible(e, t) {
369
+ if (!C(e.action.visible, t, !0)) return !1;
370
+ let n = {
371
+ ...t,
372
+ action: e.action
373
+ }, r = T(e.action.permission);
374
+ if (r.length > 0 && (!this.guards?.can || !r.every((e) => this.guards?.can?.(e, n)))) return !1;
375
+ let i = T(e.action.roles);
376
+ return !(i.length > 0 && (!this.guards?.hasAnyRole || !this.guards.hasAnyRole(i, n)));
305
377
  }
306
378
  emitLifecycle(e, t, n, r, i = {}) {
307
379
  let a = t.action, o = this.getRunState(r), s = {
@@ -311,7 +383,7 @@ var C = class {
311
383
  errors: o.errors,
312
384
  result: i.result,
313
385
  error: i.error
314
- }, c = e === "succeeded" ? S(a.successMessage, s) : e === "failed" ? S(a.errorMessage, s) : void 0, l = {
386
+ }, c = e === "succeeded" ? A(a.successMessage, s) : e === "failed" ? A(a.errorMessage, s) ?? i.message : void 0, l = {
315
387
  ...s,
316
388
  type: e,
317
389
  key: r,
@@ -322,7 +394,7 @@ var C = class {
322
394
  e === "started" && a.onStart?.(l), e === "succeeded" && a.onAfterMutate?.(l), e === "failed" && a.onError?.(l), e === "settled" && a.onSettled?.(l), e === "started" && this.feedback?.onStart?.(l), e === "succeeded" && this.feedback?.onSuccess?.(l), e === "failed" && this.feedback?.onError?.(l), e === "settled" && this.feedback?.onSettled?.(l);
323
395
  }
324
396
  findEntry(e) {
325
- for (let t of this.snapshot.registrations) for (let n of t.actions) if (_(t.id, n.id) === e) return {
397
+ for (let t of this.snapshot.registrations) for (let n of t.actions) if (x(t.id, n.id) === e) return {
326
398
  key: e,
327
399
  registration: t,
328
400
  action: n
@@ -330,14 +402,14 @@ var C = class {
330
402
  return null;
331
403
  }
332
404
  getRunState(e) {
333
- return this.snapshot.runStates[e] ?? p("idle");
405
+ return this.snapshot.runStates[e] ?? _("idle");
334
406
  }
335
407
  setRunState(e, t, n = !0) {
336
408
  this.runStates = {
337
409
  ...this.runStates,
338
410
  [e]: {
339
411
  ...t,
340
- errors: t.errors ?? d
412
+ errors: t.errors ?? h
341
413
  }
342
414
  }, n && this.publish();
343
415
  }
@@ -345,10 +417,10 @@ var C = class {
345
417
  let t = this.abortControllers.get(e);
346
418
  if (!t) return;
347
419
  let n = this.getRunState(e);
348
- this.runTokens.set(e, (this.runTokens.get(e) ?? 0) + 1), t.abort(), this.abortControllers.delete(e), this.setRunState(e, p("idle", {
420
+ this.runTokens.set(e, (this.runTokens.get(e) ?? 0) + 1), t.abort(), this.abortControllers.delete(e), this.setRunState(e, _("idle", {
349
421
  ...n,
350
422
  error: null,
351
- errors: d,
423
+ errors: h,
352
424
  completedAt: Date.now()
353
425
  }), !1);
354
426
  }
@@ -356,49 +428,76 @@ var C = class {
356
428
  return this.runTokens.get(e) === t;
357
429
  }
358
430
  publish() {
359
- this.version += 1, this.snapshot = h(this.version, this.registrations, this.runStates, this.active);
431
+ this.version += 1, this.snapshot = y(this.version, this.registrations, this.runStates, this.active);
360
432
  for (let e of this.listeners) e();
361
433
  }
362
434
  };
363
- function w() {
364
- return new C();
435
+ function P() {
436
+ return new N();
365
437
  }
366
438
  //#endregion
367
439
  //#region src/services/actions/action-provider.tsx
368
- var T = i(null), E = i(null);
369
- function D({ actions: e, feedback: t, children: n }) {
370
- let r = s(null);
371
- r.current ||= w();
372
- let i = r.current;
373
- return o(() => {
374
- i.setFeedback(t);
375
- }, [t, i]), o(() => {
376
- if (!(!e || e.length === 0)) return i.registerActions(e, { scope: u });
377
- }, [e, i]), /* @__PURE__ */ l(T.Provider, {
378
- value: i,
379
- children: /* @__PURE__ */ l(E.Provider, {
380
- value: u,
381
- children: n
440
+ var F = i(null), I = i(null);
441
+ function ee({ actions: e, feedback: t, guards: n, parseErrors: r, requestRunner: i, onOverlayOpenChange: a, onRunningChange: o, children: c }) {
442
+ let l = u(null);
443
+ l.current ||= P();
444
+ let d = l.current;
445
+ return s(() => {
446
+ d.setOptions({
447
+ feedback: t,
448
+ guards: n,
449
+ parseErrors: r,
450
+ requestRunner: i
451
+ });
452
+ }, [
453
+ t,
454
+ n,
455
+ r,
456
+ i,
457
+ d
458
+ ]), s(() => {
459
+ if (!(!e || e.length === 0)) return d.registerActions(e, { scope: m });
460
+ }, [e, d]), /* @__PURE__ */ f(F.Provider, {
461
+ value: d,
462
+ children: /* @__PURE__ */ p(I.Provider, {
463
+ value: m,
464
+ children: [/* @__PURE__ */ f(te, {
465
+ store: d,
466
+ onOverlayOpenChange: a,
467
+ onRunningChange: o
468
+ }), c]
382
469
  })
383
470
  });
384
471
  }
385
- function O() {
386
- let e = a(T);
472
+ function te({ store: e, onOverlayOpenChange: t, onRunningChange: n }) {
473
+ let r = d(e.subscribe, e.getSnapshot, e.getSnapshot), i = r.active !== null, a = Object.values(r.runStates).some((e) => e.isRunning), o = u(i), c = u(a), l = u(t), f = u(n);
474
+ return s(() => {
475
+ l.current = t;
476
+ }, [t]), s(() => {
477
+ f.current = n;
478
+ }, [n]), s(() => {
479
+ o.current !== i && (o.current = i, l.current?.(i, r));
480
+ }, [i, r]), s(() => {
481
+ c.current !== a && (c.current = a, f.current?.(a, r));
482
+ }, [a, r]), null;
483
+ }
484
+ function L() {
485
+ let e = o(F);
387
486
  if (!e) throw Error("Action hooks must be used inside <ActionProvider>.");
388
487
  return e;
389
488
  }
390
489
  //#endregion
391
490
  //#region src/services/actions/hooks.ts
392
- function k() {
393
- return a(E) ?? "__global__";
491
+ function R() {
492
+ return o(I) ?? "__global__";
394
493
  }
395
- function A() {
396
- let e = O();
397
- return c(e.subscribe, e.getSnapshot, e.getSnapshot);
494
+ function z() {
495
+ let e = L();
496
+ return d(e.subscribe, e.getSnapshot, e.getSnapshot);
398
497
  }
399
- function j(e, t = {}) {
400
- let n = O(), r = k(), i = t.scope ?? r;
401
- o(() => {
498
+ function B(e, t = {}) {
499
+ let n = L(), r = R(), i = t.scope ?? r;
500
+ s(() => {
402
501
  if (e.length !== 0) return n.registerActions(e, { scope: i });
403
502
  }, [
404
503
  e,
@@ -406,9 +505,9 @@ function j(e, t = {}) {
406
505
  n
407
506
  ]);
408
507
  }
409
- function M(e) {
410
- let t = O(), n = k(), r = e.scope ?? n, { surface: i, payload: a, metadata: o, includeGlobal: s } = e;
411
- return A(), t.selectSurfaceActions({
508
+ function ne(e) {
509
+ let t = L(), n = R(), r = e.scope ?? n, { surface: i, payload: a, metadata: o, includeGlobal: s } = e;
510
+ return z(), t.selectSurfaceActions({
412
511
  surface: i,
413
512
  payload: a,
414
513
  metadata: o,
@@ -416,49 +515,57 @@ function M(e) {
416
515
  scope: r
417
516
  });
418
517
  }
419
- function N(e, t = {}) {
420
- let n = O(), r = k(), i = t.scope ?? r, { payload: a, metadata: o, includeGlobal: s } = t;
421
- return A(), n.selectAction(e, {
518
+ function V(e, t = {}) {
519
+ let n = L(), r = R(), i = t.scope ?? r, { payload: a, metadata: o, includeGlobal: s } = t;
520
+ return z(), n.selectAction(e, {
422
521
  payload: a,
423
522
  metadata: o,
424
523
  includeGlobal: s,
425
524
  scope: i
426
525
  });
427
526
  }
428
- function P() {
429
- let e = O();
430
- return A(), e.getActiveAction();
527
+ function H(e, t = {}) {
528
+ let n = R(), r = c(), i = t.scope ?? `${n}:local:${r}`;
529
+ return B(l(() => [e], [e]), { scope: i }), V(e.id, {
530
+ ...t,
531
+ scope: i,
532
+ includeGlobal: !1
533
+ });
534
+ }
535
+ function U() {
536
+ let e = L();
537
+ return z(), e.getActiveAction();
431
538
  }
432
539
  //#endregion
433
540
  //#region src/services/actions/action-scope.tsx
434
- function F({ scope: e = u, actions: t, children: n }) {
435
- return j(t, { scope: e }), /* @__PURE__ */ l(E.Provider, {
541
+ function W({ scope: e = m, actions: t, children: n }) {
542
+ return B(t, { scope: e }), /* @__PURE__ */ f(I.Provider, {
436
543
  value: e,
437
544
  children: n
438
545
  });
439
546
  }
440
547
  //#endregion
441
548
  //#region src/services/actions/actions.strings.ts
442
- var I = {
549
+ var G = {
443
550
  confirm: "Confirm",
444
551
  cancel: "Cancel"
445
552
  };
446
553
  //#endregion
447
554
  //#region src/services/actions/action-overlay-outlet.tsx
448
- function L(e) {
555
+ function K(e) {
449
556
  return e === "destructive" ? "error" : e ?? "default";
450
557
  }
451
- function R(e) {
558
+ function q(e) {
452
559
  return e === "destructive" || e === "error" ? "error" : e === "warning" ? "warning" : e === "success" ? "success" : "primary";
453
560
  }
454
- function z(e) {
561
+ function J(e) {
455
562
  return e ?? "lg";
456
563
  }
457
- function B(e) {
564
+ function Y(e) {
458
565
  return e ?? "right";
459
566
  }
460
- function V({ strings: i }) {
461
- let a = P(), o = e(I, i);
567
+ function X({ strings: i }) {
568
+ let a = U(), o = e(G, i);
462
569
  if (!a) return null;
463
570
  let s = a.definition.modality;
464
571
  if (!s || s === "none") return null;
@@ -473,7 +580,7 @@ function V({ strings: i }) {
473
580
  errors: a.errors,
474
581
  result: a.result,
475
582
  error: a.error
476
- }, u = S(s.title, c), d = S(s.description, c), f = S(s.confirmLabel, c) ?? o.confirm, p = S(s.cancelLabel, c) ?? o.cancel, m = S(s.alertMessage, c), h = L(s.tone), g = R(s.tone), _ = h !== "default", v = s.emphasis ?? _, y = s.showIcon ?? _, b = s.closeOnBackdropClick ?? s.type !== "alert", x = s.render?.({
583
+ }, l = A(s.title, c), u = A(s.description, c), d = A(s.confirmLabel, c) ?? o.confirm, p = A(s.cancelLabel, c) ?? o.cancel, m = A(s.alertMessage, c), h = K(s.tone), g = q(s.tone), _ = h !== "default", v = s.emphasis ?? _, y = s.showIcon ?? _, b = s.closeOnBackdropClick ?? s.type !== "alert", x = s.render?.({
477
584
  action: a.definition,
478
585
  actionId: a.id,
479
586
  scope: a.scope,
@@ -499,13 +606,13 @@ function V({ strings: i }) {
499
606
  await a.submit(n);
500
607
  }
501
608
  })
502
- }), C = {
609
+ }), S = {
503
610
  open: !0,
504
611
  onOpenChange: (e) => {
505
612
  e || a.close();
506
613
  },
507
- title: u,
508
- description: d,
614
+ title: l,
615
+ description: u,
509
616
  visuallyHideHeader: s.visuallyHideHeader,
510
617
  className: s.className,
511
618
  contentClassName: s.contentClassName,
@@ -525,38 +632,213 @@ function V({ strings: i }) {
525
632
  confirmStyle: s.confirmStyle,
526
633
  closeOnBackdropClick: b,
527
634
  strings: {
528
- confirm: f,
635
+ confirm: d,
529
636
  cancel: p
530
637
  }
531
638
  };
532
- return s.type === "alert" ? /* @__PURE__ */ l(r, {
533
- ...C,
639
+ return s.type === "alert" ? /* @__PURE__ */ f(r, {
640
+ ...S,
534
641
  tone: h,
535
642
  showIcon: y,
536
643
  alertMessage: m,
537
644
  destructive: h === "error",
538
645
  children: x
539
- }) : s.type === "drawer" ? /* @__PURE__ */ l(t, {
540
- ...C,
646
+ }) : s.type === "drawer" ? /* @__PURE__ */ f(t, {
647
+ ...S,
541
648
  tone: h,
542
649
  emphasis: v,
543
650
  showIcon: y,
544
651
  alertMessage: m,
545
- width: z(s.size),
546
- direction: B(s.drawerDirection),
652
+ width: J(s.size),
653
+ direction: Y(s.drawerDirection),
547
654
  showFooter: s.showFooter ?? !0,
548
655
  children: x
549
- }) : /* @__PURE__ */ l(n, {
550
- ...C,
656
+ }) : /* @__PURE__ */ f(n, {
657
+ ...S,
551
658
  tone: h,
552
659
  emphasis: v,
553
660
  showIcon: y,
554
661
  alertMessage: m,
555
- size: z(s.size),
662
+ size: J(s.size),
556
663
  children: x
557
664
  });
558
665
  }
559
666
  //#endregion
560
- export { u as ACTION_GLOBAL_SCOPE, V as ActionOverlayOutlet, D as ActionProvider, F as ActionScope, w as createActionStore, I as defaultActionOverlayStrings, x as extractActionFieldErrors, S as resolveActionMessage, N as useAction, k as useActionScope, A as useActionSnapshot, O as useActionStore, M as useActionSurface, P as useActiveAction, j as useRegisterActions };
667
+ //#region src/services/actions/action-adapters.ts
668
+ var Z = class extends Error {
669
+ status;
670
+ statusText;
671
+ body;
672
+ response;
673
+ errors;
674
+ constructor({ status: e, statusText: t, body: n, response: r }) {
675
+ super(t || `Request failed with status ${e}`), this.name = "ActionHttpError", this.status = e, this.statusText = t, this.body = n, this.response = r, this.errors = n && typeof n == "object" && "errors" in n ? n.errors : void 0;
676
+ }
677
+ };
678
+ async function re(e) {
679
+ if (e.status !== 204) return (e.headers.get("content-type") ?? "").includes("application/json") ? e.json() : e.text();
680
+ }
681
+ function ie(e, t) {
682
+ if (!t) throw Error("Action request requires a url.");
683
+ return e ? new URL(t, e).toString() : t;
684
+ }
685
+ function ae(e) {
686
+ if (e != null) return typeof FormData < "u" && e instanceof FormData || typeof URLSearchParams < "u" && e instanceof URLSearchParams || typeof Blob < "u" && e instanceof Blob || typeof e == "string" ? e : JSON.stringify(e);
687
+ }
688
+ function oe({ baseUrl: e, fetcher: t = fetch, parseResponse: n = re } = {}) {
689
+ return async (r, i) => {
690
+ let a = r.method.toUpperCase(), o = a === "GET" ? void 0 : ae(r.data), s = typeof FormData < "u" && o instanceof FormData, c = {
691
+ ...o && !s ? { "Content-Type": "application/json" } : {},
692
+ ...r.headers
693
+ }, l = await t(ie(e, r.url), {
694
+ ...r.options,
695
+ method: a,
696
+ headers: c,
697
+ body: o,
698
+ signal: i.signal
699
+ }), u = await n(l);
700
+ if (!l.ok) throw new Z({
701
+ status: l.status,
702
+ statusText: l.statusText,
703
+ body: u,
704
+ response: l
705
+ });
706
+ return u;
707
+ };
708
+ }
709
+ function se(e, t) {
710
+ if (e.url) return e.url;
711
+ if (e.route && t) return t(e.route, e.params);
712
+ throw Error("Inertia action request requires a url or route resolver.");
713
+ }
714
+ function ce({ router: e, route: t, defaults: n }) {
715
+ return (r) => new Promise((i, a) => {
716
+ let o = !1, s = {
717
+ ...n,
718
+ ...r.options
719
+ }, c = s.onSuccess, l = s.onError, u = s.onCancel, d = s.onFinish, f = (e) => {
720
+ o || (o = !0, e());
721
+ }, p = e.visit(se(r, t), {
722
+ ...s,
723
+ method: r.method,
724
+ data: r.data,
725
+ headers: r.headers,
726
+ onSuccess: (e) => {
727
+ c?.(e), f(() => i(e));
728
+ },
729
+ onError: (e) => {
730
+ l?.(e);
731
+ let t = Object.assign(/* @__PURE__ */ Error("Action request failed."), { errors: e });
732
+ f(() => a(t));
733
+ },
734
+ onCancel: () => {
735
+ u?.(), f(() => a(/* @__PURE__ */ Error("Action request was cancelled.")));
736
+ },
737
+ onFinish: (e) => {
738
+ d?.(e);
739
+ }
740
+ });
741
+ p && typeof p.then == "function" && p.then((e) => f(() => i(e)), (e) => f(() => a(e)));
742
+ });
743
+ }
744
+ function le(e) {
745
+ return e === void 0 ? [] : Array.isArray(e) ? e : [e];
746
+ }
747
+ function ue({ queryClient: e, invalidate: t, feedback: n }) {
748
+ return {
749
+ onStart: n?.onStart,
750
+ onError: n?.onError,
751
+ onSettled: n?.onSettled,
752
+ onSuccess: (r) => {
753
+ n?.onSuccess?.(r);
754
+ let i = typeof t == "function" ? t(r) : t;
755
+ for (let t of le(i)) e.invalidateQueries?.(t);
756
+ }
757
+ };
758
+ }
759
+ function de(e) {
760
+ return e;
761
+ }
762
+ function fe(e) {
763
+ return {
764
+ ...e,
765
+ modality: {
766
+ type: "alert",
767
+ tone: "destructive",
768
+ ...e.modality
769
+ }
770
+ };
771
+ }
772
+ function pe(e) {
773
+ return {
774
+ ...e,
775
+ modality: {
776
+ type: "dialog",
777
+ ...e.modality
778
+ }
779
+ };
780
+ }
781
+ function me(e) {
782
+ return {
783
+ ...e,
784
+ modality: "none"
785
+ };
786
+ }
787
+ function Q(e) {
788
+ let t = e.definition.modality && e.definition.modality !== "none" ? e.definition.modality.tone : void 0;
789
+ if (t === "destructive" || t === "error") return "destructive";
790
+ if (t === "warning") return "warning";
791
+ if (t === "success") return "success";
792
+ }
793
+ function $(e) {
794
+ return e.searchLabel || e.id;
795
+ }
796
+ function he(e) {
797
+ return {
798
+ id: e.id,
799
+ label: e.label,
800
+ onClick: () => e.open(),
801
+ disabled: e.disabled,
802
+ loading: e.isRunning,
803
+ icon: e.icon,
804
+ variant: Q(e),
805
+ visible: e.visible,
806
+ group: e.group,
807
+ placement: e.placement
808
+ };
809
+ }
810
+ function ge(e) {
811
+ return {
812
+ label: $(e),
813
+ onClick: () => e.open(),
814
+ disabled: e.disabled || e.isRunning,
815
+ icon: e.icon,
816
+ variant: Q(e) === "destructive" ? "error" : "secondary"
817
+ };
818
+ }
819
+ function _e(e) {
820
+ return {
821
+ id: e.id,
822
+ label: $(e),
823
+ onClick: (t) => e.open(t),
824
+ disabled: e.disabled,
825
+ isDisabled: () => e.disabled || e.isRunning,
826
+ isVisible: () => e.visible,
827
+ icon: e.icon ? a(e.icon, { className: "size-4" }) : void 0,
828
+ variant: Q(e) === "destructive" ? "destructive" : "secondary"
829
+ };
830
+ }
831
+ function ve(e, t) {
832
+ return {
833
+ id: e.id,
834
+ label: $(e),
835
+ group: e.group,
836
+ disabled: e.disabled || e.isRunning,
837
+ icon: e.icon,
838
+ onSelect: () => e.open(void 0, t)
839
+ };
840
+ }
841
+ //#endregion
842
+ export { m as ACTION_GLOBAL_SCOPE, Z as ActionHttpError, X as ActionOverlayOutlet, ee as ActionProvider, W as ActionScope, P as createActionStore, oe as createHttpActionRunner, ce as createInertiaActionRunner, ue as createReactQueryActionFeedback, G as defaultActionOverlayStrings, de as defineAction, fe as defineDeleteAction, pe as defineFormAction, me as defineSilentAction, k as extractActionFieldErrors, M as parseActionError, A as resolveActionMessage, j as resolveActionRequest, ve as toCommandAction, ge as toMenuAction, he as toPageAction, _e as toTableAction, V as useAction, R as useActionScope, z as useActionSnapshot, L as useActionStore, ne as useActionSurface, U as useActiveAction, H as useLocalAction, B as useRegisterActions };
561
843
 
562
844
  //# sourceMappingURL=index.js.map