@inploi/plugin-chatbot 3.2.5 → 3.2.6

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,2223 +0,0 @@
1
- import { m as ze, AnimatePresence as Ke } from "framer-motion";
2
- import { _ as j, g as Zt, A as ye, N as te, a as Xt, o as c, c as ce, b as Ee, p as He, d as Vt, e as er, f as U, h as ke, k as Ft, i as tr, j as We, C as W, l as rr, V as sr, m as Ct, t as Et, n as ir, q as Mt, r as nr, s as ar, u as xe, v as lr, w as or, x as ur, y as qe, T as cr, z as $e, F as ct, B as dr, E as fr } from "./chatbot.js";
3
- const Dt = ({
4
- node: e,
5
- nodes: s,
6
- stopWhen: t
7
- }) => {
8
- if ((t == null ? void 0 : t(e)) === !0)
9
- return e;
10
- const r = e.nextId ? s.find((n) => n.id === e.nextId) : void 0;
11
- if (r)
12
- return Dt({
13
- node: r,
14
- nodes: s,
15
- stopWhen: t
16
- });
17
- }, hr = ({
18
- childNode: e,
19
- nodes: s
20
- }) => {
21
- const r = s.filter((n) => n.type === "if-block").find((n) => {
22
- if (!n.branchId)
23
- return !1;
24
- const a = s.find((y) => y.id === n.branchId);
25
- if (!a)
26
- return !1;
27
- const o = Dt({
28
- node: a,
29
- nodes: s,
30
- stopWhen: (y) => y.id === e.id
31
- });
32
- return !(!o || o.id !== e.id);
33
- });
34
- if (r != null && r.nextId)
35
- return s.find((n) => n.id === r.nextId);
36
- }, yr = ({
37
- flow: e,
38
- analytics: s,
39
- logger: t,
40
- context: r,
41
- apiClient: n,
42
- getSubmissions: a,
43
- chatService: o,
44
- onFlowEnd: y,
45
- onInterpret: f
46
- }) => {
47
- const x = new AbortController(), S = async (p, g) => {
48
- const V = a();
49
- f == null || f(p, g);
50
- try {
51
- await pr({
52
- analytics: s,
53
- logger: t,
54
- apiClient: n,
55
- context: r,
56
- node: p,
57
- submissions: V,
58
- chat: {
59
- sendMessage: async (k) => o.send({
60
- groupId: p.id,
61
- message: k,
62
- signal: x.signal
63
- }),
64
- userInput: async (k) => o.input({
65
- input: k,
66
- signal: x.signal
67
- })
68
- },
69
- next: (k) => {
70
- const R = k ? e.find((E) => E.id === k) : hr({
71
- childNode: p,
72
- nodes: e
73
- });
74
- return R ? S(R, p) : y == null ? void 0 : y(p);
75
- }
76
- });
77
- } catch (k) {
78
- if (k instanceof ye)
79
- return;
80
- throw k;
81
- }
82
- };
83
- return {
84
- interpret: async (p) => {
85
- const g = e.find((V) => V.id === p) ?? Zt(e);
86
- return S(g);
87
- },
88
- abort: () => {
89
- x.abort();
90
- }
91
- };
92
- };
93
- async function pr(e) {
94
- return await te(e).with({
95
- node: {
96
- type: "text"
97
- }
98
- }, xr).with({
99
- node: {
100
- type: "image"
101
- }
102
- }, br).with({
103
- node: {
104
- type: "question-text"
105
- }
106
- }, wr).with({
107
- node: {
108
- type: "question-enum"
109
- }
110
- }, kr).with({
111
- node: {
112
- type: "question-number"
113
- }
114
- }, Sr).with({
115
- node: {
116
- type: "question-boolean"
117
- }
118
- }, _r).with({
119
- node: {
120
- type: "question-file"
121
- }
122
- }, Vr).with({
123
- node: {
124
- type: "question-address"
125
- }
126
- }, Ar).with({
127
- node: {
128
- type: "end-flow"
129
- }
130
- }, Fr).with({
131
- node: {
132
- type: "if-block"
133
- }
134
- }, vr).with({
135
- node: {
136
- type: "jump"
137
- }
138
- }, ({
139
- node: s,
140
- next: t
141
- }) => t(s.data.targetId)).with({
142
- node: {
143
- type: "link"
144
- }
145
- }, mr).with({
146
- node: {
147
- type: "submit"
148
- }
149
- }, gr).exhaustive();
150
- }
151
- async function gr({
152
- chat: e,
153
- next: s,
154
- node: t,
155
- logger: r,
156
- apiClient: n,
157
- submissions: a,
158
- context: o
159
- }) {
160
- await e.userInput({
161
- type: "multiple-choice",
162
- key: void 0,
163
- config: {
164
- options: [{
165
- label: "Submit my application",
166
- value: "submit"
167
- }],
168
- maxSelected: 1,
169
- minSelected: 1
170
- }
171
- }), await e.sendMessage({
172
- type: "system",
173
- variant: "info",
174
- text: "Submitting your application…"
175
- });
176
- const y = await n.fetch("/flow/apply", {
177
- method: "POST",
178
- body: JSON.stringify({
179
- ...o,
180
- submissions: Xt(a || {})
181
- })
182
- }).catch((f) => f);
183
- await te(y).with({
184
- redirect_url: j.string
185
- }, async (f) => {
186
- await e.sendMessage({
187
- type: "text",
188
- author: "bot",
189
- text: "Almost there! Please finalise your application on our partner’s website."
190
- }), await e.sendMessage({
191
- type: "link",
192
- href: f.redirect_url,
193
- text: "Finalise application on partner"
194
- });
195
- }).with({
196
- message: "Success"
197
- }, async () => {
198
- await e.sendMessage({
199
- type: "system",
200
- variant: "success",
201
- text: "Application submitted"
202
- }), s(t.nextId);
203
- }).otherwise(async (f) => {
204
- r.error(f), await e.sendMessage({
205
- type: "system",
206
- variant: "error",
207
- text: "Failed to submit application"
208
- }), s(t.id);
209
- });
210
- }
211
- async function mr({
212
- chat: e,
213
- next: s,
214
- node: t
215
- }) {
216
- await e.sendMessage({
217
- type: "link",
218
- href: t.data.href,
219
- text: t.data.cta
220
- }), s(t.nextId);
221
- }
222
- async function vr({
223
- submissions: e,
224
- next: s,
225
- node: t
226
- }) {
227
- const r = Cr(t, e) ? t.branchId : t.nextId;
228
- s(r);
229
- }
230
- async function xr({
231
- chat: e,
232
- next: s,
233
- node: t
234
- }) {
235
- await e.sendMessage({
236
- author: "bot",
237
- type: "text",
238
- text: t.data.text
239
- }), s(t.nextId);
240
- }
241
- async function br({
242
- chat: e,
243
- next: s,
244
- node: t
245
- }) {
246
- await e.sendMessage({
247
- author: "bot",
248
- type: "image",
249
- url: t.data.url,
250
- height: t.data.height,
251
- width: t.data.width
252
- }), s(t.nextId);
253
- }
254
- async function wr({
255
- chat: e,
256
- next: s,
257
- node: t
258
- }) {
259
- await e.sendMessage({
260
- author: "bot",
261
- type: "text",
262
- text: t.data.question
263
- });
264
- const r = await e.userInput({
265
- key: t.data.key,
266
- type: "text",
267
- config: {
268
- placeholder: t.data.placeholder,
269
- format: t.data.format
270
- }
271
- });
272
- await e.sendMessage({
273
- author: "user",
274
- type: "text",
275
- text: r.value
276
- }), s(t.nextId);
277
- }
278
- async function Sr({
279
- chat: e,
280
- next: s,
281
- node: t
282
- }) {
283
- await e.sendMessage({
284
- author: "bot",
285
- type: "text",
286
- text: t.data.question
287
- });
288
- const r = await e.userInput({
289
- key: t.data.key,
290
- type: "text",
291
- config: {
292
- placeholder: t.data.placeholder,
293
- format: "text"
294
- }
295
- });
296
- await e.sendMessage({
297
- author: "user",
298
- type: "text",
299
- text: r.value
300
- }), s(t.nextId);
301
- }
302
- async function kr({
303
- chat: e,
304
- next: s,
305
- node: t
306
- }) {
307
- await e.sendMessage({
308
- author: "bot",
309
- type: "text",
310
- text: t.data.question
311
- });
312
- const r = await e.userInput({
313
- key: t.data.key,
314
- type: "multiple-choice",
315
- config: t.data
316
- });
317
- await e.sendMessage({
318
- author: "user",
319
- type: "text",
320
- text: r.value.join(", ")
321
- }), s(t.nextId);
322
- }
323
- async function _r({
324
- chat: e,
325
- next: s,
326
- node: t
327
- }) {
328
- await e.sendMessage({
329
- author: "bot",
330
- type: "text",
331
- text: t.data.question
332
- });
333
- const n = (await e.userInput({
334
- key: t.data.key,
335
- type: "boolean",
336
- config: {
337
- labels: {
338
- true: t.data.trueLabel,
339
- false: t.data.falseLabel
340
- }
341
- }
342
- })).value, a = {
343
- true: t.data.trueLabel,
344
- false: t.data.falseLabel
345
- };
346
- await e.sendMessage({
347
- author: "user",
348
- type: "text",
349
- text: a[n]
350
- }), s(t.nextId);
351
- }
352
- async function Ar({
353
- chat: e,
354
- next: s,
355
- node: t
356
- }) {
357
- await e.sendMessage({
358
- author: "bot",
359
- type: "text",
360
- text: "Address questions are not implemented yet"
361
- }), s(t.nextId);
362
- }
363
- async function Vr({
364
- node: e,
365
- chat: s,
366
- next: t
367
- }) {
368
- await s.sendMessage({
369
- author: "bot",
370
- type: "text",
371
- text: e.data.question
372
- });
373
- const r = await s.userInput({
374
- key: e.data.key,
375
- type: "file",
376
- config: {
377
- extensions: e.data.extensions,
378
- fileSizeLimitKib: e.data.maxSizeKb,
379
- allowMultiple: e.data.multiple === !0
380
- }
381
- });
382
- for await (const n of r.value)
383
- await s.sendMessage({
384
- author: "user",
385
- type: "file",
386
- fileName: n.name,
387
- fileSizeKb: n.sizeKb
388
- });
389
- t(e.nextId);
390
- }
391
- async function Fr({
392
- chat: e,
393
- next: s,
394
- node: t
395
- }) {
396
- await e.sendMessage({
397
- type: "system",
398
- variant: "info",
399
- text: t.data.systemMessage || "Conversation finished"
400
- }), s(void 0);
401
- }
402
- const dt = j.union(j.string, j.array(j.string)), Cr = (e, s) => {
403
- const t = s == null ? void 0 : s[e.data.compareKey];
404
- return t ? te({
405
- ...e.data,
406
- answer: t
407
- }).with({
408
- compare: "equals"
409
- }, ({
410
- compareValue: r
411
- }) => typeof t.value == "string" || typeof t.value == "boolean" ? r === t.value.toString() : !1).with({
412
- compare: "notEquals"
413
- }, ({
414
- compareValue: r
415
- }) => typeof t.value == "string" || typeof t.value == "boolean" ? r !== t.value.toString() : !1).with({
416
- compare: "contains",
417
- answer: {
418
- value: dt
419
- }
420
- }, ({
421
- compareValue: r,
422
- answer: n
423
- }) => n.value.includes(r)).with({
424
- compare: "notContains",
425
- answer: {
426
- value: dt
427
- }
428
- }, ({
429
- compareValue: r,
430
- answer: n
431
- }) => !n.value.includes(r)).with({
432
- answer: {
433
- type: "file"
434
- }
435
- }, () => !1).exhaustive() : !1;
436
- }, Me = ({
437
- class: e,
438
- ...s
439
- }) => c("button", {
440
- class: ce("bg-accent-7 active:bg-accent-10 active:text-accent-2 text-lowest pointer-coarse:touch-hitbox focus-visible:ring-accent-7/50 flex-shrink-0 rounded-full p-2 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", e),
441
- ...s,
442
- children: c("svg", {
443
- class: "block",
444
- width: "16",
445
- height: "16",
446
- viewBox: "0 0 16 16",
447
- fill: "transparent",
448
- stroke: "currentColor",
449
- "stroke-linecap": "round",
450
- "stroke-width": "2",
451
- children: [c("title", {
452
- children: "Send"
453
- }), c("path", {
454
- d: "M3.5 7.5L8 3L12.5 7.5"
455
- }), c("path", {
456
- d: "M8 4V13"
457
- })]
458
- })
459
- }), Qe = () => {
460
- const e = Ee(null);
461
- return He(() => {
462
- var s;
463
- (s = e.current) == null || s.focus();
464
- }, []), e;
465
- }, It = ["true", "false"], Er = er(It), Mr = "answer", Dr = ({
466
- input: e,
467
- onSubmitSuccess: s,
468
- onHeightChange: t
469
- }) => {
470
- const r = Qe();
471
- return t(), c("form", {
472
- noValidate: !0,
473
- class: "flex items-center gap-2",
474
- onSubmit: (n) => {
475
- n.preventDefault();
476
- const a = te(n).with({
477
- nativeEvent: {
478
- submitter: j.select(j.union(j.instanceOf(HTMLButtonElement), j.instanceOf(HTMLInputElement)))
479
- }
480
- }, (y) => y.value).otherwise(() => {
481
- throw new Error("invalid form");
482
- }), o = Vt(Er, a);
483
- s(o);
484
- },
485
- children: It.map((n, a) => c("button", {
486
- ref: a === 0 ? r : null,
487
- type: "submit",
488
- name: Mr,
489
- value: n,
490
- class: "bg-lowest ease-expo-out ring-neutral-12/5 text-neutral-12 active:ring-accent-7 active:bg-accent-2 active:text-accent-11 fr block flex-1 overflow-hidden rounded-2xl px-2.5 py-2.5 ring-2 transition-all duration-300 selection:bg-transparent",
491
- children: c("p", {
492
- class: "truncate text-center text-base",
493
- children: e.config.labels[n]
494
- })
495
- }))
496
- });
497
- }, Ge = ({
498
- error: e,
499
- onAnimationComplete: s
500
- }) => c(Ke, {
501
- children: e && c(ze.div, {
502
- initial: {
503
- height: 0,
504
- opacity: 0
505
- },
506
- animate: {
507
- height: "auto",
508
- opacity: 1
509
- },
510
- exit: {
511
- height: 0,
512
- opacity: 0
513
- },
514
- onAnimationComplete: s,
515
- role: "alert",
516
- class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full p-0.5 px-1 opacity-0",
517
- children: [c("svg", {
518
- class: "text-error-10",
519
- width: "16",
520
- height: "16",
521
- viewBox: "0 0 16 16",
522
- fill: "none",
523
- xmlns: "http://www.w3.org/2000/svg",
524
- children: [c("circle", {
525
- cx: "8",
526
- cy: "8",
527
- r: "6.3",
528
- stroke: "currentColor",
529
- "stroke-width": "1.4"
530
- }), c("rect", {
531
- x: "7",
532
- y: "4",
533
- width: "2",
534
- height: "5",
535
- fill: "currentColor"
536
- }), c("rect", {
537
- x: "7",
538
- y: "10",
539
- width: "2",
540
- height: "2",
541
- fill: "currentColor"
542
- })]
543
- }), c("p", {
544
- class: "truncate pr-1 text-sm",
545
- children: e.message
546
- })]
547
- })
548
- }), Ir = (e) => new Promise((s, t) => {
549
- const r = new FileReader();
550
- r.readAsDataURL(e), r.onload = () => r.result ? s(r.result.toString()) : t("No result from reader"), r.onerror = t;
551
- }), be = (e) => te(e).with(j.number.lte(1e3), () => `${Math.round(e)}KB`).with(j.number.lt(1e3 * 10), () => `${(e / 1e3).toFixed(1)}MB`).otherwise(() => `${Math.round(e / 1e3)}MB`), Tr = (e) => e.reduce((s, t) => s + t.sizeKb, 0), Nr = We("file"), ft = 3, Or = ({
552
- file: e,
553
- class: s,
554
- ...t
555
- }) => {
556
- const r = e.name.split(".").pop(), n = e.name.replace(new RegExp(`.${r}$`), "");
557
- return c("div", {
558
- class: ce("bg-accent-1 outline-neutral-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline", s),
559
- ...t,
560
- children: [c("p", {
561
- "aria-label": "File name",
562
- class: "text-accent-12 flex flex-grow overflow-hidden",
563
- children: [c("span", {
564
- class: "block truncate",
565
- children: n
566
- }), c("span", {
567
- children: [".", r]
568
- })]
569
- }), c("p", {
570
- "aria-label": "File size",
571
- class: "text-neutral-10",
572
- children: be(e.sizeKb)
573
- })]
574
- });
575
- }, ht = ({
576
- class: e,
577
- ...s
578
- }) => c("li", {
579
- class: ce("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1", e),
580
- ...s
581
- }), Lr = ({
582
- input: e,
583
- onSubmitSuccess: s,
584
- onHeightChange: t
585
- }) => {
586
- var p;
587
- const r = (p = U.current$.value.application) == null ? void 0 : p.data.submissions[e.key], [n, a] = ke(Nr(r) ? r.value : []), [o, y] = ke(), f = n.length - ft, x = Tr(n), S = Qe();
588
- return c("form", {
589
- class: "flex flex-col gap-1",
590
- onSubmit: (g) => (g.preventDefault(), y(void 0), n.length === 0 && y({
591
- type: "required",
592
- message: "Please select a file"
593
- }), e.config.fileSizeLimitKib && x > e.config.fileSizeLimitKib && y({
594
- type: "max",
595
- message: `File size exceeds limit of ${be(e.config.fileSizeLimitKib)}`
596
- }), s(n)),
597
- children: [c("div", {
598
- class: "flex items-center gap-2",
599
- children: [c("label", {
600
- ref: S,
601
- for: "dropzone-file",
602
- class: "border-neutral-8 bg-neutral-2 flex h-48 w-full cursor-pointer flex-col items-center justify-center overflow-hidden rounded-2xl border border-dashed p-4",
603
- children: [n.length > 0 ? c(Ft, {
604
- children: [c("ul", {
605
- class: "flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",
606
- children: [n.slice(0, ft).map((g) => {
607
- const V = g.name.split(".").pop(), k = g.name.replace(new RegExp(`.${V}$`), "");
608
- return c(ht, {
609
- class: "flex overflow-hidden",
610
- children: [c("span", {
611
- class: "block truncate",
612
- children: k
613
- }), c("span", {
614
- children: [".", V]
615
- })]
616
- });
617
- }), f > 0 ? c(ht, {
618
- children: ["+", f, " file", f !== 1 ? "s" : ""]
619
- }) : null]
620
- }), c("p", {
621
- class: "text-neutral-11 text-xs",
622
- children: [be(x), " ", n.length > 1 ? "total" : ""]
623
- })]
624
- }) : c("div", {
625
- class: "flex flex-col justify-center gap-4 pb-6 pt-5",
626
- children: [c("header", {
627
- class: "flex flex-col items-center gap-0",
628
- children: [c("svg", {
629
- class: "text-neutral-11 mb-1 h-8 w-8",
630
- "aria-hidden": "true",
631
- xmlns: "http://www.w3.org/2000/svg",
632
- fill: "none",
633
- viewBox: "0 0 20 16",
634
- children: c("path", {
635
- stroke: "currentColor",
636
- "stroke-linecap": "round",
637
- "stroke-linejoin": "round",
638
- "stroke-width": "1.5",
639
- d: "M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"
640
- })
641
- }), c("p", {
642
- class: "text-neutral-12 tracking-[-0.01em] dark:text-gray-400",
643
- children: [e.config.allowMultiple ? "Select files" : "Select a file", " to upload"]
644
- }), e.config.fileSizeLimitKib ? c("p", {
645
- class: "text-neutral-10 text-xs",
646
- children: ["(max ", be(e.config.fileSizeLimitKib), ")"]
647
- }) : null]
648
- }), c("aside", {
649
- class: "flex flex-col items-center gap-2",
650
- children: [c("p", {
651
- id: "accepted-filetypes",
652
- class: "sr-only",
653
- children: "Accepted file extensions"
654
- }), c("ul", {
655
- "aria-describedby": "accepted-filetypes",
656
- class: "flex flex-wrap justify-center gap-2",
657
- children: e.config.extensions.map((g) => c("li", {
658
- class: "ring-lowest outline-neutral-6 text-neutral-9 bg-neutral-1 rounded-md px-1 py-0.5 text-[11px] uppercase tracking-wide outline outline-1 ring-2",
659
- children: g.replace(".", "")
660
- }))
661
- })]
662
- })]
663
- }), c("input", {
664
- id: "dropzone-file",
665
- onInput: async (g) => {
666
- tr(g.target instanceof HTMLInputElement);
667
- const V = g.target.files ? Array.from(g.target.files) : [], k = await Promise.allSettled(V.map(async (E) => {
668
- const re = await Ir(E);
669
- return {
670
- name: E.name,
671
- data: re,
672
- sizeKb: E.size / 1e3
673
- };
674
- }));
675
- if (k.some(({
676
- status: E
677
- }) => E === "rejected"))
678
- return y({
679
- type: "invalid",
680
- message: "Invalid file"
681
- });
682
- const R = k.map((E) => E.status === "fulfilled" ? E.value : null).filter(Boolean);
683
- a(R);
684
- },
685
- multiple: e.config.allowMultiple,
686
- type: "file",
687
- class: "sr-only"
688
- })]
689
- }), c(Me, {
690
- disabled: n.length === 0
691
- })]
692
- }), o && c(Ge, {
693
- onAnimationComplete: t,
694
- error: o
695
- })]
696
- });
697
- };
698
- var pe = (e) => e.type === "checkbox", ue = (e) => e instanceof Date, L = (e) => e == null;
699
- const Tt = (e) => typeof e == "object";
700
- var T = (e) => !L(e) && !Array.isArray(e) && Tt(e) && !ue(e), Rr = (e) => T(e) && e.target ? pe(e.target) ? e.target.checked : e.target.value : e, Br = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, Pr = (e, s) => e.has(Br(s)), Ur = (e) => {
701
- const s = e.constructor && e.constructor.prototype;
702
- return T(s) && s.hasOwnProperty("isPrototypeOf");
703
- }, Je = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
704
- function Z(e) {
705
- let s;
706
- const t = Array.isArray(e);
707
- if (e instanceof Date)
708
- s = new Date(e);
709
- else if (e instanceof Set)
710
- s = new Set(e);
711
- else if (!(Je && (e instanceof Blob || e instanceof FileList)) && (t || T(e)))
712
- if (s = t ? [] : {}, !t && !Ur(e))
713
- s = e;
714
- else
715
- for (const r in e)
716
- e.hasOwnProperty(r) && (s[r] = Z(e[r]));
717
- else
718
- return e;
719
- return s;
720
- }
721
- var ge = (e) => Array.isArray(e) ? e.filter(Boolean) : [], D = (e) => e === void 0, m = (e, s, t) => {
722
- if (!s || !T(e))
723
- return t;
724
- const r = ge(s.split(/[,[\].]+?/)).reduce((n, a) => L(n) ? n : n[a], e);
725
- return D(r) || r === e ? D(e[s]) ? t : e[s] : r;
726
- }, X = (e) => typeof e == "boolean";
727
- const yt = {
728
- BLUR: "blur",
729
- FOCUS_OUT: "focusout",
730
- CHANGE: "change"
731
- }, z = {
732
- onBlur: "onBlur",
733
- onChange: "onChange",
734
- onSubmit: "onSubmit",
735
- onTouched: "onTouched",
736
- all: "all"
737
- }, Y = {
738
- max: "max",
739
- min: "min",
740
- maxLength: "maxLength",
741
- minLength: "minLength",
742
- pattern: "pattern",
743
- required: "required",
744
- validate: "validate"
745
- };
746
- W.createContext(null);
747
- var jr = (e, s, t, r = !0) => {
748
- const n = {
749
- defaultValues: s._defaultValues
750
- };
751
- for (const a in e)
752
- Object.defineProperty(n, a, {
753
- get: () => {
754
- const o = a;
755
- return s._proxyFormState[o] !== z.all && (s._proxyFormState[o] = !r || z.all), t && (t[o] = !0), e[o];
756
- }
757
- });
758
- return n;
759
- }, $ = (e) => T(e) && !Object.keys(e).length, qr = (e, s, t, r) => {
760
- t(e);
761
- const { name: n, ...a } = e;
762
- return $(a) || Object.keys(a).length >= Object.keys(s).length || Object.keys(a).find((o) => s[o] === (!r || z.all));
763
- }, Re = (e) => Array.isArray(e) ? e : [e];
764
- function $r(e) {
765
- const s = W.useRef(e);
766
- s.current = e, W.useEffect(() => {
767
- const t = !e.disabled && s.current.subject && s.current.subject.subscribe({
768
- next: s.current.next
769
- });
770
- return () => {
771
- t && t.unsubscribe();
772
- };
773
- }, [e.disabled]);
774
- }
775
- var Q = (e) => typeof e == "string", zr = (e, s, t, r, n) => Q(e) ? (r && s.watch.add(e), m(t, e, n)) : Array.isArray(e) ? e.map((a) => (r && s.watch.add(a), m(t, a))) : (r && (s.watchAll = !0), t), Ye = (e) => /^\w*$/.test(e), Nt = (e) => ge(e.replace(/["|']|\]/g, "").split(/\.|\[/));
776
- function F(e, s, t) {
777
- let r = -1;
778
- const n = Ye(s) ? [s] : Nt(s), a = n.length, o = a - 1;
779
- for (; ++r < a; ) {
780
- const y = n[r];
781
- let f = t;
782
- if (r !== o) {
783
- const x = e[y];
784
- f = T(x) || Array.isArray(x) ? x : isNaN(+n[r + 1]) ? {} : [];
785
- }
786
- e[y] = f, e = e[y];
787
- }
788
- return e;
789
- }
790
- var Ot = (e, s, t, r, n) => s ? {
791
- ...t[e],
792
- types: {
793
- ...t[e] && t[e].types ? t[e].types : {},
794
- [r]: n || !0
795
- }
796
- } : {}, pt = (e) => ({
797
- isOnSubmit: !e || e === z.onSubmit,
798
- isOnBlur: e === z.onBlur,
799
- isOnChange: e === z.onChange,
800
- isOnAll: e === z.all,
801
- isOnTouch: e === z.onTouched
802
- }), gt = (e, s, t) => !t && (s.watchAll || s.watch.has(e) || [...s.watch].some((r) => e.startsWith(r) && /^\.\w+/.test(e.slice(r.length))));
803
- const we = (e, s, t, r) => {
804
- for (const n of t || Object.keys(e)) {
805
- const a = m(e, n);
806
- if (a) {
807
- const { _f: o, ...y } = a;
808
- if (o) {
809
- if (o.refs && o.refs[0] && s(o.refs[0], n) && !r)
810
- break;
811
- if (o.ref && s(o.ref, o.name) && !r)
812
- break;
813
- } else
814
- T(y) && we(y, s);
815
- }
816
- }
817
- };
818
- var Kr = (e, s, t) => {
819
- const r = ge(m(e, t));
820
- return F(r, "root", s[t]), F(e, t, r), e;
821
- }, Ze = (e) => e.type === "file", ee = (e) => typeof e == "function", _e = (e) => {
822
- if (!Je)
823
- return !1;
824
- const s = e ? e.ownerDocument : 0;
825
- return e instanceof (s && s.defaultView ? s.defaultView.HTMLElement : HTMLElement);
826
- }, Se = (e) => Q(e), Xe = (e) => e.type === "radio", Ae = (e) => e instanceof RegExp;
827
- const mt = {
828
- value: !1,
829
- isValid: !1
830
- }, vt = { value: !0, isValid: !0 };
831
- var Lt = (e) => {
832
- if (Array.isArray(e)) {
833
- if (e.length > 1) {
834
- const s = e.filter((t) => t && t.checked && !t.disabled).map((t) => t.value);
835
- return { value: s, isValid: !!s.length };
836
- }
837
- return e[0].checked && !e[0].disabled ? (
838
- // @ts-expect-error expected to work in the browser
839
- e[0].attributes && !D(e[0].attributes.value) ? D(e[0].value) || e[0].value === "" ? vt : { value: e[0].value, isValid: !0 } : vt
840
- ) : mt;
841
- }
842
- return mt;
843
- };
844
- const xt = {
845
- isValid: !1,
846
- value: null
847
- };
848
- var Rt = (e) => Array.isArray(e) ? e.reduce((s, t) => t && t.checked && !t.disabled ? {
849
- isValid: !0,
850
- value: t.value
851
- } : s, xt) : xt;
852
- function bt(e, s, t = "validate") {
853
- if (Se(e) || Array.isArray(e) && e.every(Se) || X(e) && !e)
854
- return {
855
- type: t,
856
- message: Se(e) ? e : "",
857
- ref: s
858
- };
859
- }
860
- var oe = (e) => T(e) && !Ae(e) ? e : {
861
- value: e,
862
- message: ""
863
- }, wt = async (e, s, t, r, n) => {
864
- const { ref: a, refs: o, required: y, maxLength: f, minLength: x, min: S, max: p, pattern: g, validate: V, name: k, valueAsNumber: R, mount: E, disabled: re } = e._f, w = m(s, k);
865
- if (!E || re)
866
- return {};
867
- const B = o ? o[0] : a, G = (A) => {
868
- r && B.reportValidity && (B.setCustomValidity(X(A) ? "" : A || ""), B.reportValidity());
869
- }, N = {}, de = Xe(a), ae = pe(a), De = de || ae, K = (R || Ze(a)) && D(a.value) && D(w) || _e(a) && a.value === "" || w === "" || Array.isArray(w) && !w.length, se = Ot.bind(null, k, t, N), J = (A, _, M, P = Y.maxLength, q = Y.minLength) => {
870
- const H = A ? _ : M;
871
- N[k] = {
872
- type: A ? P : q,
873
- message: H,
874
- ref: a,
875
- ...se(A ? P : q, H)
876
- };
877
- };
878
- if (n ? !Array.isArray(w) || !w.length : y && (!De && (K || L(w)) || X(w) && !w || ae && !Lt(o).isValid || de && !Rt(o).isValid)) {
879
- const { value: A, message: _ } = Se(y) ? { value: !!y, message: y } : oe(y);
880
- if (A && (N[k] = {
881
- type: Y.required,
882
- message: _,
883
- ref: B,
884
- ...se(Y.required, _)
885
- }, !t))
886
- return G(_), N;
887
- }
888
- if (!K && (!L(S) || !L(p))) {
889
- let A, _;
890
- const M = oe(p), P = oe(S);
891
- if (!L(w) && !isNaN(w)) {
892
- const q = a.valueAsNumber || w && +w;
893
- L(M.value) || (A = q > M.value), L(P.value) || (_ = q < P.value);
894
- } else {
895
- const q = a.valueAsDate || new Date(w), H = (me) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + me), ie = a.type == "time", fe = a.type == "week";
896
- Q(M.value) && w && (A = ie ? H(w) > H(M.value) : fe ? w > M.value : q > new Date(M.value)), Q(P.value) && w && (_ = ie ? H(w) < H(P.value) : fe ? w < P.value : q < new Date(P.value));
897
- }
898
- if ((A || _) && (J(!!A, M.message, P.message, Y.max, Y.min), !t))
899
- return G(N[k].message), N;
900
- }
901
- if ((f || x) && !K && (Q(w) || n && Array.isArray(w))) {
902
- const A = oe(f), _ = oe(x), M = !L(A.value) && w.length > +A.value, P = !L(_.value) && w.length < +_.value;
903
- if ((M || P) && (J(M, A.message, _.message), !t))
904
- return G(N[k].message), N;
905
- }
906
- if (g && !K && Q(w)) {
907
- const { value: A, message: _ } = oe(g);
908
- if (Ae(A) && !w.match(A) && (N[k] = {
909
- type: Y.pattern,
910
- message: _,
911
- ref: a,
912
- ...se(Y.pattern, _)
913
- }, !t))
914
- return G(_), N;
915
- }
916
- if (V) {
917
- if (ee(V)) {
918
- const A = await V(w, s), _ = bt(A, B);
919
- if (_ && (N[k] = {
920
- ..._,
921
- ...se(Y.validate, _.message)
922
- }, !t))
923
- return G(_.message), N;
924
- } else if (T(V)) {
925
- let A = {};
926
- for (const _ in V) {
927
- if (!$(A) && !t)
928
- break;
929
- const M = bt(await V[_](w, s), B, _);
930
- M && (A = {
931
- ...M,
932
- ...se(_, M.message)
933
- }, G(M.message), t && (N[k] = A));
934
- }
935
- if (!$(A) && (N[k] = {
936
- ref: B,
937
- ...A
938
- }, !t))
939
- return N;
940
- }
941
- }
942
- return G(!0), N;
943
- };
944
- function Hr(e, s) {
945
- const t = s.slice(0, -1).length;
946
- let r = 0;
947
- for (; r < t; )
948
- e = D(e) ? r++ : e[s[r++]];
949
- return e;
950
- }
951
- function Wr(e) {
952
- for (const s in e)
953
- if (e.hasOwnProperty(s) && !D(e[s]))
954
- return !1;
955
- return !0;
956
- }
957
- function O(e, s) {
958
- const t = Array.isArray(s) ? s : Ye(s) ? [s] : Nt(s), r = t.length === 1 ? e : Hr(e, t), n = t.length - 1, a = t[n];
959
- return r && delete r[a], n !== 0 && (T(r) && $(r) || Array.isArray(r) && Wr(r)) && O(e, t.slice(0, -1)), e;
960
- }
961
- function Be() {
962
- let e = [];
963
- return {
964
- get observers() {
965
- return e;
966
- },
967
- next: (n) => {
968
- for (const a of e)
969
- a.next && a.next(n);
970
- },
971
- subscribe: (n) => (e.push(n), {
972
- unsubscribe: () => {
973
- e = e.filter((a) => a !== n);
974
- }
975
- }),
976
- unsubscribe: () => {
977
- e = [];
978
- }
979
- };
980
- }
981
- var Ve = (e) => L(e) || !Tt(e);
982
- function ne(e, s) {
983
- if (Ve(e) || Ve(s))
984
- return e === s;
985
- if (ue(e) && ue(s))
986
- return e.getTime() === s.getTime();
987
- const t = Object.keys(e), r = Object.keys(s);
988
- if (t.length !== r.length)
989
- return !1;
990
- for (const n of t) {
991
- const a = e[n];
992
- if (!r.includes(n))
993
- return !1;
994
- if (n !== "ref") {
995
- const o = s[n];
996
- if (ue(a) && ue(o) || T(a) && T(o) || Array.isArray(a) && Array.isArray(o) ? !ne(a, o) : a !== o)
997
- return !1;
998
- }
999
- }
1000
- return !0;
1001
- }
1002
- var Bt = (e) => e.type === "select-multiple", Qr = (e) => Xe(e) || pe(e), Pe = (e) => _e(e) && e.isConnected, Pt = (e) => {
1003
- for (const s in e)
1004
- if (ee(e[s]))
1005
- return !0;
1006
- return !1;
1007
- };
1008
- function Fe(e, s = {}) {
1009
- const t = Array.isArray(e);
1010
- if (T(e) || t)
1011
- for (const r in e)
1012
- Array.isArray(e[r]) || T(e[r]) && !Pt(e[r]) ? (s[r] = Array.isArray(e[r]) ? [] : {}, Fe(e[r], s[r])) : L(e[r]) || (s[r] = !0);
1013
- return s;
1014
- }
1015
- function Ut(e, s, t) {
1016
- const r = Array.isArray(e);
1017
- if (T(e) || r)
1018
- for (const n in e)
1019
- Array.isArray(e[n]) || T(e[n]) && !Pt(e[n]) ? D(s) || Ve(t[n]) ? t[n] = Array.isArray(e[n]) ? Fe(e[n], []) : { ...Fe(e[n]) } : Ut(e[n], L(s) ? {} : s[n], t[n]) : t[n] = !ne(e[n], s[n]);
1020
- return t;
1021
- }
1022
- var Ue = (e, s) => Ut(e, s, Fe(s)), jt = (e, { valueAsNumber: s, valueAsDate: t, setValueAs: r }) => D(e) ? e : s ? e === "" ? NaN : e && +e : t && Q(e) ? new Date(e) : r ? r(e) : e;
1023
- function je(e) {
1024
- const s = e.ref;
1025
- if (!(e.refs ? e.refs.every((t) => t.disabled) : s.disabled))
1026
- return Ze(s) ? s.files : Xe(s) ? Rt(e.refs).value : Bt(s) ? [...s.selectedOptions].map(({ value: t }) => t) : pe(s) ? Lt(e.refs).value : jt(D(s.value) ? e.ref.value : s.value, e);
1027
- }
1028
- var Gr = (e, s, t, r) => {
1029
- const n = {};
1030
- for (const a of e) {
1031
- const o = m(s, a);
1032
- o && F(n, a, o._f);
1033
- }
1034
- return {
1035
- criteriaMode: t,
1036
- names: [...e],
1037
- fields: n,
1038
- shouldUseNativeValidation: r
1039
- };
1040
- }, he = (e) => D(e) ? e : Ae(e) ? e.source : T(e) ? Ae(e.value) ? e.value.source : e.value : e, Jr = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate);
1041
- function St(e, s, t) {
1042
- const r = m(e, t);
1043
- if (r || Ye(t))
1044
- return {
1045
- error: r,
1046
- name: t
1047
- };
1048
- const n = t.split(".");
1049
- for (; n.length; ) {
1050
- const a = n.join("."), o = m(s, a), y = m(e, a);
1051
- if (o && !Array.isArray(o) && t !== a)
1052
- return { name: t };
1053
- if (y && y.type)
1054
- return {
1055
- name: a,
1056
- error: y
1057
- };
1058
- n.pop();
1059
- }
1060
- return {
1061
- name: t
1062
- };
1063
- }
1064
- var Yr = (e, s, t, r, n) => n.isOnAll ? !1 : !t && n.isOnTouch ? !(s || e) : (t ? r.isOnBlur : n.isOnBlur) ? !e : (t ? r.isOnChange : n.isOnChange) ? e : !0, Zr = (e, s) => !ge(m(e, s)).length && O(e, s);
1065
- const Xr = {
1066
- mode: z.onSubmit,
1067
- reValidateMode: z.onChange,
1068
- shouldFocusError: !0
1069
- };
1070
- function es(e = {}, s) {
1071
- let t = {
1072
- ...Xr,
1073
- ...e
1074
- }, r = {
1075
- submitCount: 0,
1076
- isDirty: !1,
1077
- isLoading: ee(t.defaultValues),
1078
- isValidating: !1,
1079
- isSubmitted: !1,
1080
- isSubmitting: !1,
1081
- isSubmitSuccessful: !1,
1082
- isValid: !1,
1083
- touchedFields: {},
1084
- dirtyFields: {},
1085
- errors: {},
1086
- disabled: !1
1087
- }, n = {}, a = T(t.defaultValues) || T(t.values) ? Z(t.defaultValues || t.values) || {} : {}, o = t.shouldUnregister ? {} : Z(a), y = {
1088
- action: !1,
1089
- mount: !1,
1090
- watch: !1
1091
- }, f = {
1092
- mount: /* @__PURE__ */ new Set(),
1093
- unMount: /* @__PURE__ */ new Set(),
1094
- array: /* @__PURE__ */ new Set(),
1095
- watch: /* @__PURE__ */ new Set()
1096
- }, x, S = 0;
1097
- const p = {
1098
- isDirty: !1,
1099
- dirtyFields: !1,
1100
- touchedFields: !1,
1101
- isValidating: !1,
1102
- isValid: !1,
1103
- errors: !1
1104
- }, g = {
1105
- values: Be(),
1106
- array: Be(),
1107
- state: Be()
1108
- }, V = e.resetOptions && e.resetOptions.keepDirtyValues, k = pt(t.mode), R = pt(t.reValidateMode), E = t.criteriaMode === z.all, re = (i) => (l) => {
1109
- clearTimeout(S), S = setTimeout(i, l);
1110
- }, w = async (i) => {
1111
- if (p.isValid || i) {
1112
- const l = t.resolver ? $((await K()).errors) : await J(n, !0);
1113
- l !== r.isValid && g.state.next({
1114
- isValid: l
1115
- });
1116
- }
1117
- }, B = (i) => p.isValidating && g.state.next({
1118
- isValidating: i
1119
- }), G = (i, l = [], u, v, h = !0, d = !0) => {
1120
- if (v && u) {
1121
- if (y.action = !0, d && Array.isArray(m(n, i))) {
1122
- const b = u(m(n, i), v.argA, v.argB);
1123
- h && F(n, i, b);
1124
- }
1125
- if (d && Array.isArray(m(r.errors, i))) {
1126
- const b = u(m(r.errors, i), v.argA, v.argB);
1127
- h && F(r.errors, i, b), Zr(r.errors, i);
1128
- }
1129
- if (p.touchedFields && d && Array.isArray(m(r.touchedFields, i))) {
1130
- const b = u(m(r.touchedFields, i), v.argA, v.argB);
1131
- h && F(r.touchedFields, i, b);
1132
- }
1133
- p.dirtyFields && (r.dirtyFields = Ue(a, o)), g.state.next({
1134
- name: i,
1135
- isDirty: _(i, l),
1136
- dirtyFields: r.dirtyFields,
1137
- errors: r.errors,
1138
- isValid: r.isValid
1139
- });
1140
- } else
1141
- F(o, i, l);
1142
- }, N = (i, l) => {
1143
- F(r.errors, i, l), g.state.next({
1144
- errors: r.errors
1145
- });
1146
- }, de = (i, l, u, v) => {
1147
- const h = m(n, i);
1148
- if (h) {
1149
- const d = m(o, i, D(u) ? m(a, i) : u);
1150
- D(d) || v && v.defaultChecked || l ? F(o, i, l ? d : je(h._f)) : q(i, d), y.mount && w();
1151
- }
1152
- }, ae = (i, l, u, v, h) => {
1153
- let d = !1, b = !1;
1154
- const C = {
1155
- name: i
1156
- };
1157
- if (!u || v) {
1158
- p.isDirty && (b = r.isDirty, r.isDirty = C.isDirty = _(), d = b !== C.isDirty);
1159
- const I = ne(m(a, i), l);
1160
- b = m(r.dirtyFields, i), I ? O(r.dirtyFields, i) : F(r.dirtyFields, i, !0), C.dirtyFields = r.dirtyFields, d = d || p.dirtyFields && b !== !I;
1161
- }
1162
- if (u) {
1163
- const I = m(r.touchedFields, i);
1164
- I || (F(r.touchedFields, i, u), C.touchedFields = r.touchedFields, d = d || p.touchedFields && I !== u);
1165
- }
1166
- return d && h && g.state.next(C), d ? C : {};
1167
- }, De = (i, l, u, v) => {
1168
- const h = m(r.errors, i), d = p.isValid && X(l) && r.isValid !== l;
1169
- if (e.delayError && u ? (x = re(() => N(i, u)), x(e.delayError)) : (clearTimeout(S), x = null, u ? F(r.errors, i, u) : O(r.errors, i)), (u ? !ne(h, u) : h) || !$(v) || d) {
1170
- const b = {
1171
- ...v,
1172
- ...d && X(l) ? { isValid: l } : {},
1173
- errors: r.errors,
1174
- name: i
1175
- };
1176
- r = {
1177
- ...r,
1178
- ...b
1179
- }, g.state.next(b);
1180
- }
1181
- B(!1);
1182
- }, K = async (i) => t.resolver(o, t.context, Gr(i || f.mount, n, t.criteriaMode, t.shouldUseNativeValidation)), se = async (i) => {
1183
- const { errors: l } = await K(i);
1184
- if (i)
1185
- for (const u of i) {
1186
- const v = m(l, u);
1187
- v ? F(r.errors, u, v) : O(r.errors, u);
1188
- }
1189
- else
1190
- r.errors = l;
1191
- return l;
1192
- }, J = async (i, l, u = {
1193
- valid: !0
1194
- }) => {
1195
- for (const v in i) {
1196
- const h = i[v];
1197
- if (h) {
1198
- const { _f: d, ...b } = h;
1199
- if (d) {
1200
- const C = f.array.has(d.name), I = await wt(h, o, E, t.shouldUseNativeValidation && !l, C);
1201
- if (I[d.name] && (u.valid = !1, l))
1202
- break;
1203
- !l && (m(I, d.name) ? C ? Kr(r.errors, I, d.name) : F(r.errors, d.name, I[d.name]) : O(r.errors, d.name));
1204
- }
1205
- b && await J(b, l, u);
1206
- }
1207
- }
1208
- return u.valid;
1209
- }, A = () => {
1210
- for (const i of f.unMount) {
1211
- const l = m(n, i);
1212
- l && (l._f.refs ? l._f.refs.every((u) => !Pe(u)) : !Pe(l._f.ref)) && Te(i);
1213
- }
1214
- f.unMount = /* @__PURE__ */ new Set();
1215
- }, _ = (i, l) => (i && l && F(o, i, l), !ne(et(), a)), M = (i, l, u) => zr(i, f, {
1216
- ...y.mount ? o : D(l) ? a : Q(i) ? { [i]: l } : l
1217
- }, u, l), P = (i) => ge(m(y.mount ? o : a, i, e.shouldUnregister ? m(a, i, []) : [])), q = (i, l, u = {}) => {
1218
- const v = m(n, i);
1219
- let h = l;
1220
- if (v) {
1221
- const d = v._f;
1222
- d && (!d.disabled && F(o, i, jt(l, d)), h = _e(d.ref) && L(l) ? "" : l, Bt(d.ref) ? [...d.ref.options].forEach((b) => b.selected = h.includes(b.value)) : d.refs ? pe(d.ref) ? d.refs.length > 1 ? d.refs.forEach((b) => (!b.defaultChecked || !b.disabled) && (b.checked = Array.isArray(h) ? !!h.find((C) => C === b.value) : h === b.value)) : d.refs[0] && (d.refs[0].checked = !!h) : d.refs.forEach((b) => b.checked = b.value === h) : Ze(d.ref) ? d.ref.value = "" : (d.ref.value = h, d.ref.type || g.values.next({
1223
- name: i,
1224
- values: { ...o }
1225
- })));
1226
- }
1227
- (u.shouldDirty || u.shouldTouch) && ae(i, h, u.shouldTouch, u.shouldDirty, !0), u.shouldValidate && Ie(i);
1228
- }, H = (i, l, u) => {
1229
- for (const v in l) {
1230
- const h = l[v], d = `${i}.${v}`, b = m(n, d);
1231
- (f.array.has(i) || !Ve(h) || b && !b._f) && !ue(h) ? H(d, h, u) : q(d, h, u);
1232
- }
1233
- }, ie = (i, l, u = {}) => {
1234
- const v = m(n, i), h = f.array.has(i), d = Z(l);
1235
- F(o, i, d), h ? (g.array.next({
1236
- name: i,
1237
- values: { ...o }
1238
- }), (p.isDirty || p.dirtyFields) && u.shouldDirty && g.state.next({
1239
- name: i,
1240
- dirtyFields: Ue(a, o),
1241
- isDirty: _(i, d)
1242
- })) : v && !v._f && !L(d) ? H(i, d, u) : q(i, d, u), gt(i, f) && g.state.next({ ...r }), g.values.next({
1243
- name: i,
1244
- values: { ...o }
1245
- }), !y.mount && s();
1246
- }, fe = async (i) => {
1247
- const l = i.target;
1248
- let u = l.name, v = !0;
1249
- const h = m(n, u), d = () => l.type ? je(h._f) : Rr(i), b = (C) => {
1250
- v = Number.isNaN(C) || C === m(o, u, C);
1251
- };
1252
- if (h) {
1253
- let C, I;
1254
- const ve = d(), le = i.type === yt.BLUR || i.type === yt.FOCUS_OUT, Gt = !Jr(h._f) && !t.resolver && !m(r.errors, u) && !h._f.deps || Yr(le, m(r.touchedFields, u), r.isSubmitted, R, k), Oe = gt(u, f, le);
1255
- F(o, u, ve), le ? (h._f.onBlur && h._f.onBlur(i), x && x(0)) : h._f.onChange && h._f.onChange(i);
1256
- const Le = ae(u, ve, le, !1), Jt = !$(Le) || Oe;
1257
- if (!le && g.values.next({
1258
- name: u,
1259
- type: i.type,
1260
- values: { ...o }
1261
- }), Gt)
1262
- return p.isValid && w(), Jt && g.state.next({ name: u, ...Oe ? {} : Le });
1263
- if (!le && Oe && g.state.next({ ...r }), B(!0), t.resolver) {
1264
- const { errors: ot } = await K([u]);
1265
- if (b(ve), v) {
1266
- const Yt = St(r.errors, n, u), ut = St(ot, n, Yt.name || u);
1267
- C = ut.error, u = ut.name, I = $(ot);
1268
- }
1269
- } else
1270
- C = (await wt(h, o, E, t.shouldUseNativeValidation))[u], b(ve), v && (C ? I = !1 : p.isValid && (I = await J(n, !0)));
1271
- v && (h._f.deps && Ie(h._f.deps), De(u, I, C, Le));
1272
- }
1273
- }, me = (i, l) => {
1274
- if (m(r.errors, l) && i.focus)
1275
- return i.focus(), 1;
1276
- }, Ie = async (i, l = {}) => {
1277
- let u, v;
1278
- const h = Re(i);
1279
- if (B(!0), t.resolver) {
1280
- const d = await se(D(i) ? i : h);
1281
- u = $(d), v = i ? !h.some((b) => m(d, b)) : u;
1282
- } else
1283
- i ? (v = (await Promise.all(h.map(async (d) => {
1284
- const b = m(n, d);
1285
- return await J(b && b._f ? { [d]: b } : b);
1286
- }))).every(Boolean), !(!v && !r.isValid) && w()) : v = u = await J(n);
1287
- return g.state.next({
1288
- ...!Q(i) || p.isValid && u !== r.isValid ? {} : { name: i },
1289
- ...t.resolver || !i ? { isValid: u } : {},
1290
- errors: r.errors,
1291
- isValidating: !1
1292
- }), l.shouldFocus && !v && we(n, me, i ? h : f.mount), v;
1293
- }, et = (i) => {
1294
- const l = {
1295
- ...a,
1296
- ...y.mount ? o : {}
1297
- };
1298
- return D(i) ? l : Q(i) ? m(l, i) : i.map((u) => m(l, u));
1299
- }, tt = (i, l) => ({
1300
- invalid: !!m((l || r).errors, i),
1301
- isDirty: !!m((l || r).dirtyFields, i),
1302
- isTouched: !!m((l || r).touchedFields, i),
1303
- error: m((l || r).errors, i)
1304
- }), Kt = (i) => {
1305
- i && Re(i).forEach((l) => O(r.errors, l)), g.state.next({
1306
- errors: i ? r.errors : {}
1307
- });
1308
- }, rt = (i, l, u) => {
1309
- const v = (m(n, i, { _f: {} })._f || {}).ref;
1310
- F(r.errors, i, {
1311
- ...l,
1312
- ref: v
1313
- }), g.state.next({
1314
- name: i,
1315
- errors: r.errors,
1316
- isValid: !1
1317
- }), u && u.shouldFocus && v && v.focus && v.focus();
1318
- }, Ht = (i, l) => ee(i) ? g.values.subscribe({
1319
- next: (u) => i(M(void 0, l), u)
1320
- }) : M(i, l, !0), Te = (i, l = {}) => {
1321
- for (const u of i ? Re(i) : f.mount)
1322
- f.mount.delete(u), f.array.delete(u), l.keepValue || (O(n, u), O(o, u)), !l.keepError && O(r.errors, u), !l.keepDirty && O(r.dirtyFields, u), !l.keepTouched && O(r.touchedFields, u), !t.shouldUnregister && !l.keepDefaultValue && O(a, u);
1323
- g.values.next({
1324
- values: { ...o }
1325
- }), g.state.next({
1326
- ...r,
1327
- ...l.keepDirty ? { isDirty: _() } : {}
1328
- }), !l.keepIsValid && w();
1329
- }, st = ({ disabled: i, name: l, field: u, fields: v, value: h }) => {
1330
- if (X(i)) {
1331
- const d = i ? void 0 : D(h) ? je(u ? u._f : m(v, l)._f) : h;
1332
- F(o, l, d), ae(l, d, !1, !1, !0);
1333
- }
1334
- }, Ne = (i, l = {}) => {
1335
- let u = m(n, i);
1336
- const v = X(l.disabled);
1337
- return F(n, i, {
1338
- ...u || {},
1339
- _f: {
1340
- ...u && u._f ? u._f : { ref: { name: i } },
1341
- name: i,
1342
- mount: !0,
1343
- ...l
1344
- }
1345
- }), f.mount.add(i), u ? st({
1346
- field: u,
1347
- disabled: l.disabled,
1348
- name: i
1349
- }) : de(i, !0, l.value), {
1350
- ...v ? { disabled: l.disabled } : {},
1351
- ...t.progressive ? {
1352
- required: !!l.required,
1353
- min: he(l.min),
1354
- max: he(l.max),
1355
- minLength: he(l.minLength),
1356
- maxLength: he(l.maxLength),
1357
- pattern: he(l.pattern)
1358
- } : {},
1359
- name: i,
1360
- onChange: fe,
1361
- onBlur: fe,
1362
- ref: (h) => {
1363
- if (h) {
1364
- Ne(i, l), u = m(n, i);
1365
- const d = D(h.value) && h.querySelectorAll && h.querySelectorAll("input,select,textarea")[0] || h, b = Qr(d), C = u._f.refs || [];
1366
- if (b ? C.find((I) => I === d) : d === u._f.ref)
1367
- return;
1368
- F(n, i, {
1369
- _f: {
1370
- ...u._f,
1371
- ...b ? {
1372
- refs: [
1373
- ...C.filter(Pe),
1374
- d,
1375
- ...Array.isArray(m(a, i)) ? [{}] : []
1376
- ],
1377
- ref: { type: d.type, name: i }
1378
- } : { ref: d }
1379
- }
1380
- }), de(i, !1, void 0, d);
1381
- } else
1382
- u = m(n, i, {}), u._f && (u._f.mount = !1), (t.shouldUnregister || l.shouldUnregister) && !(Pr(f.array, i) && y.action) && f.unMount.add(i);
1383
- }
1384
- };
1385
- }, it = () => t.shouldFocusError && we(n, me, f.mount), Wt = (i) => {
1386
- X(i) && (g.state.next({ disabled: i }), we(n, (l) => {
1387
- l.disabled = i;
1388
- }, 0, !1));
1389
- }, nt = (i, l) => async (u) => {
1390
- u && (u.preventDefault && u.preventDefault(), u.persist && u.persist());
1391
- let v = Z(o);
1392
- if (g.state.next({
1393
- isSubmitting: !0
1394
- }), t.resolver) {
1395
- const { errors: h, values: d } = await K();
1396
- r.errors = h, v = d;
1397
- } else
1398
- await J(n);
1399
- O(r.errors, "root"), $(r.errors) ? (g.state.next({
1400
- errors: {}
1401
- }), await i(v, u)) : (l && await l({ ...r.errors }, u), it(), setTimeout(it)), g.state.next({
1402
- isSubmitted: !0,
1403
- isSubmitting: !1,
1404
- isSubmitSuccessful: $(r.errors),
1405
- submitCount: r.submitCount + 1,
1406
- errors: r.errors
1407
- });
1408
- }, Qt = (i, l = {}) => {
1409
- m(n, i) && (D(l.defaultValue) ? ie(i, m(a, i)) : (ie(i, l.defaultValue), F(a, i, l.defaultValue)), l.keepTouched || O(r.touchedFields, i), l.keepDirty || (O(r.dirtyFields, i), r.isDirty = l.defaultValue ? _(i, m(a, i)) : _()), l.keepError || (O(r.errors, i), p.isValid && w()), g.state.next({ ...r }));
1410
- }, at = (i, l = {}) => {
1411
- const u = i ? Z(i) : a, v = Z(u), h = i && !$(i) ? v : a;
1412
- if (l.keepDefaultValues || (a = u), !l.keepValues) {
1413
- if (l.keepDirtyValues || V)
1414
- for (const d of f.mount)
1415
- m(r.dirtyFields, d) ? F(h, d, m(o, d)) : ie(d, m(h, d));
1416
- else {
1417
- if (Je && D(i))
1418
- for (const d of f.mount) {
1419
- const b = m(n, d);
1420
- if (b && b._f) {
1421
- const C = Array.isArray(b._f.refs) ? b._f.refs[0] : b._f.ref;
1422
- if (_e(C)) {
1423
- const I = C.closest("form");
1424
- if (I) {
1425
- I.reset();
1426
- break;
1427
- }
1428
- }
1429
- }
1430
- }
1431
- n = {};
1432
- }
1433
- o = e.shouldUnregister ? l.keepDefaultValues ? Z(a) : {} : Z(h), g.array.next({
1434
- values: { ...h }
1435
- }), g.values.next({
1436
- values: { ...h }
1437
- });
1438
- }
1439
- f = {
1440
- mount: /* @__PURE__ */ new Set(),
1441
- unMount: /* @__PURE__ */ new Set(),
1442
- array: /* @__PURE__ */ new Set(),
1443
- watch: /* @__PURE__ */ new Set(),
1444
- watchAll: !1,
1445
- focus: ""
1446
- }, !y.mount && s(), y.mount = !p.isValid || !!l.keepIsValid, y.watch = !!e.shouldUnregister, g.state.next({
1447
- submitCount: l.keepSubmitCount ? r.submitCount : 0,
1448
- isDirty: l.keepDirty ? r.isDirty : !!(l.keepDefaultValues && !ne(i, a)),
1449
- isSubmitted: l.keepIsSubmitted ? r.isSubmitted : !1,
1450
- dirtyFields: l.keepDirtyValues ? r.dirtyFields : l.keepDefaultValues && i ? Ue(a, i) : {},
1451
- touchedFields: l.keepTouched ? r.touchedFields : {},
1452
- errors: l.keepErrors ? r.errors : {},
1453
- isSubmitSuccessful: l.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
1454
- isSubmitting: !1
1455
- });
1456
- }, lt = (i, l) => at(ee(i) ? i(o) : i, l);
1457
- return {
1458
- control: {
1459
- register: Ne,
1460
- unregister: Te,
1461
- getFieldState: tt,
1462
- handleSubmit: nt,
1463
- setError: rt,
1464
- _executeSchema: K,
1465
- _getWatch: M,
1466
- _getDirty: _,
1467
- _updateValid: w,
1468
- _removeUnmounted: A,
1469
- _updateFieldArray: G,
1470
- _updateDisabledField: st,
1471
- _getFieldArray: P,
1472
- _reset: at,
1473
- _resetDefaultValues: () => ee(t.defaultValues) && t.defaultValues().then((i) => {
1474
- lt(i, t.resetOptions), g.state.next({
1475
- isLoading: !1
1476
- });
1477
- }),
1478
- _updateFormState: (i) => {
1479
- r = {
1480
- ...r,
1481
- ...i
1482
- };
1483
- },
1484
- _disableForm: Wt,
1485
- _subjects: g,
1486
- _proxyFormState: p,
1487
- get _fields() {
1488
- return n;
1489
- },
1490
- get _formValues() {
1491
- return o;
1492
- },
1493
- get _state() {
1494
- return y;
1495
- },
1496
- set _state(i) {
1497
- y = i;
1498
- },
1499
- get _defaultValues() {
1500
- return a;
1501
- },
1502
- get _names() {
1503
- return f;
1504
- },
1505
- set _names(i) {
1506
- f = i;
1507
- },
1508
- get _formState() {
1509
- return r;
1510
- },
1511
- set _formState(i) {
1512
- r = i;
1513
- },
1514
- get _options() {
1515
- return t;
1516
- },
1517
- set _options(i) {
1518
- t = {
1519
- ...t,
1520
- ...i
1521
- };
1522
- }
1523
- },
1524
- trigger: Ie,
1525
- register: Ne,
1526
- handleSubmit: nt,
1527
- watch: Ht,
1528
- setValue: ie,
1529
- getValues: et,
1530
- reset: lt,
1531
- resetField: Qt,
1532
- clearErrors: Kt,
1533
- unregister: Te,
1534
- setError: rt,
1535
- setFocus: (i, l = {}) => {
1536
- const u = m(n, i), v = u && u._f;
1537
- if (v) {
1538
- const h = v.refs ? v.refs[0] : v.ref;
1539
- h.focus && (h.focus(), l.shouldSelect && h.select());
1540
- }
1541
- },
1542
- getFieldState: tt
1543
- };
1544
- }
1545
- function qt(e = {}) {
1546
- const s = W.useRef(), t = W.useRef(), [r, n] = W.useState({
1547
- isDirty: !1,
1548
- isValidating: !1,
1549
- isLoading: ee(e.defaultValues),
1550
- isSubmitted: !1,
1551
- isSubmitting: !1,
1552
- isSubmitSuccessful: !1,
1553
- isValid: !1,
1554
- submitCount: 0,
1555
- dirtyFields: {},
1556
- touchedFields: {},
1557
- errors: {},
1558
- disabled: !1,
1559
- defaultValues: ee(e.defaultValues) ? void 0 : e.defaultValues
1560
- });
1561
- s.current || (s.current = {
1562
- ...es(e, () => n((o) => ({ ...o }))),
1563
- formState: r
1564
- });
1565
- const a = s.current.control;
1566
- return a._options = e, $r({
1567
- subject: a._subjects.state,
1568
- next: (o) => {
1569
- qr(o, a._proxyFormState, a._updateFormState, !0) && n({ ...a._formState });
1570
- }
1571
- }), W.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), W.useEffect(() => {
1572
- if (a._proxyFormState.isDirty) {
1573
- const o = a._getDirty();
1574
- o !== r.isDirty && a._subjects.state.next({
1575
- isDirty: o
1576
- });
1577
- }
1578
- }, [a, r.isDirty]), W.useEffect(() => {
1579
- e.values && !ne(e.values, t.current) ? (a._reset(e.values, a._options.resetOptions), t.current = e.values) : a._resetDefaultValues();
1580
- }, [e.values, a]), W.useEffect(() => {
1581
- a._state.mount || (a._updateValid(), a._state.mount = !0), a._state.watch && (a._state.watch = !1, a._subjects.state.next({ ...a._formState })), a._removeUnmounted();
1582
- }), s.current.formState = jr(r, a), s.current;
1583
- }
1584
- var kt = function(e, s, t) {
1585
- if (e && "reportValidity" in e) {
1586
- var r = m(t, s);
1587
- e.setCustomValidity(r && r.message || ""), e.reportValidity();
1588
- }
1589
- }, ts = function(e, s) {
1590
- var t = function(n) {
1591
- var a = s.fields[n];
1592
- a && a.ref && "reportValidity" in a.ref ? kt(a.ref, n, e) : a.refs && a.refs.forEach(function(o) {
1593
- return kt(o, n, e);
1594
- });
1595
- };
1596
- for (var r in s.fields)
1597
- t(r);
1598
- }, rs = function(e, s) {
1599
- s.shouldUseNativeValidation && ts(e, s);
1600
- var t = {};
1601
- for (var r in e) {
1602
- var n = m(s.fields, r), a = Object.assign(e[r] || {}, { ref: n && n.ref });
1603
- if (is(s.names || Object.keys(e), r)) {
1604
- var o = Object.assign({}, ss(m(t, r)));
1605
- F(o, "root", a), F(t, r, o);
1606
- } else
1607
- F(t, r, a);
1608
- }
1609
- return t;
1610
- }, ss = function(e) {
1611
- return Array.isArray(e) ? e.filter(Boolean) : [];
1612
- }, is = function(e, s) {
1613
- return e.some(function(t) {
1614
- return t.startsWith(s + ".");
1615
- });
1616
- }, ns = function(e, s) {
1617
- for (var t = {}; e.issues.length; ) {
1618
- var r = e.issues[0];
1619
- if (r.path) {
1620
- var n = r.path.map(function(y) {
1621
- return y.key;
1622
- }).join(".");
1623
- if (t[n] || (t[n] = { message: r.message, type: r.validation }), s) {
1624
- var a = t[n].types, o = a && a[r.validation];
1625
- t[n] = Ot(n, s, t, r.validation, o ? [].concat(o, r.message) : r.message);
1626
- }
1627
- e.issues.shift();
1628
- }
1629
- }
1630
- return t;
1631
- }, $t = function(e, s, t) {
1632
- return t === void 0 && (t = {}), function(r, n, a) {
1633
- try {
1634
- return Promise.resolve(function(o, y) {
1635
- try {
1636
- var f = function() {
1637
- function x(p) {
1638
- return { values: t.raw ? r : p, errors: {} };
1639
- }
1640
- var S = Object.assign({}, { abortEarly: !1, abortPipeEarly: !1 }, s);
1641
- return t.mode === "sync" ? x(Vt(e, r, S)) : Promise.resolve(rr(e, r, S)).then(x);
1642
- }();
1643
- } catch (x) {
1644
- return y(x);
1645
- }
1646
- return f && f.then ? f.then(void 0, y) : f;
1647
- }(0, function(o) {
1648
- if (o instanceof sr)
1649
- return { values: {}, errors: rs(ns(o, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a) };
1650
- throw o;
1651
- }));
1652
- } catch (o) {
1653
- return Promise.reject(o);
1654
- }
1655
- };
1656
- };
1657
- const as = (e) => {
1658
- const s = Object.fromEntries(new FormData(e).entries());
1659
- Object.keys(s).length && e.dispatchEvent(new Event("submit", {
1660
- bubbles: !0
1661
- }));
1662
- }, ls = We("multiple-choice"), os = (e) => {
1663
- const s = {
1664
- min: e.minSelected ?? 0,
1665
- max: e.maxSelected ?? e.options.length
1666
- };
1667
- return $t(Ct({
1668
- checked: Et(nr(ar()), (t) => Object.entries(t).filter(([r, n]) => n).map(([r, n]) => r), [ir(s.max, `Please select at most ${s.max} option${s.max !== 1 ? "s" : ""}`), Mt(s.min, `Please select at least ${s.min} option${s.min !== 1 ? "s" : ""}`)])
1669
- }));
1670
- }, us = ({
1671
- input: e,
1672
- onSubmitSuccess: s,
1673
- onHeightChange: t
1674
- }) => {
1675
- var x, S;
1676
- const r = e.key ? (x = U.current$.value.application) == null ? void 0 : x.data.submissions[e.key] : void 0, {
1677
- register: n,
1678
- handleSubmit: a,
1679
- formState: {
1680
- errors: o
1681
- }
1682
- } = qt({
1683
- defaultValues: {
1684
- checked: ls(r) ? Object.fromEntries(r.value.map((p) => [p, !0])) : {}
1685
- },
1686
- resolver: os(e.config)
1687
- }), y = Qe(), f = e.config.minSelected === 1 && e.config.maxSelected === 1;
1688
- return c("form", {
1689
- noValidate: !0,
1690
- class: "flex flex-col gap-1",
1691
- onChange: (p) => {
1692
- f && as(p.currentTarget);
1693
- },
1694
- onSubmit: a((p) => {
1695
- const g = p.checked;
1696
- s(g);
1697
- }),
1698
- children: [c("div", {
1699
- class: "flex items-center gap-2",
1700
- children: [c("div", {
1701
- class: ce("flex w-full flex-1 flex-wrap gap-3 p-1", {
1702
- "justify-center": e.config.options.length === 1
1703
- }),
1704
- children: e.config.options.map((p, g) => {
1705
- const V = `checked.${p.value}`, {
1706
- ref: k,
1707
- ...R
1708
- } = n(V);
1709
- return c("div", {
1710
- children: [c("input", {
1711
- autoFocus: g === 0,
1712
- ref: (E) => {
1713
- E && g === 0 && (y.current = E), k(E);
1714
- },
1715
- id: V,
1716
- ...R,
1717
- class: "peer sr-only",
1718
- type: "checkbox"
1719
- }), c("label", {
1720
- class: "bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-neutral-12/5 text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 block rounded-2xl px-2.5 py-1 outline outline-2 ring-0 ring-transparent transition-all duration-300 selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",
1721
- htmlFor: V,
1722
- children: p.label
1723
- })]
1724
- }, p.value);
1725
- })
1726
- }), !f && c(Me, {})]
1727
- }), c(Ge, {
1728
- onAnimationComplete: t,
1729
- error: (S = o.checked) == null ? void 0 : S.root
1730
- })]
1731
- });
1732
- }, Ce = {
1733
- email: "That doesn’t look like a valid email address",
1734
- phone: "That doesn’t look like a valid phone number"
1735
- }, cs = xe(Ce.phone, [ur(/^\+?[0-9 -]+$/, Ce.phone)]), ds = {
1736
- email: xe(Ce.email, [lr(Ce.email)]),
1737
- phone: Et(cs, (e) => e.replace(/[^0-9]/g, "")),
1738
- text: xe([Mt(1, "Please enter some text")]),
1739
- url: xe([or("That doesn’t look like a valid URL")])
1740
- }, fs = {
1741
- email: {
1742
- type: "email",
1743
- inputMode: "email",
1744
- formNoValidate: !0
1745
- },
1746
- phone: {
1747
- type: "tel",
1748
- inputMode: "tel"
1749
- },
1750
- text: {
1751
- type: "text",
1752
- inputMode: "text"
1753
- },
1754
- url: {
1755
- type: "url",
1756
- inputMode: "url",
1757
- formNoValidate: !0
1758
- }
1759
- }, hs = We("text"), ys = (e) => $t(Ct({
1760
- text: ds[e.format]
1761
- })), ps = ({
1762
- input: e,
1763
- onSubmitSuccess: s,
1764
- onHeightChange: t
1765
- }) => {
1766
- var S;
1767
- const r = e.key ? (S = U.current$.value.application) == null ? void 0 : S.data.submissions[e.key] : void 0, {
1768
- register: n,
1769
- handleSubmit: a,
1770
- formState: {
1771
- errors: o
1772
- }
1773
- } = qt({
1774
- defaultValues: {
1775
- text: hs(r) ? r.value : ""
1776
- },
1777
- resolver: ys(e.config)
1778
- }), {
1779
- ref: y,
1780
- ...f
1781
- } = n("text", {
1782
- required: !0
1783
- }), x = Ee();
1784
- return qe(() => {
1785
- x.current && (x.current.focus(), x.current.select());
1786
- }, []), c("form", {
1787
- noValidate: !0,
1788
- class: "flex flex-col gap-1",
1789
- onSubmit: a((p) => {
1790
- s(p.text);
1791
- }),
1792
- children: [c("div", {
1793
- class: "flex items-center gap-2",
1794
- children: [c("input", {
1795
- id: "chat-input",
1796
- ...f,
1797
- ...fs[e.config.format],
1798
- autocomplete: "off",
1799
- autoCapitalize: "off",
1800
- autoCorrect: "off",
1801
- autoFocus: !0,
1802
- ref: (p) => {
1803
- p && (x.current = p), y(p);
1804
- },
1805
- class: "outline-neutral-12/5 ease-expo-out placeholder:text-neutral-5 focus-visible:outline-accent-7 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2 transition-all duration-300",
1806
- placeholder: e.config.placeholder
1807
- }), c(Me, {})]
1808
- }), c(Ge, {
1809
- onAnimationComplete: t,
1810
- error: o.text
1811
- })]
1812
- });
1813
- }, gs = ({
1814
- onSubmit: e,
1815
- onInputChange: s,
1816
- input: t
1817
- }) => {
1818
- const r = Ee(null), n = cr(() => {
1819
- r.current && ($e.value = r.current.getBoundingClientRect().height);
1820
- }, []);
1821
- He(() => {
1822
- n(), s(t == null ? void 0 : t.type);
1823
- }, [t == null ? void 0 : t.type, s, n]);
1824
- const a = (o) => (y) => e({
1825
- type: o,
1826
- value: y
1827
- });
1828
- return c(ze.div, {
1829
- initial: {
1830
- height: 0
1831
- },
1832
- animate: {
1833
- height: $e.value
1834
- },
1835
- exit: {
1836
- height: 0,
1837
- opacity: 0
1838
- },
1839
- class: "bg-neutral-2/80 absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",
1840
- children: c("div", {
1841
- ref: r,
1842
- class: "border-neutral-12/5 border-t p-2.5",
1843
- children: te({
1844
- application: U,
1845
- input: t,
1846
- onHeightChange: n
1847
- }).with({
1848
- input: j.nullish
1849
- }, () => c("div", {
1850
- class: "flex items-center gap-2",
1851
- children: [c("input", {
1852
- "aria-hidden": "true",
1853
- id: "chat-input",
1854
- class: "outline-neutral-12/5 placeholder:text-neutral-4 focus-visible:outline-accent-9 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2",
1855
- disabled: !0
1856
- }), c(Me, {
1857
- disabled: !0,
1858
- "aria-hidden": "true",
1859
- tabIndex: -1
1860
- })]
1861
- })).with({
1862
- input: {
1863
- type: "text"
1864
- }
1865
- }, (o) => c(ps, {
1866
- onSubmitSuccess: a(o.input.type),
1867
- ...o
1868
- })).with({
1869
- input: {
1870
- type: "multiple-choice"
1871
- }
1872
- }, (o) => c(us, {
1873
- onSubmitSuccess: a(o.input.type),
1874
- ...o
1875
- })).with({
1876
- input: {
1877
- type: "boolean"
1878
- }
1879
- }, (o) => c(Dr, {
1880
- onSubmitSuccess: a(o.input.type),
1881
- ...o
1882
- })).with({
1883
- input: {
1884
- type: "file"
1885
- }
1886
- }, (o) => c(Lr, {
1887
- onSubmitSuccess: a(o.input.type),
1888
- ...o
1889
- })).exhaustive()
1890
- })
1891
- });
1892
- }, _t = (e) => typeof e == "boolean" ? "".concat(e) : e === 0 ? "0" : e, At = ce, zt = (e, s) => (t) => {
1893
- var r;
1894
- if ((s == null ? void 0 : s.variants) == null)
1895
- return At(e, t == null ? void 0 : t.class, t == null ? void 0 : t.className);
1896
- const { variants: n, defaultVariants: a } = s, o = Object.keys(n).map((x) => {
1897
- const S = t == null ? void 0 : t[x], p = a == null ? void 0 : a[x];
1898
- if (S === null)
1899
- return null;
1900
- const g = _t(S) || _t(p);
1901
- return n[x][g];
1902
- }), y = t && Object.entries(t).reduce((x, S) => {
1903
- let [p, g] = S;
1904
- return g === void 0 || (x[p] = g), x;
1905
- }, {}), f = s == null || (r = s.compoundVariants) === null || r === void 0 ? void 0 : r.reduce((x, S) => {
1906
- let { class: p, className: g, ...V } = S;
1907
- return Object.entries(V).every((k) => {
1908
- let [R, E] = k;
1909
- return Array.isArray(E) ? E.includes({
1910
- ...a,
1911
- ...y
1912
- }[R]) : {
1913
- ...a,
1914
- ...y
1915
- }[R] === E;
1916
- }) ? [
1917
- ...x,
1918
- p,
1919
- g
1920
- ] : x;
1921
- }, []);
1922
- return At(e, o, f, t == null ? void 0 : t.class, t == null ? void 0 : t.className);
1923
- }, ms = zt("max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink-1 min-w-[2rem] text-md py-2 px-3 rounded-[18px] min-h-[36px] break-words", {
1924
- variants: {
1925
- side: {
1926
- left: "bg-lowest text-neutral-12 shadow-surface-sm outline outline-1 outline-neutral-11/[.08] rounded-bl-md",
1927
- right: "ml-auto bg-accent-7 text-lowest rounded-br-md bubble-right"
1928
- },
1929
- transitionState: {
1930
- entering: "opacity-0 translate-y-8",
1931
- entered: "opacity-100 translate-y-0",
1932
- exiting: "opacity-0 scale-0",
1933
- exited: ""
1934
- }
1935
- },
1936
- defaultVariants: {
1937
- side: "left"
1938
- }
1939
- }), vs = {
1940
- hidden: {
1941
- y: "100%",
1942
- scale: 0.75
1943
- },
1944
- shown: {
1945
- y: 0,
1946
- scale: 1
1947
- }
1948
- }, xs = ({
1949
- children: e,
1950
- className: s,
1951
- transitionState: t,
1952
- side: r,
1953
- ...n
1954
- }) => c(ze.p, {
1955
- variants: vs,
1956
- initial: "hidden",
1957
- animate: "shown",
1958
- transition: {
1959
- type: "spring",
1960
- damping: 25,
1961
- stiffness: 500
1962
- },
1963
- "data-transition": t,
1964
- style: {
1965
- transformOrigin: r === "left" ? "0% 50%" : "100% 50%"
1966
- },
1967
- class: ms({
1968
- className: s,
1969
- side: r,
1970
- transitionState: t
1971
- }),
1972
- ...n,
1973
- children: e
1974
- }), bs = ({
1975
- className: e,
1976
- ...s
1977
- }) => c("div", {
1978
- class: ce("flex gap-1 p-4", e),
1979
- ...s,
1980
- children: Array.from({
1981
- length: 3
1982
- }, (t, r) => c("div", {
1983
- class: "bg-accent-7 h-1.5 w-1.5 animate-bounce rounded-full",
1984
- style: {
1985
- animationDelay: `${-r * 200}ms`
1986
- }
1987
- }))
1988
- }), ws = {
1989
- bot: "left",
1990
- user: "right"
1991
- }, Ss = zt("w-full select-none py-2 text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_white]", {
1992
- variants: {
1993
- variant: {
1994
- info: "text-neutral-8",
1995
- warning: "text-[#FFC107]",
1996
- error: "text-error-9",
1997
- success: "text-[#4CAF50]"
1998
- }
1999
- }
2000
- }), ks = ({
2001
- messages: e,
2002
- isBotTyping: s
2003
- }) => c("ol", {
2004
- "aria-label": "Chat messages",
2005
- class: "flex flex-grow flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",
2006
- children: [c(Ke, {
2007
- initial: !1,
2008
- children: e.map((t, r) => c("li", {
2009
- class: "flex",
2010
- children: te(t).with({
2011
- type: "system"
2012
- }, (n) => c("p", {
2013
- class: Ss({
2014
- variant: n.variant
2015
- }),
2016
- children: n.text
2017
- })).with({
2018
- type: "text",
2019
- author: j.union("bot", "user")
2020
- }, (n) => c(xs, {
2021
- side: ws[n.author],
2022
- children: n.text
2023
- }, r)).with({
2024
- type: "link"
2025
- }, (n) => c("div", {
2026
- class: "bg-accent-8/5 flex w-full items-center justify-center overflow-hidden rounded-xl py-2",
2027
- children: c("a", {
2028
- class: "bg-lowest shadow-surface-sm ring-accent-8/20 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 flex items-center gap-1.5 truncate rounded-full py-2 pl-4 pr-2.5 no-underline ring-1 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2",
2029
- target: "_blank",
2030
- href: n.href,
2031
- children: [n.text, c("svg", {
2032
- width: "15",
2033
- height: "15",
2034
- viewBox: "0 0 15 15",
2035
- fill: "none",
2036
- xmlns: "http://www.w3.org/2000/svg",
2037
- children: c("path", {
2038
- d: "M3.64645 11.3536C3.45118 11.1583 3.45118 10.8417 3.64645 10.6465L10.2929 4L6 4C5.72386 4 5.5 3.77614 5.5 3.5C5.5 3.22386 5.72386 3 6 3L11.5 3C11.6326 3 11.7598 3.05268 11.8536 3.14645C11.9473 3.24022 12 3.36739 12 3.5L12 9.00001C12 9.27615 11.7761 9.50001 11.5 9.50001C11.2239 9.50001 11 9.27615 11 9.00001V4.70711L4.35355 11.3536C4.15829 11.5488 3.84171 11.5488 3.64645 11.3536Z",
2039
- fill: "currentColor",
2040
- "fill-rule": "evenodd",
2041
- "clip-rule": "evenodd"
2042
- })
2043
- })]
2044
- })
2045
- })).with({
2046
- type: "image"
2047
- }, (n) => c("img", {
2048
- class: "shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",
2049
- src: n.url,
2050
- style: {
2051
- aspectRatio: n.width / n.height
2052
- }
2053
- })).with({
2054
- type: "file"
2055
- }, (n) => c(Or, {
2056
- class: n.author === "bot" ? "" : "ml-auto",
2057
- file: {
2058
- name: n.fileName,
2059
- sizeKb: n.fileSizeKb
2060
- }
2061
- })).exhaustive()
2062
- }, r))
2063
- }), c("aside", {
2064
- "aria-hidden": !0,
2065
- children: s && c(bs, {})
2066
- })]
2067
- }), _s = 25, As = () => {
2068
- const e = Ee(null), [s, t] = ke(!1), [r, n] = ke(() => () => {
2069
- }), a = ct(() => (y) => {
2070
- var f;
2071
- return (f = e.current) == null ? void 0 : f.scrollTo({
2072
- top: e.current.scrollHeight,
2073
- ...y
2074
- });
2075
- }, [e]), o = ct(() => ({
2076
- send: async ({
2077
- message: y,
2078
- signal: f,
2079
- groupId: x
2080
- }) => {
2081
- if (await te(y).with({
2082
- author: "bot",
2083
- type: "text"
2084
- }, async (S) => {
2085
- if (f != null && f.aborted)
2086
- throw new ye();
2087
- t(!0);
2088
- const p = Math.max(20, S.text.length) * _s;
2089
- await new Promise((g) => setTimeout(g, p, {
2090
- signal: f
2091
- })), t(!1);
2092
- }).otherwise(async () => {
2093
- }), f != null && f.aborted)
2094
- throw new ye();
2095
- U.addMessage(y, x);
2096
- },
2097
- input: async ({
2098
- input: y,
2099
- signal: f
2100
- }) => {
2101
- if (f != null && f.aborted)
2102
- throw new ye();
2103
- return U.setInput(y), await new Promise((x) => {
2104
- const S = (p) => {
2105
- if (f != null && f.aborted)
2106
- throw new ye();
2107
- U.setInput(void 0), y.key && U.setSubmission(y.key, p), x(p);
2108
- };
2109
- n(() => S);
2110
- });
2111
- }
2112
- }), []);
2113
- return {
2114
- chatRef: e,
2115
- chatService: o,
2116
- isBotTyping: s,
2117
- onSubmitSuccessFn: r,
2118
- scrollToEnd: a
2119
- };
2120
- }, Ds = ({
2121
- currentApplication: e,
2122
- logger: s,
2123
- apiClient: t,
2124
- analytics: r
2125
- }) => {
2126
- const {
2127
- chatRef: n,
2128
- chatService: a,
2129
- isBotTyping: o,
2130
- onSubmitSuccessFn: y,
2131
- scrollToEnd: f
2132
- } = As(), x = dr.value, S = e.flow, p = e.job;
2133
- return qe(() => {
2134
- x === "maximised" && f({
2135
- behavior: "instant"
2136
- });
2137
- }, [f, x]), He(() => {
2138
- f({
2139
- behavior: "smooth"
2140
- });
2141
- }, [e.data.messages, f]), qe(() => {
2142
- const {
2143
- state: g,
2144
- application: V
2145
- } = U.current$.peek();
2146
- if (g !== "loaded")
2147
- throw new Error(fr.invalid_state);
2148
- const k = V.data.currentNodeId;
2149
- if (f({
2150
- behavior: "instant"
2151
- }), U.setInput(void 0), V.data.isFinished)
2152
- return;
2153
- V.data.messages.length === 0 && r.log({
2154
- event: "APPLY_START",
2155
- properties: {
2156
- job_id: p.id
2157
- },
2158
- customProperties: {
2159
- flow_id: S.id
2160
- }
2161
- }), U.removeLastGroupMessagesById(k);
2162
- const {
2163
- interpret: E,
2164
- abort: re
2165
- } = yr({
2166
- context: {
2167
- jobId: p.id,
2168
- flowId: S.id
2169
- },
2170
- analytics: r,
2171
- apiClient: t,
2172
- logger: s,
2173
- flow: S.nodes,
2174
- chatService: a,
2175
- // We need to get fresh submissions, that’s why we call `peek` here.
2176
- getSubmissions: () => {
2177
- var w;
2178
- return (w = U.current$.peek().application) == null ? void 0 : w.data.submissions;
2179
- },
2180
- onInterpret: (w, B) => {
2181
- r.log({
2182
- event: "FLOW_NODE",
2183
- properties: {
2184
- flow_id: S.id,
2185
- flow_version: S.version,
2186
- job_id: p.id,
2187
- from_node_id: B ? B.id : null,
2188
- to_node_id: w.id,
2189
- sequence: 1
2190
- }
2191
- }), U.setCurrentNodeId(w.id);
2192
- },
2193
- onFlowEnd: async () => {
2194
- U.markAsFinished();
2195
- }
2196
- });
2197
- return E(k), re;
2198
- }, [r, t, a, s, f, S, p.id, e.startedAt]), c(Ft, {
2199
- children: [c("div", {
2200
- ref: n,
2201
- className: "hide-scrollbars relative flex max-w-full flex-grow flex-col overflow-y-scroll",
2202
- style: {
2203
- WebkitOverflowScrolling: "touch",
2204
- paddingBottom: $e.value
2205
- },
2206
- children: c(Ke, {
2207
- children: c(ks, {
2208
- isBotTyping: o,
2209
- messages: e.data.messages
2210
- })
2211
- })
2212
- }), c(gs, {
2213
- input: e.data.currentInput,
2214
- onInputChange: () => f({
2215
- behavior: "smooth"
2216
- }),
2217
- onSubmit: y
2218
- })]
2219
- });
2220
- };
2221
- export {
2222
- Ds as JobApplicationContent
2223
- };