@alfadocs/ui-kit 1.43.0 → 1.45.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.
Files changed (113) hide show
  1. package/dist/_chunks/ai-sparkle-DXeP_6a0.js +52 -0
  2. package/dist/_chunks/{calendar-ChJQzRw-.js → calendar-U6N0F99w.js} +383 -359
  3. package/dist/_chunks/calendar-workspace-B7KvZ1_D.js +12161 -0
  4. package/dist/_chunks/{face-scheme-Dg6ZyLKb.js → face-scheme-Bm6pe7R8.js} +265 -275
  5. package/dist/_chunks/help-me-write-templates-GUeEn3Ff.js +741 -0
  6. package/dist/_chunks/{notes-panel-CRAovkjx.js → notes-panel-Dkk9QPPX.js} +159 -152
  7. package/dist/_chunks/{panel-subview-PMBRPFOa.js → panel-subview-CYnuX-KR.js} +61 -40
  8. package/dist/_chunks/rich-text-editor-BrAvNajV.js +3779 -0
  9. package/dist/_chunks/undo-2-CYNAzclj.js +26 -0
  10. package/dist/_chunks/use-ai-sparkle-CyQSRTCe.js +103 -0
  11. package/dist/_chunks/variables-menu-vXUaSBj4.js +401 -0
  12. package/dist/agent-catalog.json +84 -3
  13. package/dist/agent-i18n/en.json +14 -3
  14. package/dist/components/ai-sparkle/ai-sparkle.d.ts +24 -0
  15. package/dist/components/ai-sparkle/index.d.ts +3 -0
  16. package/dist/components/ai-sparkle/index.js +5 -0
  17. package/dist/components/calendar/calendar.d.ts +6 -0
  18. package/dist/components/calendar/index.js +1 -1
  19. package/dist/components/face-scheme/index.js +1 -1
  20. package/dist/components/index.d.ts +4 -2
  21. package/dist/components/notes-panel/index.js +1 -1
  22. package/dist/components/notes-panel/notes-panel.d.ts +4 -0
  23. package/dist/components/panel-subview/index.js +1 -1
  24. package/dist/components/panel-subview/panel-subview.d.ts +6 -0
  25. package/dist/components/rich-text-editor/editor-toolbar.d.ts +35 -3
  26. package/dist/components/rich-text-editor/index.d.ts +1 -1
  27. package/dist/components/rich-text-editor/index.js +1 -1
  28. package/dist/components/rich-text-editor/rich-text-editor.d.ts +98 -15
  29. package/dist/components/variables-menu/index.d.ts +4 -0
  30. package/dist/components/variables-menu/index.js +6 -0
  31. package/dist/components/variables-menu/variables-menu.agent.d.ts +10 -0
  32. package/dist/components/variables-menu/variables-menu.d.ts +53 -0
  33. package/dist/hooks/index.d.ts +1 -0
  34. package/dist/hooks/index.js +64 -56
  35. package/dist/hooks/use-ai-sparkle.d.ts +109 -0
  36. package/dist/host-compat.css +5 -5
  37. package/dist/i18n/locales/ar.d.ts +77 -6
  38. package/dist/i18n/locales/ar.js +78 -7
  39. package/dist/i18n/locales/de.d.ts +77 -6
  40. package/dist/i18n/locales/de.js +78 -7
  41. package/dist/i18n/locales/el.d.ts +77 -6
  42. package/dist/i18n/locales/el.js +78 -7
  43. package/dist/i18n/locales/en.d.ts +77 -6
  44. package/dist/i18n/locales/en.js +85 -7
  45. package/dist/i18n/locales/es.d.ts +77 -6
  46. package/dist/i18n/locales/es.js +78 -7
  47. package/dist/i18n/locales/fr.d.ts +77 -6
  48. package/dist/i18n/locales/fr.js +78 -7
  49. package/dist/i18n/locales/hi.d.ts +77 -6
  50. package/dist/i18n/locales/hi.js +78 -7
  51. package/dist/i18n/locales/it.d.ts +77 -6
  52. package/dist/i18n/locales/it.js +78 -7
  53. package/dist/i18n/locales/ja.d.ts +77 -6
  54. package/dist/i18n/locales/ja.js +78 -7
  55. package/dist/i18n/locales/nl.d.ts +77 -6
  56. package/dist/i18n/locales/nl.js +78 -7
  57. package/dist/i18n/locales/pl.d.ts +77 -6
  58. package/dist/i18n/locales/pl.js +78 -7
  59. package/dist/i18n/locales/pt.d.ts +77 -6
  60. package/dist/i18n/locales/pt.js +78 -7
  61. package/dist/i18n/locales/ro.d.ts +77 -6
  62. package/dist/i18n/locales/ro.js +78 -7
  63. package/dist/i18n/locales/ru.d.ts +77 -6
  64. package/dist/i18n/locales/ru.js +78 -7
  65. package/dist/i18n/locales/sq.d.ts +77 -6
  66. package/dist/i18n/locales/sq.js +78 -7
  67. package/dist/i18n/locales/sv.d.ts +77 -6
  68. package/dist/i18n/locales/sv.js +78 -7
  69. package/dist/i18n/locales/tr.d.ts +77 -6
  70. package/dist/i18n/locales/tr.js +78 -7
  71. package/dist/i18n/locales/zh.d.ts +77 -6
  72. package/dist/i18n/locales/zh.js +78 -7
  73. package/dist/index.js +1106 -1099
  74. package/dist/locales/ar.json +78 -7
  75. package/dist/locales/de.json +78 -7
  76. package/dist/locales/el.json +78 -7
  77. package/dist/locales/en.json +78 -7
  78. package/dist/locales/es.json +78 -7
  79. package/dist/locales/fr.json +78 -7
  80. package/dist/locales/hi.json +78 -7
  81. package/dist/locales/it.json +78 -7
  82. package/dist/locales/ja.json +78 -7
  83. package/dist/locales/nl.json +78 -7
  84. package/dist/locales/pl.json +78 -7
  85. package/dist/locales/pt.json +78 -7
  86. package/dist/locales/ro.json +78 -7
  87. package/dist/locales/ru.json +78 -7
  88. package/dist/locales/sq.json +78 -7
  89. package/dist/locales/sv.json +78 -7
  90. package/dist/locales/tr.json +78 -7
  91. package/dist/locales/zh.json +78 -7
  92. package/dist/patterns/calendar/calendar-bookings-panel.d.ts +8 -3
  93. package/dist/patterns/calendar/calendar-care-rules.d.ts +49 -0
  94. package/dist/patterns/calendar/calendar-task-editor.d.ts +31 -0
  95. package/dist/patterns/calendar/calendar-workspace.d.ts +8 -1
  96. package/dist/patterns/calendar/calendar-workspace.model.d.ts +39 -12
  97. package/dist/patterns/calendar/calendar.data.d.ts +9 -0
  98. package/dist/patterns/calendar/calendar.journey.d.ts +35 -3
  99. package/dist/patterns/calendar/calendar.model.d.ts +23 -1
  100. package/dist/patterns/calendar/calendar.sheets.d.ts +21 -3
  101. package/dist/patterns/calendar/calendar.surface.d.ts +6 -1
  102. package/dist/patterns/calendar/calendar.types.d.ts +32 -1
  103. package/dist/patterns/calendar/index.js +1 -1
  104. package/dist/patterns/help-me-write-templates/help-me-write-templates.d.ts +58 -26
  105. package/dist/patterns/help-me-write-templates/index.d.ts +1 -1
  106. package/dist/patterns/help-me-write-templates/index.js +1 -1
  107. package/dist/tokens.css +6 -6
  108. package/package.json +5 -1
  109. package/dist/_chunks/calendar-workspace-DhXqqu-D.js +0 -11392
  110. package/dist/_chunks/help-me-write-templates-B-m7zgJa.js +0 -775
  111. package/dist/_chunks/highlighter-DSkckT2Q.js +0 -15
  112. package/dist/_chunks/rich-text-editor-DUMeifwc.js +0 -3176
  113. package/dist/_chunks/wand-sparkles-DAjKyhz7.js +0 -27
@@ -0,0 +1,741 @@
1
+ import { jsxs as m, jsx as r, Fragment as _ } from "react/jsx-runtime";
2
+ import { useState as b, useEffect as U, useId as ee, useRef as V, useCallback as S, useMemo as Y } from "react";
3
+ import { useTranslation as $ } from "react-i18next";
4
+ import { c as ce } from "./index-D2ZczOXr.js";
5
+ import { A as P } from "./alert-CiQ5Pa3Q.js";
6
+ import { B as D } from "./button-CaUe1uyd.js";
7
+ import { I as F } from "./icon-button-CehAeZoP.js";
8
+ import { D as y } from "./dialog-BJiLqhx6.js";
9
+ import { E as de } from "./editor-overlay-DwNKaI22.js";
10
+ import { E as me } from "./empty-state-BUN_UAWf.js";
11
+ import { F as Z } from "./form-field-CahJzTxp.js";
12
+ import { P as pe } from "./progress-CK8otcQ-.js";
13
+ import { S as ue } from "./spinner-hbwuKwMf.js";
14
+ import { T as se } from "./text-area-Bt3p7Pt0.js";
15
+ import { T as re } from "./text-input-CUvCb6ST.js";
16
+ import { SafeHtml as he } from "../safe-html/index.js";
17
+ import { T as ge } from "./trending-up-C_luYBzS.js";
18
+ import { A as fe } from "./astroid-BN4f5VXU.js";
19
+ import { A as ve } from "./arrow-left-BfaGqVam.js";
20
+ import { P as be } from "./pencil-B1sKKyuT.js";
21
+ import { T as Te } from "./trash-2-uumy3fy1.js";
22
+ import { P as Me } from "./plus-DzMQ_c6b.js";
23
+ import { X as te } from "./x-B5YnXwCz.js";
24
+ import { R as Ce } from "./rotate-ccw-BBQnIVTr.js";
25
+ import { S as We } from "./square-DASBRZ0U.js";
26
+ import { M as ye } from "./mic-CUklMZGF.js";
27
+ import { S as xe } from "./send-C5kDJ-Mz.js";
28
+ import { G as we } from "./grip-vertical-onSb1JXO.js";
29
+ class ae extends Error {
30
+ constructor(o = "AI credits exhausted") {
31
+ super(o), this.name = "AiCreditsExhaustedError";
32
+ }
33
+ }
34
+ const q = "ds:!size-[var(--min-target-size)]", Ne = `${q} ds:bg-[image:var(--gradient-brand)] ds:rounded-full`, ke = "ds:aria-pressed:!bg-[var(--destructive)] ds:aria-pressed:!text-[var(--destructive-foreground)]", K = "ds:m-0 ds:text-[length:var(--font-size-sm)] ds:text-[color:var(--muted-foreground)]", De = "type-eyebrow ds:m-0 ds:text-[color:var(--muted-foreground)]", Ee = [
35
+ "ds:rounded-[var(--radius-md)] ds:border ds:border-[color:var(--border)]",
36
+ "ds:bg-[color-mix(in_srgb,var(--background)_70%,transparent)]",
37
+ "ds:p-[var(--spacing-sm)] ds:[max-block-size:14rem] ds:overflow-y-auto",
38
+ "ds:text-[length:var(--font-size-sm)] ds:text-[color:var(--foreground)]",
39
+ "ds:[&_ul]:list-disc ds:[&_ul]:ps-[var(--spacing-md)]",
40
+ "ds:[&_h3]:font-medium ds:[&_h3]:[margin-block-start:var(--spacing-xs)]",
41
+ "ds:[&_p]:[margin-block-end:var(--spacing-xs)]",
42
+ "ds:[&>:first-child]:[margin-block-start:0]"
43
+ ].join(" ");
44
+ function ne(e, o) {
45
+ return o ? e ? /\s$/.test(e) ? `${e}${o}` : `${e} ${o}` : o : e;
46
+ }
47
+ function ze(e) {
48
+ return typeof e == "object" && e !== null && "name" in e && e.name === "AbortError";
49
+ }
50
+ function Ie({
51
+ credits: e,
52
+ onBack: o
53
+ }) {
54
+ const { t: l, i18n: u } = $(), f = e == null ? void 0 : e.limit, T = (e == null ? void 0 : e.remaining) ?? 0, a = f !== void 0 ? l("helpMeWriteTemplates.credits.remaining", { remaining: T, limit: f }) : void 0, t = e != null && e.resetsOn ? new Intl.DateTimeFormat(u.language, {
55
+ day: "numeric",
56
+ month: "long"
57
+ }).format(e.resetsOn) : void 0;
58
+ return /* @__PURE__ */ m(
59
+ "div",
60
+ {
61
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]",
62
+ "data-component": "ai-credits-exhausted-notice",
63
+ children: [
64
+ /* @__PURE__ */ m(P, { variant: "promo", icon: /* @__PURE__ */ r(fe, { "aria-hidden": "true" }), children: [
65
+ /* @__PURE__ */ r(P.Title, { as: "h2", children: l("helpMeWriteTemplates.credits.title") }),
66
+ /* @__PURE__ */ r(P.Description, { children: e != null && e.onBuyCredits ? t ? l("helpMeWriteTemplates.credits.bodyResets", { date: t }) : l("helpMeWriteTemplates.credits.body") : t ? l("helpMeWriteTemplates.credits.bodyWaitResets", {
67
+ date: t
68
+ }) : l("helpMeWriteTemplates.credits.bodyWait") }),
69
+ f !== void 0 && a ? /* @__PURE__ */ m("div", { className: "ds:flex ds:flex-col ds:gap-[var(--spacing-2xs)] ds:[margin-block-start:var(--spacing-sm)]", children: [
70
+ /* @__PURE__ */ m("div", { className: "ds:flex ds:items-center ds:gap-[var(--spacing-xs)]", children: [
71
+ /* @__PURE__ */ r("span", { className: "type-label", children: l("helpMeWriteTemplates.credits.meterLabel") }),
72
+ /* @__PURE__ */ r("span", { className: "type-label ds:ms-auto ds:tabular-nums", children: a })
73
+ ] }),
74
+ /* @__PURE__ */ r(
75
+ pe,
76
+ {
77
+ value: Math.max(0, f - T),
78
+ max: f,
79
+ size: "sm",
80
+ ariaLabel: l("helpMeWriteTemplates.credits.meterLabel"),
81
+ ariaValueText: a
82
+ }
83
+ )
84
+ ] }) : null,
85
+ e != null && e.onBuyCredits || e != null && e.onSeeCosts ? /* @__PURE__ */ m(P.Action, { children: [
86
+ e.onBuyCredits ? /* @__PURE__ */ r(
87
+ D,
88
+ {
89
+ intent: "tonal",
90
+ size: "sm",
91
+ startIcon: /* @__PURE__ */ r(ge, { "aria-hidden": "true" }),
92
+ onClick: e.onBuyCredits,
93
+ children: l("helpMeWriteTemplates.credits.cta")
94
+ }
95
+ ) : null,
96
+ e.onSeeCosts ? /* @__PURE__ */ r(D, { intent: "link", size: "sm", onClick: e.onSeeCosts, children: l("helpMeWriteTemplates.credits.secondary") }) : null
97
+ ] }) : null
98
+ ] }),
99
+ /* @__PURE__ */ m("div", { className: "ds:flex ds:flex-wrap ds:items-center ds:gap-[var(--spacing-sm)]", children: [
100
+ o ? /* @__PURE__ */ r(D, { intent: "ghost", startIcon: /* @__PURE__ */ r(ve, {}), onClick: o, children: l("helpMeWriteTemplates.credits.back") }) : null,
101
+ /* @__PURE__ */ r("p", { className: K, children: l("helpMeWriteTemplates.credits.kept") })
102
+ ] })
103
+ ]
104
+ }
105
+ );
106
+ }
107
+ function Re({
108
+ context: e,
109
+ onGenerate: o,
110
+ onApplied: l,
111
+ credits: u,
112
+ enableDictation: f = !0,
113
+ suspendClose: T = !1
114
+ }) {
115
+ const { t: a } = $(), { open: t } = e, x = ee(), s = ee(), [c, E] = b(""), [w, I] = b(!1), [z, i] = b(!1), [v, d] = b(!1), [C, h] = b(null), g = V(null), k = f ? e.onDictate : void 0, [N, A] = b(!1), [L, B] = b(""), [X, n] = b(""), W = V(null), R = S(() => {
116
+ var p;
117
+ return (p = W.current) == null ? void 0 : p.abort();
118
+ }, []), ie = S(() => {
119
+ if (N) {
120
+ R();
121
+ return;
122
+ }
123
+ if (!k) return;
124
+ const p = new AbortController();
125
+ W.current = p, A(!0), n(a("helpMeWriteTemplates.bar.listening")), k({
126
+ signal: p.signal,
127
+ onPartialTranscript: (M) => {
128
+ p.signal.aborted || B(M);
129
+ },
130
+ onFinalTranscript: (M) => {
131
+ if (p.signal.aborted) return;
132
+ B("");
133
+ const O = M.trim();
134
+ O && (E((H) => ne(H, O)), n(O));
135
+ }
136
+ }).catch((M) => {
137
+ M instanceof ae && d(!0);
138
+ }).finally(() => {
139
+ B(""), W.current === p && (W.current = null, A(!1), n(""));
140
+ });
141
+ }, [N, k, R, a]);
142
+ U(() => {
143
+ var p, M;
144
+ t ? (E(""), I(!1), i(!1), d(e.creditsExhausted), h(null)) : ((p = g.current) == null || p.abort(), (M = W.current) == null || M.abort());
145
+ }, [t]), U(
146
+ () => () => {
147
+ var p, M;
148
+ (p = g.current) == null || p.abort(), (M = W.current) == null || M.abort();
149
+ },
150
+ []
151
+ );
152
+ const Q = S(() => {
153
+ var O;
154
+ if (w || !c.trim()) return;
155
+ R(), (O = g.current) == null || O.abort();
156
+ const p = new AbortController();
157
+ g.current = p, i(!1), I(!0);
158
+ const M = e.scope === "selection";
159
+ o({
160
+ prompt: c.trim(),
161
+ sourceText: M ? e.selectionText : e.getText(),
162
+ scope: M ? "selection" : "document",
163
+ signal: p.signal
164
+ }).then((H) => {
165
+ p.signal.aborted || (h(H), I(!1));
166
+ }).catch((H) => {
167
+ p.signal.aborted || ze(H) || (H instanceof ae ? d(!0) : i(!0), I(!1));
168
+ });
169
+ }, [w, c, o, R]), { onClose: G } = e, le = S(() => {
170
+ T || G();
171
+ }, [T, G]), oe = () => {
172
+ if (C === null) return;
173
+ const p = e.getHTML();
174
+ e.insertAtSelection(C), e.onClose();
175
+ const { setContent: M } = e;
176
+ l == null || l({
177
+ mode: e.scope === "selection" ? "replace" : "insert",
178
+ previousHtml: p,
179
+ undo: () => M(p)
180
+ });
181
+ };
182
+ let j;
183
+ if (v)
184
+ j = /* @__PURE__ */ r(
185
+ Ie,
186
+ {
187
+ credits: u,
188
+ onBack: () => d(!1)
189
+ }
190
+ );
191
+ else if (C !== null)
192
+ j = /* @__PURE__ */ m(_, { children: [
193
+ /* @__PURE__ */ m(
194
+ "section",
195
+ {
196
+ "aria-labelledby": x,
197
+ className: "ds:flex ds:min-w-0 ds:flex-col ds:gap-[var(--spacing-2xs)]",
198
+ children: [
199
+ /* @__PURE__ */ r("h2", { id: x, className: De, children: a("helpMeWriteTemplates.bar.after") }),
200
+ /* @__PURE__ */ r(
201
+ he,
202
+ {
203
+ html: C,
204
+ profile: "rich-text",
205
+ className: Ee,
206
+ tabIndex: 0
207
+ }
208
+ )
209
+ ]
210
+ }
211
+ ),
212
+ /* @__PURE__ */ m("div", { className: "ds:flex ds:flex-wrap ds:items-center ds:gap-[var(--spacing-sm)]", children: [
213
+ /* @__PURE__ */ r(D, { intent: "ghost", startIcon: /* @__PURE__ */ r(te, {}), onClick: e.onClose, children: a("helpMeWriteTemplates.bar.discard") }),
214
+ /* @__PURE__ */ r(
215
+ D,
216
+ {
217
+ intent: "ghost",
218
+ startIcon: /* @__PURE__ */ r(Ce, {}),
219
+ onClick: () => {
220
+ h(null), Q();
221
+ },
222
+ children: a("helpMeWriteTemplates.bar.retry")
223
+ }
224
+ ),
225
+ /* @__PURE__ */ r("span", { className: "ds:flex-1", "aria-hidden": "true" }),
226
+ /* @__PURE__ */ r(D, { intent: "primary", onClick: oe, children: e.scope === "selection" ? a("helpMeWriteTemplates.bar.replace") : a("helpMeWriteTemplates.bar.insert") })
227
+ ] })
228
+ ] });
229
+ else {
230
+ const p = N ? ne(c, L) : c;
231
+ j = /* @__PURE__ */ m(_, { children: [
232
+ /* @__PURE__ */ m("div", { className: "ds:flex ds:items-center ds:gap-[var(--spacing-sm)]", children: [
233
+ /* @__PURE__ */ r(
234
+ F,
235
+ {
236
+ size: "md",
237
+ intent: "outline",
238
+ className: q,
239
+ icon: /* @__PURE__ */ r(te, {}),
240
+ "aria-label": a("helpMeWriteTemplates.bar.close"),
241
+ onClick: e.onClose
242
+ }
243
+ ),
244
+ /* @__PURE__ */ r("div", { className: "ds:min-w-0 ds:flex-1", children: /* @__PURE__ */ r(
245
+ se,
246
+ {
247
+ size: "md",
248
+ value: p,
249
+ onChange: (M) => E(M.target.value),
250
+ placeholder: a("editor.ai.promptPlaceholder"),
251
+ "aria-label": a("editor.ai.promptLabel"),
252
+ autoResize: !0,
253
+ minRows: 1,
254
+ maxRows: 3,
255
+ readOnly: w || N,
256
+ tone: z ? "error" : "default",
257
+ "aria-describedby": z ? s : void 0
258
+ }
259
+ ) }),
260
+ k ? /* @__PURE__ */ r(
261
+ F,
262
+ {
263
+ size: "md",
264
+ intent: "outline",
265
+ className: N ? `${q} ${ke}` : q,
266
+ icon: N ? /* @__PURE__ */ r(We, { className: "ds:fill-current" }) : /* @__PURE__ */ r(ye, {}),
267
+ "aria-pressed": N,
268
+ "aria-label": a(N ? "helpMeWriteTemplates.bar.dictateStop" : "helpMeWriteTemplates.bar.dictateStart"),
269
+ disabled: w,
270
+ onClick: ie
271
+ }
272
+ ) : null,
273
+ /* @__PURE__ */ r(
274
+ F,
275
+ {
276
+ size: "md",
277
+ intent: "primary",
278
+ className: Ne,
279
+ icon: w ? /* @__PURE__ */ r(ue, { size: "sm", variant: "pulse" }) : /* @__PURE__ */ r(xe, {}),
280
+ disabled: w || !c.trim(),
281
+ "aria-busy": w || void 0,
282
+ "aria-label": a("helpMeWriteTemplates.bar.write"),
283
+ onClick: Q
284
+ }
285
+ )
286
+ ] }),
287
+ k ? /* @__PURE__ */ r("p", { className: "ds:sr-only", role: "status", "aria-live": "polite", children: X }) : null,
288
+ z ? /* @__PURE__ */ r("p", { id: s, role: "alert", className: K, children: a("helpMeWriteTemplates.bar.error") }) : null,
289
+ /* @__PURE__ */ m("p", { className: K, children: [
290
+ e.scope === "selection" ? a("helpMeWriteTemplates.bar.contextSelection") : a("helpMeWriteTemplates.bar.contextDocument"),
291
+ " ",
292
+ e.privacyNotice
293
+ ] })
294
+ ] });
295
+ }
296
+ return /* @__PURE__ */ r(
297
+ de,
298
+ {
299
+ open: t,
300
+ onClose: le,
301
+ ariaLabel: a("editor.ai.helpMeWrite"),
302
+ children: /* @__PURE__ */ r("div", { className: "ds:contents", "data-component": "help-me-write-templates-bar", children: j })
303
+ }
304
+ );
305
+ }
306
+ const Ae = ce("", {
307
+ variants: {
308
+ dragging: { true: "ds:opacity-60", false: "" },
309
+ dropTarget: {
310
+ true: "ds:outline-[length:var(--focus-ring-width)] ds:outline-dashed ds:outline-[var(--primary)] ds:outline-offset-[-2px]",
311
+ false: ""
312
+ }
313
+ },
314
+ defaultVariants: { dragging: !1, dropTarget: !1 }
315
+ });
316
+ function Se(e, o) {
317
+ const { t: l } = $(), [u, f] = b(null), [T, a] = b(null), [t, x] = b(""), s = V(!1), c = (i, v) => {
318
+ const d = Math.max(0, Math.min(e.length - 1, v));
319
+ if (!o || d === i) return;
320
+ const C = e.map((k) => k.id), [h] = C.splice(i, 1);
321
+ C.splice(d, 0, h), o(C), s.current = !s.current;
322
+ const g = l("helpMeWriteTemplates.manager.reorderAnnounce", {
323
+ label: e[i].name,
324
+ to: d + 1,
325
+ total: e.length
326
+ });
327
+ x(s.current ? g : `${g}​`);
328
+ };
329
+ return { rowProps: (i) => o ? {
330
+ draggable: !0,
331
+ onDragStart: (v) => {
332
+ f(i), v.dataTransfer.effectAllowed = "move", v.dataTransfer.setData("text/plain", String(i));
333
+ },
334
+ onDragEnd: () => {
335
+ f(null), a(null);
336
+ },
337
+ onDragOver: (v) => {
338
+ u !== null && (v.preventDefault(), v.dataTransfer.dropEffect = "move", a(i));
339
+ },
340
+ onDragLeave: () => a(null),
341
+ onDrop: (v) => {
342
+ v.preventDefault();
343
+ const d = u;
344
+ f(null), a(null), d !== null && c(d, i);
345
+ }
346
+ } : {}, rowClass: (i) => Ae({
347
+ dragging: u === i,
348
+ dropTarget: T === i && u !== i
349
+ }), handle: (i, v) => /* @__PURE__ */ r(
350
+ F,
351
+ {
352
+ size: "sm",
353
+ intent: "ghost",
354
+ icon: /* @__PURE__ */ r(we, { "aria-hidden": "true" }),
355
+ "aria-label": l("helpMeWriteTemplates.manager.reorderHandle", {
356
+ label: v
357
+ }),
358
+ className: "ds:cursor-grab ds:active:cursor-grabbing",
359
+ onKeyDown: (d) => {
360
+ if (!d.altKey) return;
361
+ const C = d.key === "ArrowUp" ? i - 1 : d.key === "ArrowDown" ? i + 1 : d.key === "Home" ? 0 : d.key === "End" ? e.length - 1 : null;
362
+ C !== null && (d.preventDefault(), c(i, C));
363
+ }
364
+ }
365
+ ), liveRegion: /* @__PURE__ */ r("span", { role: "status", "aria-live": "polite", className: "ds:sr-only", children: t }) };
366
+ }
367
+ const J = {
368
+ name: "",
369
+ description: "",
370
+ prompt: "",
371
+ submitted: !1
372
+ };
373
+ function Pe({
374
+ open: e,
375
+ onOpenChange: o,
376
+ initialMode: l = "list",
377
+ templates: u,
378
+ onSaveTemplate: f,
379
+ onDeleteTemplate: T,
380
+ onReorderTemplates: a
381
+ }) {
382
+ const { t } = $(), x = Se(u, a), [s, c] = b(null), [E, w] = b(!1), [I, z] = b(!1), [i, v] = b(null), [d, C] = b(!1), [h, g] = b(!1), k = async () => {
383
+ if (!(!i || d)) {
384
+ C(!0), g(!1);
385
+ try {
386
+ await (T == null ? void 0 : T(i.id)), v(null);
387
+ } catch {
388
+ g(!0);
389
+ } finally {
390
+ C(!1);
391
+ }
392
+ }
393
+ };
394
+ U(() => {
395
+ e && (z(!1), c(l === "create" ? { ...J } : null));
396
+ }, [e]);
397
+ const N = (n, W) => u.some(
398
+ (R) => R.id !== W && R.name.toLowerCase() === n.toLowerCase()
399
+ ), A = (() => {
400
+ if (!(s != null && s.submitted)) return;
401
+ const n = s.name.trim();
402
+ return n ? N(n, s.id) ? t("helpMeWriteTemplates.manager.nameTaken") : void 0 : t("helpMeWriteTemplates.manager.nameRequired");
403
+ })(), L = s != null && s.submitted && !s.prompt.trim() ? t("helpMeWriteTemplates.manager.promptRequired") : void 0, B = async () => {
404
+ if (!s || E) return;
405
+ const n = { ...s, submitted: !0 };
406
+ c(n);
407
+ const W = n.name.trim(), R = n.prompt.trim();
408
+ if (!(!W || !R || N(W, n.id))) {
409
+ w(!0), z(!1);
410
+ try {
411
+ await f({
412
+ id: n.id,
413
+ name: W,
414
+ description: n.description.trim() || void 0,
415
+ prompt: R
416
+ }), c(null);
417
+ } catch {
418
+ z(!0);
419
+ } finally {
420
+ w(!1);
421
+ }
422
+ }
423
+ }, X = s ? s.id ? t("helpMeWriteTemplates.manager.formEdit") : t("helpMeWriteTemplates.manager.formNew") : t("helpMeWriteTemplates.manager.title");
424
+ return /* @__PURE__ */ m(_, { children: [
425
+ /* @__PURE__ */ r(y, { open: e, onOpenChange: o, children: /* @__PURE__ */ r(y.Content, { size: "lg", children: /* @__PURE__ */ m("div", { className: "ds:contents", "data-component": "ai-template-manager", children: [
426
+ /* @__PURE__ */ m(y.Header, { children: [
427
+ /* @__PURE__ */ r(y.Title, { children: X }),
428
+ /* @__PURE__ */ r(y.Description, { children: t("helpMeWriteTemplates.manager.description") })
429
+ ] }),
430
+ /* @__PURE__ */ m(y.Body, { children: [
431
+ s ? /* @__PURE__ */ m("div", { className: "ds:flex ds:flex-col ds:gap-[var(--spacing-md)]", children: [
432
+ I ? /* @__PURE__ */ r(P, { variant: "error", children: t("helpMeWriteTemplates.manager.saveError") }) : null,
433
+ /* @__PURE__ */ r(
434
+ Z,
435
+ {
436
+ label: t("helpMeWriteTemplates.manager.name"),
437
+ error: A,
438
+ required: !0,
439
+ children: /* @__PURE__ */ r(
440
+ re,
441
+ {
442
+ value: s.name,
443
+ maxLength: 100,
444
+ placeholder: t(
445
+ "helpMeWriteTemplates.manager.namePlaceholder"
446
+ ),
447
+ onChange: (n) => c({ ...s, name: n.target.value })
448
+ }
449
+ )
450
+ }
451
+ ),
452
+ /* @__PURE__ */ r(
453
+ Z,
454
+ {
455
+ label: t("helpMeWriteTemplates.manager.descLabel"),
456
+ description: t("helpMeWriteTemplates.manager.descHint"),
457
+ optional: !0,
458
+ children: /* @__PURE__ */ r(
459
+ re,
460
+ {
461
+ value: s.description,
462
+ maxLength: 120,
463
+ onChange: (n) => c({ ...s, description: n.target.value })
464
+ }
465
+ )
466
+ }
467
+ ),
468
+ /* @__PURE__ */ r(
469
+ Z,
470
+ {
471
+ label: t("helpMeWriteTemplates.manager.prompt"),
472
+ description: t(
473
+ "helpMeWriteTemplates.manager.promptDescription"
474
+ ),
475
+ error: L,
476
+ required: !0,
477
+ children: /* @__PURE__ */ r(
478
+ se,
479
+ {
480
+ value: s.prompt,
481
+ maxLength: 4e3,
482
+ autoResize: !0,
483
+ minRows: 4,
484
+ maxRows: 10,
485
+ onChange: (n) => c({ ...s, prompt: n.target.value })
486
+ }
487
+ )
488
+ }
489
+ )
490
+ ] }) : u.length === 0 ? /* @__PURE__ */ r(
491
+ me,
492
+ {
493
+ variant: "first-use",
494
+ size: "sm",
495
+ title: t("helpMeWriteTemplates.manager.emptyTitle"),
496
+ description: t(
497
+ "helpMeWriteTemplates.manager.emptyDescription"
498
+ ),
499
+ primaryAction: {
500
+ label: t("helpMeWriteTemplates.manager.new"),
501
+ onClick: () => c({ ...J })
502
+ }
503
+ }
504
+ ) : /* @__PURE__ */ r(
505
+ "ul",
506
+ {
507
+ "aria-label": t("helpMeWriteTemplates.manager.listLabel"),
508
+ className: "ds:m-0 ds:flex ds:list-none ds:flex-col ds:gap-[var(--spacing-sm)] ds:p-0",
509
+ children: u.map((n, W) => /* @__PURE__ */ m(
510
+ "li",
511
+ {
512
+ ...x.rowProps(W),
513
+ className: `ds:flex ds:items-start ds:gap-[var(--spacing-sm)] ds:rounded-[var(--radius-md)] ds:border ds:border-[color:var(--border)] ds:p-[var(--spacing-sm)] ${x.rowClass(W)}`,
514
+ children: [
515
+ a ? x.handle(W, n.name) : null,
516
+ /* @__PURE__ */ m("div", { className: "ds:flex ds:min-w-0 ds:flex-1 ds:flex-col ds:gap-[var(--spacing-2xs)]", children: [
517
+ /* @__PURE__ */ r("div", { className: "ds:flex ds:flex-wrap ds:items-center ds:gap-[var(--spacing-xs)]", children: /* @__PURE__ */ r("span", { className: "type-title-item ds:text-[color:var(--foreground)]", children: n.name }) }),
518
+ /* @__PURE__ */ r("p", { className: `${K} ds:line-clamp-2`, children: n.description || n.prompt })
519
+ ] }),
520
+ /* @__PURE__ */ r(
521
+ F,
522
+ {
523
+ size: "sm",
524
+ intent: "ghost",
525
+ icon: /* @__PURE__ */ r(be, {}),
526
+ "aria-label": t("helpMeWriteTemplates.manager.edit", {
527
+ name: n.name
528
+ }),
529
+ onClick: () => c({
530
+ id: n.id,
531
+ name: n.name,
532
+ description: n.description ?? "",
533
+ prompt: n.prompt,
534
+ submitted: !1
535
+ })
536
+ }
537
+ ),
538
+ T ? /* @__PURE__ */ r(
539
+ F,
540
+ {
541
+ size: "sm",
542
+ intent: "ghost",
543
+ icon: /* @__PURE__ */ r(Te, {}),
544
+ "aria-label": t("helpMeWriteTemplates.manager.delete", {
545
+ name: n.name
546
+ }),
547
+ onClick: () => v(n)
548
+ }
549
+ ) : null
550
+ ]
551
+ },
552
+ n.id
553
+ ))
554
+ }
555
+ ),
556
+ x.liveRegion
557
+ ] }),
558
+ /* @__PURE__ */ r(y.Footer, { children: s ? /* @__PURE__ */ m(_, { children: [
559
+ /* @__PURE__ */ r(D, { intent: "secondary", onClick: () => c(null), children: t("helpMeWriteTemplates.manager.cancel") }),
560
+ /* @__PURE__ */ r(
561
+ D,
562
+ {
563
+ intent: "primary",
564
+ loading: E,
565
+ onClick: () => void B(),
566
+ children: t("helpMeWriteTemplates.manager.save")
567
+ }
568
+ )
569
+ ] }) : /* @__PURE__ */ m(_, { children: [
570
+ u.length > 0 ? /* @__PURE__ */ r(
571
+ D,
572
+ {
573
+ intent: "outline",
574
+ startIcon: /* @__PURE__ */ r(Me, {}),
575
+ onClick: () => c({ ...J }),
576
+ children: t("helpMeWriteTemplates.manager.new")
577
+ }
578
+ ) : null,
579
+ /* @__PURE__ */ r(y.Close, { asChild: !0, children: /* @__PURE__ */ r(D, { intent: "primary", children: t("helpMeWriteTemplates.manager.done") }) })
580
+ ] }) })
581
+ ] }) }) }),
582
+ /* @__PURE__ */ r(
583
+ y,
584
+ {
585
+ open: i != null,
586
+ onOpenChange: (n) => {
587
+ !n && !d && (v(null), g(!1));
588
+ },
589
+ children: /* @__PURE__ */ m(y.Content, { size: "sm", variant: "alert", children: [
590
+ /* @__PURE__ */ m(y.Header, { children: [
591
+ /* @__PURE__ */ r(y.Title, { children: t("helpMeWriteTemplates.manager.deleteTitle", {
592
+ name: (i == null ? void 0 : i.name) ?? ""
593
+ }) }),
594
+ /* @__PURE__ */ r(y.Description, { children: t("helpMeWriteTemplates.manager.deleteDescription") })
595
+ ] }),
596
+ h ? /* @__PURE__ */ r(y.Body, { children: /* @__PURE__ */ r(P, { variant: "error", children: t("helpMeWriteTemplates.manager.deleteError") }) }) : null,
597
+ /* @__PURE__ */ m(y.Footer, { children: [
598
+ /* @__PURE__ */ r(y.Close, { asChild: !0, children: /* @__PURE__ */ r(D, { intent: "secondary", disabled: d, children: t("helpMeWriteTemplates.manager.cancel") }) }),
599
+ /* @__PURE__ */ r(
600
+ D,
601
+ {
602
+ intent: "destructive",
603
+ loading: d,
604
+ onClick: () => void k(),
605
+ children: t("helpMeWriteTemplates.manager.deleteConfirm")
606
+ }
607
+ )
608
+ ] })
609
+ ] })
610
+ }
611
+ )
612
+ ] });
613
+ }
614
+ function Le({
615
+ applied: e,
616
+ onUndo: o,
617
+ onDismiss: l
618
+ }) {
619
+ const { t: u } = $(), f = V(null);
620
+ if (U(() => {
621
+ var a;
622
+ e && ((a = f.current) == null || a.focus());
623
+ }, [e]), !(e != null && e.template)) return null;
624
+ const T = e.template.name;
625
+ return /* @__PURE__ */ r(
626
+ P,
627
+ {
628
+ variant: "success",
629
+ dismissible: !0,
630
+ onOpenChange: (a) => {
631
+ a || l();
632
+ },
633
+ "data-component": "help-me-write-undo-notice",
634
+ children: /* @__PURE__ */ m("div", { className: "ds:flex ds:flex-wrap ds:items-center ds:gap-[var(--spacing-sm)]", children: [
635
+ /* @__PURE__ */ r("span", { children: e.mode === "below" ? u("helpMeWriteTemplates.undo.addedBelow", { name: T }) : u("helpMeWriteTemplates.undo.replaced", { name: T }) }),
636
+ /* @__PURE__ */ r(D, { ref: f, intent: "outline", size: "sm", onClick: o, children: u("helpMeWriteTemplates.undo.undo") })
637
+ ] })
638
+ }
639
+ );
640
+ }
641
+ function mr({
642
+ templates: e,
643
+ onGenerate: o,
644
+ onSaveTemplate: l,
645
+ onDeleteTemplate: u,
646
+ onReorderTemplates: f,
647
+ credits: T,
648
+ enableDictation: a,
649
+ onApplied: t
650
+ }) {
651
+ const [x, s] = b({ open: !1, mode: "list" }), [c, E] = b(null), w = S(
652
+ (h = "list") => s({ open: !0, mode: h }),
653
+ []
654
+ ), I = S(
655
+ (h) => /* @__PURE__ */ r(
656
+ Re,
657
+ {
658
+ context: h,
659
+ onGenerate: o,
660
+ credits: T,
661
+ enableDictation: a,
662
+ suspendClose: x.open,
663
+ onApplied: t
664
+ }
665
+ ),
666
+ [o, T, a, x.open, t]
667
+ ), z = Y(() => {
668
+ const h = new Map(e.map((g) => [g.id, g]));
669
+ return {
670
+ templates: e,
671
+ onRun: ({ template: g, text: k, scope: N, signal: A }) => {
672
+ const L = h.get(g.id);
673
+ return L ? o({
674
+ template: L,
675
+ prompt: "",
676
+ sourceText: k,
677
+ scope: N,
678
+ signal: A
679
+ }) : Promise.reject(new Error("Unknown template"));
680
+ },
681
+ onManage: l ? w : void 0
682
+ };
683
+ }, [e, o, l, w]), i = S(
684
+ (h) => {
685
+ if (h.action !== "template" || !h.template) return;
686
+ const g = e.find((N) => {
687
+ var A;
688
+ return N.id === ((A = h.template) == null ? void 0 : A.id);
689
+ }), k = {
690
+ mode: "replace",
691
+ template: g,
692
+ previousHtml: h.previousHtml,
693
+ undo: h.undo
694
+ };
695
+ E(g ? k : null), t == null || t(k);
696
+ },
697
+ [e, t]
698
+ ), v = Y(
699
+ () => l ? /* @__PURE__ */ r(
700
+ Pe,
701
+ {
702
+ open: x.open,
703
+ initialMode: x.mode,
704
+ onOpenChange: (h) => s((g) => ({ ...g, open: h })),
705
+ templates: e,
706
+ onSaveTemplate: l,
707
+ onDeleteTemplate: u,
708
+ onReorderTemplates: f
709
+ }
710
+ ) : null,
711
+ [x, e, l, u, f]
712
+ ), d = /* @__PURE__ */ r(
713
+ Le,
714
+ {
715
+ applied: c,
716
+ onUndo: () => {
717
+ c == null || c.undo(), E(null);
718
+ },
719
+ onDismiss: () => E(null)
720
+ }
721
+ ), C = Y(
722
+ () => ({ renderHelpMeWrite: I, aiTemplates: z, onAiApplied: i }),
723
+ [I, z, i]
724
+ );
725
+ return {
726
+ ...C,
727
+ editorProps: C,
728
+ manager: v,
729
+ undoNotice: d,
730
+ openManager: w
731
+ };
732
+ }
733
+ export {
734
+ ae as A,
735
+ Re as H,
736
+ Ie as a,
737
+ Pe as b,
738
+ Le as c,
739
+ mr as u
740
+ };
741
+ //# sourceMappingURL=help-me-write-templates-GUeEn3Ff.js.map