@viveksinghind/narrative-form-vue 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,67 +1,67 @@
1
- import { triggerRef as U, shallowRef as j, onUnmounted as N, defineComponent as _, ref as g, onMounted as H, openBlock as f, createElementBlock as y, createElementVNode as $, toDisplayString as k, createCommentVNode as F, createBlock as V, Transition as q, withCtx as z, watch as E, nextTick as O, withKeys as G, withModifiers as J, createVNode as Q, computed as x, Fragment as X, renderList as Y, unref as b } from "vue";
2
- import { FormStateEngine as Z, validateField as ee, hasAsyncValidation as te, validateFieldAsync as ne, mergeStrings as le } from "@viveksinghind/narrative-form-core";
3
- function se(n) {
4
- const e = new Z(n, () => {
5
- t.value = e.getSnapshot(), U(t);
6
- }), t = j(e.getSnapshot());
7
- return N(() => {
8
- e.reset();
1
+ import { triggerRef as X, shallowRef as Y, onUnmounted as H, defineComponent as N, ref as C, onMounted as O, openBlock as i, createElementBlock as f, createElementVNode as E, toDisplayString as S, createCommentVNode as K, createBlock as j, Transition as ee, withCtx as te, watch as q, computed as x, normalizeClass as R, createTextVNode as ne, unref as L, Fragment as P, renderList as U, createVNode as Z, mergeProps as W, resolveDynamicComponent as le, nextTick as ae, provide as J, normalizeStyle as se, renderSlot as Q } from "vue";
2
+ import { FormStateEngine as oe, validateField as re, hasAsyncValidation as ie, validateFieldAsync as ue, mergeStrings as ce, fetchFormConfig as de } from "@viveksinghind/narrative-form-core";
3
+ function fe(e) {
4
+ const s = new oe(e, () => {
5
+ t.value = s.getSnapshot(), X(t);
6
+ }), t = Y(s.getSnapshot());
7
+ return H(() => {
8
+ s.reset();
9
9
  }), {
10
10
  snapshot: t,
11
- startTyping: (l) => e.startTyping(l),
12
- activateField: (l) => e.activateField(l),
13
- confirmField: (l, u) => e.confirmField(l, u),
14
- editField: (l) => e.editField(l),
15
- reconfirmField: (l, u) => e.reconfirmField(l, u),
16
- next: () => e.next(),
17
- focusField: (l) => e.focusField(l),
11
+ startTyping: (n) => s.startTyping(n),
12
+ activateField: (n) => s.activateField(n),
13
+ confirmField: (n, a) => s.confirmField(n, a),
14
+ editField: (n) => s.editField(n),
15
+ reconfirmField: (n, a) => s.reconfirmField(n, a),
16
+ next: () => s.next(),
17
+ focusField: (n) => s.focusField(n),
18
18
  reset: () => {
19
- e.reset(), t.value = e.getSnapshot();
19
+ s.reset(), t.value = s.getSnapshot();
20
20
  },
21
- getValues: () => e.getValues(),
22
- getMeta: (l, u) => e.getMeta(l, u)
21
+ getValues: () => s.getValues(),
22
+ getMeta: (n, a) => s.getMeta(n, a)
23
23
  };
24
24
  }
25
- const ae = { class: "ns-welcome fade-in" }, ie = { class: "ns-welcome-title" }, oe = {
25
+ const me = { class: "ns-welcome fade-in" }, ve = { class: "ns-welcome-title" }, pe = {
26
26
  key: 0,
27
27
  class: "ns-welcome-subtitle"
28
- }, re = /* @__PURE__ */ _({
28
+ }, ye = /* @__PURE__ */ N({
29
29
  __name: "WelcomeScreen",
30
30
  props: {
31
31
  welcome: {},
32
32
  typewriter: {}
33
33
  },
34
34
  emits: ["start"],
35
- setup(n, { emit: e }) {
36
- const t = n, l = e, u = g("");
37
- let p;
38
- return H(() => {
35
+ setup(e, { emit: s }) {
36
+ const t = e, n = s, a = C("");
37
+ let o;
38
+ return O(() => {
39
39
  if (!t.typewriter.enabled) {
40
- u.value = t.welcome.heading || "";
40
+ a.value = t.welcome.heading || "";
41
41
  return;
42
42
  }
43
- let c = 0;
44
- p = setInterval(() => {
45
- u.value = (t.welcome.heading || "").slice(0, c + 1), c++, c >= (t.welcome.heading || "").length && clearInterval(p);
43
+ let l = 0;
44
+ o = setInterval(() => {
45
+ a.value = (t.welcome.heading || "").slice(0, l + 1), l++, l >= (t.welcome.heading || "").length && clearInterval(o);
46
46
  }, t.typewriter.speed ?? 30);
47
- }), N(() => {
48
- clearInterval(p);
49
- }), (c, i) => (f(), y("div", ae, [
50
- $("h1", ie, k(u.value), 1),
51
- n.welcome.subtext ? (f(), y("p", oe, k(n.welcome.subtext), 1)) : F("", !0),
52
- $("button", {
47
+ }), H(() => {
48
+ clearInterval(o);
49
+ }), (l, r) => (i(), f("div", me, [
50
+ E("h1", ve, S(a.value), 1),
51
+ e.welcome.subtext ? (i(), f("p", pe, S(e.welcome.subtext), 1)) : K("", !0),
52
+ E("button", {
53
53
  type: "button",
54
54
  class: "ns-welcome-start",
55
- onClick: i[0] || (i[0] = (h) => l("start"))
56
- }, k(n.welcome.ctaLabel || "Start"), 1)
55
+ onClick: r[0] || (r[0] = (y) => n("start"))
56
+ }, S(e.welcome.ctaLabel || "Start"), 1)
57
57
  ]));
58
58
  }
59
- }), L = (n, e) => {
60
- const t = n.__vccOpts || n;
61
- for (const [l, u] of e)
62
- t[l] = u;
59
+ }), G = (e, s) => {
60
+ const t = e.__vccOpts || e;
61
+ for (const [n, a] of s)
62
+ t[n] = a;
63
63
  return t;
64
- }, ue = /* @__PURE__ */ L(re, [["__scopeId", "data-v-dbeb46ea"]]), de = { class: "ns-done fade-in" }, ce = { class: "ns-done-title" }, ve = /* @__PURE__ */ _({
64
+ }, ge = /* @__PURE__ */ G(ye, [["__scopeId", "data-v-dbeb46ea"]]), he = { class: "ns-done fade-in" }, be = { class: "ns-done-title" }, Ce = /* @__PURE__ */ N({
65
65
  __name: "DoneScreen",
66
66
  props: {
67
67
  done: {},
@@ -69,37 +69,699 @@ const ae = { class: "ns-welcome fade-in" }, ie = { class: "ns-welcome-title" },
69
69
  meta: {},
70
70
  typewriter: {}
71
71
  },
72
- setup(n) {
73
- return (e, t) => (f(), y("div", de, [
74
- $("h1", ce, k(typeof n.done.message == "function" ? n.done.message(n.values) : n.done.message), 1)
72
+ setup(e) {
73
+ return (s, t) => (i(), f("div", he, [
74
+ E("h1", be, S(typeof e.done.message == "function" ? e.done.message(e.values) : e.done.message), 1)
75
75
  ]));
76
76
  }
77
- }), fe = /* @__PURE__ */ L(ve, [["__scopeId", "data-v-7802c8f5"]]), me = {
77
+ }), ke = /* @__PURE__ */ G(Ce, [["__scopeId", "data-v-7802c8f5"]]), we = {
78
78
  key: 0,
79
79
  class: "ns-error-wrapper"
80
- }, pe = { class: "ns-error-text" }, ye = /* @__PURE__ */ _({
80
+ }, Fe = { class: "ns-error-text" }, xe = /* @__PURE__ */ N({
81
81
  __name: "ErrorMessage",
82
82
  props: {
83
83
  message: {},
84
84
  config: {}
85
85
  },
86
- setup(n) {
87
- return (e, t) => (f(), V(q, { name: "fade-slide" }, {
88
- default: z(() => [
89
- n.message ? (f(), y("div", me, [
90
- $("p", pe, k(n.message), 1)
91
- ])) : F("", !0)
86
+ setup(e) {
87
+ return (s, t) => (i(), j(ee, { name: "fade-slide" }, {
88
+ default: te(() => [
89
+ e.message ? (i(), f("div", we, [
90
+ E("p", Fe, S(e.message), 1)
91
+ ])) : K("", !0)
92
92
  ]),
93
93
  _: 1
94
94
  }));
95
95
  }
96
- }), ge = /* @__PURE__ */ L(ye, [["__scopeId", "data-v-a8be2d7b"]]), we = { class: "ns-line fade-in" }, be = { class: "ns-prompt-row" }, ke = { class: "ns-prompt" }, Fe = {
96
+ }), $e = /* @__PURE__ */ G(xe, [["__scopeId", "data-v-a8be2d7b"]]);
97
+ function Ne() {
98
+ return typeof window > "u" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
99
+ }
100
+ function De(e) {
101
+ const s = () => typeof e.text == "function" ? e.text() : e.text, t = C(0), n = C(!1);
102
+ let a = null, o = null;
103
+ const l = () => {
104
+ a !== null && (clearInterval(a), a = null), o !== null && (clearTimeout(o), o = null);
105
+ };
106
+ H(l), q(
107
+ [
108
+ () => s(),
109
+ () => e.speed,
110
+ () => e.enabled,
111
+ () => e.pauseAfter
112
+ ],
113
+ ([b, g, d, v]) => {
114
+ var k;
115
+ l();
116
+ const h = g ?? 38, V = d ?? !0, u = v ?? 100, $ = String(b || "");
117
+ if (!V || Ne() || $.length === 0) {
118
+ t.value = $.length, n.value = !0, (k = e.onComplete) == null || k.call(e);
119
+ return;
120
+ }
121
+ t.value = 0, n.value = !1, a = setInterval(() => {
122
+ t.value++, t.value >= $.length && (a !== null && (clearInterval(a), a = null), o = setTimeout(() => {
123
+ var T;
124
+ n.value = !0, (T = e.onComplete) == null || T.call(e);
125
+ }, u));
126
+ }, h);
127
+ },
128
+ { immediate: !0 }
129
+ );
130
+ const r = x(() => s().slice(0, t.value)), y = x(() => t.value < s().length && !n.value);
131
+ return {
132
+ displayedText: r,
133
+ isTyping: y,
134
+ isComplete: n
135
+ };
136
+ }
137
+ const Be = /* @__PURE__ */ N({
138
+ __name: "Cursor",
139
+ props: {
140
+ cursorChar: { default: "|" },
141
+ className: {}
142
+ },
143
+ setup(e) {
144
+ const s = e, t = x(() => ["ns-cursor", s.className].filter(Boolean).join(" "));
145
+ return (n, a) => (i(), f("span", {
146
+ class: R(t.value),
147
+ "aria-hidden": "true"
148
+ }, S(e.cursorChar), 3));
149
+ }
150
+ }), Ve = /* @__PURE__ */ N({
151
+ __name: "Prose",
152
+ props: {
153
+ text: {},
154
+ animate: { type: Boolean, default: !0 },
155
+ speed: { default: 38 },
156
+ cursor: { type: Boolean, default: !0 },
157
+ cursorChar: { default: "|" },
158
+ pauseAfter: { default: 100 },
159
+ className: {}
160
+ },
161
+ emits: ["complete"],
162
+ setup(e, { emit: s }) {
163
+ const t = e, n = s, { displayedText: a, isTyping: o } = De({
164
+ text: () => t.text,
165
+ speed: t.speed,
166
+ enabled: t.animate,
167
+ pauseAfter: t.pauseAfter,
168
+ onComplete: () => n("complete")
169
+ }), l = x(() => [
170
+ "ns-prose",
171
+ o.value ? "ns-prose--typing" : void 0,
172
+ t.className
173
+ ].filter(Boolean).join(" "));
174
+ return (r, y) => (i(), f("span", {
175
+ class: R(l.value)
176
+ }, [
177
+ ne(S(L(a)) + " ", 1),
178
+ e.cursor && L(o) ? (i(), j(Be, {
179
+ key: 0,
180
+ cursorChar: e.cursorChar
181
+ }, null, 8, ["cursorChar"])) : K("", !0)
182
+ ], 2));
183
+ }
184
+ }), Ae = ["aria-label", "title"], Te = /* @__PURE__ */ N({
185
+ __name: "EditIcon",
186
+ props: {
187
+ label: { default: "Edit" },
188
+ className: {}
189
+ },
190
+ emits: ["edit"],
191
+ setup(e, { emit: s }) {
192
+ const t = e, n = s, a = x(() => ["ns-edit-btn", t.className].filter(Boolean).join(" "));
193
+ return (o, l) => (i(), f("button", {
194
+ type: "button",
195
+ class: R(a.value),
196
+ onClick: l[0] || (l[0] = (r) => n("edit")),
197
+ "aria-label": e.label,
198
+ title: e.label
199
+ }, [...l[1] || (l[1] = [
200
+ E("svg", {
201
+ width: "14",
202
+ height: "14",
203
+ viewBox: "0 0 24 24",
204
+ fill: "none",
205
+ stroke: "currentColor",
206
+ "stroke-width": "2",
207
+ "stroke-linecap": "round",
208
+ "stroke-linejoin": "round",
209
+ "aria-hidden": "true"
210
+ }, [
211
+ E("path", { d: "M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" }),
212
+ E("path", { d: "m15 5 4 4" })
213
+ ], -1)
214
+ ])], 10, Ae));
215
+ }
216
+ }), Ie = { class: "ns-filled-value" }, Se = {
97
217
  key: 0,
98
- class: "ns-value"
99
- }, he = {
218
+ class: "ns-suffix"
219
+ }, Le = /* @__PURE__ */ N({
220
+ __name: "FilledValue",
221
+ props: {
222
+ value: {},
223
+ suffix: {},
224
+ editable: { type: Boolean, default: !0 },
225
+ editLabel: { default: "Edit" },
226
+ className: {}
227
+ },
228
+ emits: ["edit"],
229
+ setup(e, { emit: s }) {
230
+ const t = e, n = s, a = x(() => ["ns-filled-wrap", t.className].filter(Boolean).join(" "));
231
+ return (o, l) => (i(), f("span", {
232
+ class: R(a.value)
233
+ }, [
234
+ E("span", Ie, S(e.value), 1),
235
+ e.suffix ? (i(), f("span", Se, S(e.suffix), 1)) : K("", !0),
236
+ e.editable ? (i(), j(Te, {
237
+ key: 1,
238
+ label: e.editLabel,
239
+ onEdit: l[0] || (l[0] = (r) => n("edit"))
240
+ }, null, 8, ["label"])) : K("", !0)
241
+ ], 2));
242
+ }
243
+ }), Ee = ["aria-label"], Ke = ["onClick", "onKeydown", "aria-selected", "tabindex"], Re = /* @__PURE__ */ N({
244
+ __name: "ChipsField",
245
+ props: {
246
+ fieldKey: {},
247
+ options: {},
248
+ defaultValue: {},
249
+ autoAdvance: { type: Boolean, default: !1 },
250
+ className: {}
251
+ },
252
+ emits: ["confirm", "change"],
253
+ setup(e, { emit: s }) {
254
+ const t = e, n = s, a = C(t.defaultValue ?? null), o = C(0), l = C([]), r = (d) => {
255
+ a.value = d, n("change", d), t.autoAdvance && n("confirm", d);
256
+ }, y = () => {
257
+ a.value !== null && n("confirm", a.value);
258
+ }, b = (d, v) => {
259
+ var h, V;
260
+ switch (d.key) {
261
+ case "Enter":
262
+ case " ": {
263
+ d.preventDefault();
264
+ const u = t.options[v];
265
+ u && r(u);
266
+ break;
267
+ }
268
+ case "ArrowRight":
269
+ case "ArrowDown": {
270
+ d.preventDefault();
271
+ const u = (v + 1) % t.options.length;
272
+ o.value = u, (h = l.value[u]) == null || h.focus();
273
+ break;
274
+ }
275
+ case "ArrowLeft":
276
+ case "ArrowUp": {
277
+ d.preventDefault();
278
+ const u = (v - 1 + t.options.length) % t.options.length;
279
+ o.value = u, (V = l.value[u]) == null || V.focus();
280
+ break;
281
+ }
282
+ }
283
+ }, g = x(() => ["ns-chips-wrap", t.className].filter(Boolean).join(" "));
284
+ return (d, v) => (i(), f("span", {
285
+ class: R(g.value),
286
+ role: "listbox",
287
+ "aria-label": e.fieldKey
288
+ }, [
289
+ (i(!0), f(P, null, U(e.options, (h, V) => (i(), f("button", {
290
+ key: h,
291
+ type: "button",
292
+ class: R(["ns-chip", a.value === h ? "ns-chip--active" : void 0].filter(Boolean).join(" ")),
293
+ onClick: (u) => r(h),
294
+ onKeydown: (u) => b(u, V),
295
+ "aria-selected": a.value === h,
296
+ role: "option",
297
+ tabindex: V === o.value ? 0 : -1,
298
+ ref_for: !0,
299
+ ref: (u) => {
300
+ u && (l.value[V] = u);
301
+ }
302
+ }, S(h), 43, Ke))), 128)),
303
+ !e.autoAdvance && a.value !== null ? (i(), f("button", {
304
+ key: 0,
305
+ type: "button",
306
+ class: "ns-enter-btn",
307
+ onClick: y,
308
+ "aria-label": "Confirm",
309
+ style: { opacity: "1", transform: "none" }
310
+ }, " ↵ ")) : K("", !0)
311
+ ], 10, Ee));
312
+ }
313
+ }), je = ["onClick", "onKeydown", "onMouseenter", "aria-pressed"], Me = /* @__PURE__ */ N({
314
+ __name: "MultiChipsField",
315
+ props: {
316
+ fieldKey: {},
317
+ options: {},
318
+ defaultValue: { default: () => [] },
319
+ className: {}
320
+ },
321
+ emits: ["confirm", "change"],
322
+ setup(e, { emit: s }) {
323
+ const t = e, n = s, a = C(new Set(t.defaultValue)), o = C(null), l = (g) => {
324
+ a.value.has(g) ? a.value.delete(g) : a.value.add(g);
325
+ const d = Array.from(a.value).join(", ");
326
+ n("change", d);
327
+ }, r = () => {
328
+ a.value.size > 0 && n("confirm", Array.from(a.value).join(", "));
329
+ }, y = (g, d) => {
330
+ g.key === "Enter" && a.value.size > 0 ? (g.preventDefault(), r()) : g.key === " " && (g.preventDefault(), l(d));
331
+ }, b = x(() => ["ns-chips-wrap", t.className].filter(Boolean).join(" "));
332
+ return (g, d) => (i(), f("span", {
333
+ class: R(b.value)
334
+ }, [
335
+ (i(!0), f(P, null, U(e.options, (v, h) => (i(), f("button", {
336
+ key: v,
337
+ type: "button",
338
+ class: R([
339
+ "ns-chip",
340
+ a.value.has(v) ? "ns-chip--active" : void 0,
341
+ o.value === h ? "ns-chip--hover" : void 0
342
+ ].filter(Boolean).join(" ")),
343
+ onClick: (V) => l(v),
344
+ onKeydown: (V) => y(V, v),
345
+ onMouseenter: (V) => o.value = h,
346
+ onMouseleave: d[0] || (d[0] = (V) => o.value = null),
347
+ "aria-pressed": a.value.has(v),
348
+ role: "option"
349
+ }, S(v), 43, je))), 128)),
350
+ a.value.size > 0 ? (i(), f("button", {
351
+ key: 0,
352
+ type: "button",
353
+ class: "ns-enter-btn",
354
+ onClick: r,
355
+ "aria-label": "Confirm"
356
+ }, " ↵ ")) : K("", !0)
357
+ ], 2));
358
+ }
359
+ }), Pe = ["id", "value", "aria-label"], ze = {
360
+ value: "",
361
+ disabled: ""
362
+ }, qe = ["value"], Oe = /* @__PURE__ */ N({
363
+ __name: "SelectField",
364
+ props: {
365
+ fieldKey: {},
366
+ options: {},
367
+ placeholder: { default: "Select…" },
368
+ defaultValue: { default: "" },
369
+ autoAdvance: { type: Boolean, default: !1 },
370
+ inputClassName: {},
371
+ className: {}
372
+ },
373
+ emits: ["confirm", "change", "focus", "blur"],
374
+ setup(e, { emit: s }) {
375
+ const t = e, n = s, a = C(t.defaultValue), o = C(null);
376
+ O(() => {
377
+ var d;
378
+ (d = o.value) == null || d.focus();
379
+ });
380
+ const l = (d) => {
381
+ const h = d.target.value;
382
+ a.value = h, n("change", h), t.autoAdvance && h !== "" && n("confirm", h);
383
+ }, r = (d) => {
384
+ d.key === "Enter" && a.value !== "" && (d.preventDefault(), n("confirm", a.value));
385
+ }, y = () => {
386
+ a.value !== "" && n("confirm", a.value);
387
+ }, b = x(() => ["ns-select-wrap", t.className].filter(Boolean).join(" ")), g = x(() => ["ns-select", t.inputClassName].filter(Boolean).join(" "));
388
+ return (d, v) => (i(), f("span", {
389
+ class: R(b.value)
390
+ }, [
391
+ E("select", {
392
+ ref_key: "selectRef",
393
+ ref: o,
394
+ id: `ns-field-${e.fieldKey}`,
395
+ class: R(g.value),
396
+ value: a.value,
397
+ onChange: l,
398
+ onKeydown: r,
399
+ onFocus: v[0] || (v[0] = (h) => n("focus")),
400
+ onBlur: v[1] || (v[1] = (h) => n("blur", a.value)),
401
+ "aria-label": e.fieldKey
402
+ }, [
403
+ E("option", ze, S(e.placeholder), 1),
404
+ (i(!0), f(P, null, U(e.options, (h) => (i(), f("option", {
405
+ key: h,
406
+ value: h
407
+ }, S(h), 9, qe))), 128))
408
+ ], 42, Pe),
409
+ !e.autoAdvance && a.value !== "" ? (i(), f("button", {
410
+ key: 0,
411
+ type: "button",
412
+ class: "ns-enter-btn",
413
+ onClick: y,
414
+ "aria-label": "Confirm"
415
+ }, " ↵ ")) : K("", !0)
416
+ ], 2));
417
+ }
418
+ }), Ue = { class: "ns-otp-boxes" }, We = ["value", "onInput", "onKeydown", "onFocus", "aria-label"], He = { class: "ns-otp-resend-wrap" }, Ge = {
419
+ key: 1,
420
+ class: "ns-otp-resend ns-otp-resend--disabled"
421
+ }, Ze = { class: "ns-otp-timer" }, _e = /* @__PURE__ */ N({
422
+ __name: "OtpField",
423
+ props: {
424
+ fieldKey: {},
425
+ otpLength: { default: 6 },
426
+ autoAdvance: { type: Boolean, default: !0 },
427
+ onRequest: {},
428
+ onVerify: {},
429
+ resendLabel: { default: "Resend code" },
430
+ resendDelay: { default: 30 },
431
+ className: {}
432
+ },
433
+ emits: ["confirm", "change"],
434
+ setup(e, { emit: s }) {
435
+ const t = e, n = s, a = C(Array.from({ length: t.otpLength }, () => "")), o = C(0), l = C(t.resendDelay), r = C(!1), y = C([]);
436
+ let b = null;
437
+ const g = C(!1), d = () => {
438
+ if (t.resendDelay <= 0) {
439
+ r.value = !0;
440
+ return;
441
+ }
442
+ l.value = t.resendDelay, r.value = !1, b !== null && clearInterval(b), b = setInterval(() => {
443
+ l.value -= 1, l.value <= 0 && (b !== null && clearInterval(b), r.value = !0);
444
+ }, 1e3);
445
+ };
446
+ O(() => {
447
+ var m, c;
448
+ g.value || (g.value = !0, (m = t.onRequest) == null || m.call(t)), (c = y.value[0]) == null || c.focus(), d();
449
+ }), H(() => {
450
+ b !== null && clearInterval(b);
451
+ }), q(() => t.resendDelay, d);
452
+ const v = (m) => m.join(""), h = (m, c) => {
453
+ var F, w;
454
+ const A = c.target.value.replace(/\D/g, "").slice(-1);
455
+ a.value[m] = A;
456
+ const B = v(a.value);
457
+ n("change", B), A !== "" && m < t.otpLength - 1 && ((F = y.value[m + 1]) == null || F.focus(), o.value = m + 1), a.value.every((I) => I !== "") && ((w = t.onVerify) == null || w.call(t, B), t.autoAdvance && setTimeout(() => n("confirm", B), 0));
458
+ }, V = (m, c) => {
459
+ var p, D, A;
460
+ if (c.key === "Backspace")
461
+ c.preventDefault(), a.value[m] !== "" ? (a.value[m] = "", n("change", v(a.value))) : m > 0 && (a.value[m - 1] = "", (p = y.value[m - 1]) == null || p.focus(), o.value = m - 1, n("change", v(a.value)));
462
+ else if (c.key === "Enter") {
463
+ c.preventDefault();
464
+ const B = v(a.value);
465
+ a.value.every((F) => F !== "") && n("confirm", B);
466
+ } else c.key === "ArrowLeft" && m > 0 ? (c.preventDefault(), (D = y.value[m - 1]) == null || D.focus(), o.value = m - 1) : c.key === "ArrowRight" && m < t.otpLength - 1 && (c.preventDefault(), (A = y.value[m + 1]) == null || A.focus(), o.value = m + 1);
467
+ }, u = (m) => {
468
+ var B, F, w;
469
+ m.preventDefault();
470
+ const c = ((B = m.clipboardData) == null ? void 0 : B.getData("text").replace(/\D/g, "").slice(0, t.otpLength)) || "";
471
+ if (c.length === 0) return;
472
+ for (let I = 0; I < c.length; I++) {
473
+ const _ = c[I];
474
+ _ !== void 0 && (a.value[I] = _);
475
+ }
476
+ const p = v(a.value);
477
+ n("change", p);
478
+ const D = a.value.findIndex((I) => I === ""), A = D === -1 ? t.otpLength - 1 : D;
479
+ (F = y.value[A]) == null || F.focus(), o.value = A, a.value.every((I) => I !== "") && ((w = t.onVerify) == null || w.call(t, p), t.autoAdvance && setTimeout(() => n("confirm", p), 0));
480
+ }, $ = () => {
481
+ var m, c;
482
+ r.value && (r.value = !1, a.value = Array.from({ length: t.otpLength }, () => ""), o.value = 0, (m = y.value[0]) == null || m.focus(), (c = t.onRequest) == null || c.call(t), d());
483
+ }, k = (m) => {
484
+ o.value = m;
485
+ }, T = () => {
486
+ n("confirm", v(a.value));
487
+ }, M = x(() => ["ns-otp-wrap", t.className].filter(Boolean).join(" "));
488
+ return (m, c) => (i(), f("span", {
489
+ class: R(M.value)
490
+ }, [
491
+ E("span", Ue, [
492
+ (i(!0), f(P, null, U(a.value, (p, D) => (i(), f("input", {
493
+ key: D,
494
+ ref_for: !0,
495
+ ref: (A) => {
496
+ A && (y.value[D] = A);
497
+ },
498
+ type: "text",
499
+ inputmode: "numeric",
500
+ maxlength: 1,
501
+ class: R([
502
+ "ns-otp-box",
503
+ p !== "" ? "ns-otp-box--filled" : void 0,
504
+ o.value === D ? "ns-otp-box--active" : void 0
505
+ ].filter(Boolean).join(" ")),
506
+ value: p,
507
+ onInput: (A) => h(D, A),
508
+ onKeydown: (A) => V(D, A),
509
+ onPaste: u,
510
+ onFocus: (A) => k(D),
511
+ autocomplete: "one-time-code",
512
+ "aria-label": `Digit ${D + 1}`
513
+ }, null, 42, We))), 128))
514
+ ]),
515
+ !e.autoAdvance && a.value.every((p) => p !== "") ? (i(), f("button", {
516
+ key: 0,
517
+ type: "button",
518
+ class: "ns-enter-btn",
519
+ onClick: T,
520
+ "aria-label": "Confirm"
521
+ }, " ↵ ")) : K("", !0),
522
+ E("span", He, [
523
+ r.value ? (i(), f("button", {
524
+ key: 0,
525
+ type: "button",
526
+ class: "ns-otp-resend",
527
+ onClick: $
528
+ }, S(e.resendLabel), 1)) : (i(), f("span", Ge, [
529
+ E("span", Ze, " Resend in " + S(l.value) + "s ", 1)
530
+ ]))
531
+ ])
532
+ ], 2));
533
+ }
534
+ }), Je = /* @__PURE__ */ N({
535
+ __name: "EnterButton",
536
+ props: {
537
+ label: { default: "↵" },
538
+ className: {}
539
+ },
540
+ emits: ["confirm"],
541
+ setup(e, { emit: s }) {
542
+ const t = e, n = s, a = x(() => ["ns-enter-btn", t.className].filter(Boolean).join(" "));
543
+ return (o, l) => (i(), f("button", {
544
+ type: "button",
545
+ class: R(a.value),
546
+ onClick: l[0] || (l[0] = (r) => n("confirm")),
547
+ "aria-label": "Confirm"
548
+ }, S(e.label), 3));
549
+ }
550
+ }), Qe = ["id", "type", "inputmode", "value", "placeholder", "aria-label"], Xe = {
551
+ key: 0,
552
+ class: "ns-suffix"
553
+ }, z = /* @__PURE__ */ N({
554
+ __name: "InlineInput",
555
+ props: {
556
+ fieldKey: {},
557
+ type: { default: "text" },
558
+ placeholder: {},
559
+ defaultValue: { default: "" },
560
+ suffix: {},
561
+ sanitise: {},
562
+ inputClassName: {},
563
+ className: {}
564
+ },
565
+ emits: ["confirm", "change", "focus", "blur", "escape"],
566
+ setup(e, { emit: s }) {
567
+ const t = e, n = s, a = C(t.defaultValue), o = C(!1), l = C(null);
568
+ O(() => {
569
+ var k;
570
+ (k = l.value) == null || k.focus();
571
+ });
572
+ const r = (k) => {
573
+ const T = t.sanitise ? t.sanitise(k) : k;
574
+ a.value = T, n("change", T);
575
+ }, y = (k) => {
576
+ const T = k.target;
577
+ r(T.value);
578
+ }, b = (k) => {
579
+ var M;
580
+ if (!t.sanitise) return;
581
+ k.preventDefault();
582
+ const T = ((M = k.clipboardData) == null ? void 0 : M.getData("text")) || "";
583
+ r(T);
584
+ }, g = (k) => {
585
+ k.key === "Enter" ? (k.preventDefault(), n("confirm", a.value)) : k.key === "Escape" && (k.preventDefault(), n("escape"));
586
+ }, d = () => {
587
+ o.value = !0, n("focus");
588
+ }, v = () => {
589
+ o.value = !1, n("blur", a.value);
590
+ }, h = () => {
591
+ n("confirm", a.value);
592
+ }, V = x(() => ["ns-input-wrap", t.className].filter(Boolean).join(" ")), u = x(() => [
593
+ "ns-input",
594
+ `ns-input--${t.type}`,
595
+ o.value ? "ns-input--focused" : void 0,
596
+ t.inputClassName
597
+ ].filter(Boolean).join(" ")), $ = x(() => {
598
+ switch (t.type) {
599
+ case "tel":
600
+ return "tel";
601
+ case "email":
602
+ return "email";
603
+ case "number":
604
+ return "numeric";
605
+ default:
606
+ return;
607
+ }
608
+ });
609
+ return (k, T) => (i(), f("span", {
610
+ class: R(V.value)
611
+ }, [
612
+ E("input", {
613
+ ref_key: "inputRef",
614
+ ref: l,
615
+ id: `ns-field-${e.fieldKey}`,
616
+ class: R(u.value),
617
+ type: e.type === "number" ? "text" : e.type,
618
+ inputmode: $.value,
619
+ value: a.value,
620
+ placeholder: e.placeholder,
621
+ onInput: y,
622
+ onKeydown: g,
623
+ onFocus: d,
624
+ onBlur: v,
625
+ onPaste: b,
626
+ autocomplete: "off",
627
+ "aria-label": e.fieldKey
628
+ }, null, 42, Qe),
629
+ Z(Je, { onConfirm: h }),
630
+ e.suffix ? (i(), f("span", Xe, S(e.suffix), 1)) : K("", !0)
631
+ ], 2));
632
+ }
633
+ }), Ye = /* @__PURE__ */ N({
634
+ __name: "PasswordField",
635
+ props: {
636
+ fieldKey: {},
637
+ placeholder: {},
638
+ defaultValue: {},
639
+ suffix: {},
640
+ inputClassName: {},
641
+ className: {}
642
+ },
643
+ emits: ["confirm", "change", "focus", "blur"],
644
+ setup(e, { emit: s }) {
645
+ const t = e, n = s;
646
+ return (a, o) => (i(), j(z, W(t, {
647
+ type: "password",
648
+ onConfirm: o[0] || (o[0] = (l) => n("confirm", l)),
649
+ onChange: o[1] || (o[1] = (l) => n("change", l)),
650
+ onFocus: o[2] || (o[2] = (l) => n("focus")),
651
+ onBlur: o[3] || (o[3] = (l) => n("blur", l))
652
+ }), null, 16));
653
+ }
654
+ }), et = /* @__PURE__ */ N({
655
+ __name: "DateField",
656
+ props: {
657
+ fieldKey: {},
658
+ placeholder: {},
659
+ defaultValue: {},
660
+ suffix: {},
661
+ inputClassName: {},
662
+ className: {}
663
+ },
664
+ emits: ["confirm", "change", "focus", "blur"],
665
+ setup(e, { emit: s }) {
666
+ const t = e, n = s;
667
+ return (a, o) => (i(), j(z, W(t, {
668
+ type: "date",
669
+ onConfirm: o[0] || (o[0] = (l) => n("confirm", l)),
670
+ onChange: o[1] || (o[1] = (l) => n("change", l)),
671
+ onFocus: o[2] || (o[2] = (l) => n("focus")),
672
+ onBlur: o[3] || (o[3] = (l) => n("blur", l))
673
+ }), null, 16));
674
+ }
675
+ }), tt = /* @__PURE__ */ N({
676
+ __name: "TextField",
677
+ props: {
678
+ fieldKey: {},
679
+ placeholder: {},
680
+ defaultValue: {},
681
+ suffix: {},
682
+ inputClassName: {},
683
+ className: {}
684
+ },
685
+ emits: ["confirm", "change", "focus", "blur"],
686
+ setup(e, { emit: s }) {
687
+ const t = e, n = s;
688
+ return (a, o) => (i(), j(z, W(t, {
689
+ type: "text",
690
+ onConfirm: o[0] || (o[0] = (l) => n("confirm", l)),
691
+ onChange: o[1] || (o[1] = (l) => n("change", l)),
692
+ onFocus: o[2] || (o[2] = (l) => n("focus")),
693
+ onBlur: o[3] || (o[3] = (l) => n("blur", l))
694
+ }), null, 16));
695
+ }
696
+ }), nt = /* @__PURE__ */ N({
697
+ __name: "EmailField",
698
+ props: {
699
+ fieldKey: {},
700
+ placeholder: {},
701
+ defaultValue: {},
702
+ suffix: {},
703
+ inputClassName: {},
704
+ className: {}
705
+ },
706
+ emits: ["confirm", "change", "focus", "blur"],
707
+ setup(e, { emit: s }) {
708
+ const t = e, n = s;
709
+ return (a, o) => (i(), j(z, W(t, {
710
+ type: "email",
711
+ onConfirm: o[0] || (o[0] = (l) => n("confirm", l)),
712
+ onChange: o[1] || (o[1] = (l) => n("change", l)),
713
+ onFocus: o[2] || (o[2] = (l) => n("focus")),
714
+ onBlur: o[3] || (o[3] = (l) => n("blur", l))
715
+ }), null, 16));
716
+ }
717
+ }), lt = /* @__PURE__ */ N({
718
+ __name: "NumberField",
719
+ props: {
720
+ fieldKey: {},
721
+ placeholder: {},
722
+ defaultValue: {},
723
+ suffix: {},
724
+ inputClassName: {},
725
+ className: {}
726
+ },
727
+ emits: ["confirm", "change", "focus", "blur"],
728
+ setup(e, { emit: s }) {
729
+ const t = e, n = s, a = (o) => o.replace(/[^\d.-]/g, "");
730
+ return (o, l) => (i(), j(z, W(t, {
731
+ type: "number",
732
+ sanitise: a,
733
+ onConfirm: l[0] || (l[0] = (r) => n("confirm", r)),
734
+ onChange: l[1] || (l[1] = (r) => n("change", r)),
735
+ onFocus: l[2] || (l[2] = (r) => n("focus")),
736
+ onBlur: l[3] || (l[3] = (r) => n("blur", r))
737
+ }), null, 16));
738
+ }
739
+ }), at = /* @__PURE__ */ N({
740
+ __name: "TelField",
741
+ props: {
742
+ fieldKey: {},
743
+ placeholder: {},
744
+ defaultValue: {},
745
+ suffix: {},
746
+ inputClassName: {},
747
+ className: {}
748
+ },
749
+ emits: ["confirm", "change", "focus", "blur"],
750
+ setup(e, { emit: s }) {
751
+ const t = e, n = s, a = (o) => o.replace(/\D/g, "");
752
+ return (o, l) => (i(), j(z, W(t, {
753
+ type: "tel",
754
+ sanitise: a,
755
+ onConfirm: l[0] || (l[0] = (r) => n("confirm", r)),
756
+ onChange: l[1] || (l[1] = (r) => n("change", r)),
757
+ onFocus: l[2] || (l[2] = (r) => n("focus")),
758
+ onBlur: l[3] || (l[3] = (r) => n("blur", r))
759
+ }), null, 16));
760
+ }
761
+ }), st = { class: "ns-prompt-row" }, ot = {
100
762
  key: 0,
101
763
  class: "ns-input-row"
102
- }, Ce = ["type", "disabled", "value", "onKeydown"], xe = /* @__PURE__ */ _({
764
+ }, rt = /* @__PURE__ */ N({
103
765
  __name: "Line",
104
766
  props: {
105
767
  field: {},
@@ -112,79 +774,105 @@ const ae = { class: "ns-welcome fade-in" }, ie = { class: "ns-welcome-title" },
112
774
  editLabel: {}
113
775
  },
114
776
  emits: ["typingComplete", "confirm", "edit", "error", "change", "focus", "blur"],
115
- setup(n, { emit: e }) {
116
- const t = n, l = e, u = g(null), p = g(""), c = g(t.value ? String(t.value) : ""), i = g(null), h = g(!1);
117
- let I;
118
- E(() => t.value, (v) => {
119
- v !== void 0 && String(v) !== c.value && (c.value = String(v));
120
- }), E(() => t.status, (v) => {
121
- if (v === "typing") {
122
- if (!t.typewriter.enabled) {
123
- p.value = t.field.prompt, l("typingComplete", t.field.key);
124
- return;
125
- }
126
- let o = 0;
127
- I = setInterval(() => {
128
- p.value = t.field.prompt.slice(0, o + 1), o++, o >= t.field.prompt.length && (clearInterval(I), l("typingComplete", t.field.key));
129
- }, t.typewriter.speed ?? 30);
130
- } else (v === "active" || v === "editing") && O(() => {
131
- var o;
132
- (o = u.value) == null || o.focus();
133
- });
134
- }, { immediate: !0 }), N(() => {
135
- clearInterval(I);
777
+ setup(e, { emit: s }) {
778
+ const t = e, n = s, a = {
779
+ chips: Re,
780
+ "multi-chips": Me,
781
+ select: Oe,
782
+ otp: _e,
783
+ password: Ye,
784
+ date: et,
785
+ text: tt,
786
+ email: nt,
787
+ number: lt,
788
+ tel: at
789
+ }, o = x(() => a[t.field.type] || z), l = C(t.value !== void 0 ? t.value : ""), r = C(null), y = C(!1), b = x(() => t.field.editable !== !1 && t.editable && !t.locked), g = x(() => {
790
+ var u;
791
+ return t.field.animate !== !1 && ((u = t.typewriter) == null ? void 0 : u.enabled) !== !1;
792
+ });
793
+ q(() => t.value, (u) => {
794
+ u !== void 0 && u !== l.value && (l.value = u);
136
795
  });
137
- const R = (v) => {
138
- const o = v.target;
139
- c.value = o.value, l("change", t.field.key, o.value), i.value && (i.value = null);
140
- }, D = async () => {
141
- const v = ee(t.field, c.value);
142
- if (!v.valid) {
143
- i.value = v.error || "Invalid input", l("error", t.field.key, i.value);
796
+ const d = () => {
797
+ t.status === "typing" && n("typingComplete", t.field.key);
798
+ }, v = (u) => {
799
+ l.value = u;
800
+ const $ = Array.isArray(u) ? u.join(", ") : String(u);
801
+ n("change", t.field.key, $), r.value && (r.value = null);
802
+ }, h = async (u) => {
803
+ l.value = u;
804
+ const $ = Array.isArray(u) ? u.join(", ") : String(u), k = re(t.field, u, t.allValues);
805
+ if (!k.valid) {
806
+ r.value = k.error || "Invalid input", n("error", t.field.key, r.value);
144
807
  return;
145
808
  }
146
- if (te(t.field)) {
147
- h.value = !0;
148
- const o = await ne(t.field, c.value);
149
- if (h.value = !1, !o.valid) {
150
- i.value = o.error || "Invalid input", l("error", t.field.key, i.value);
809
+ if (ie(t.field)) {
810
+ y.value = !0;
811
+ const T = await ue(t.field, u, t.allValues);
812
+ if (y.value = !1, !T.valid) {
813
+ r.value = T.error || "Invalid input", n("error", t.field.key, r.value);
151
814
  return;
152
815
  }
153
816
  }
154
- i.value = null, l("confirm", t.field.key, c.value);
817
+ r.value = null, n("confirm", t.field.key, $);
818
+ }, V = () => {
819
+ r.value = null, n("edit", t.field.key);
820
+ };
821
+ return (u, $) => {
822
+ var k, T, M, m;
823
+ return i(), f("div", {
824
+ class: R(["ns-line fade-in", e.field.className])
825
+ }, [
826
+ E("div", st, [
827
+ Z(Ve, {
828
+ text: e.field.prefix || e.field.prompt || "",
829
+ animate: e.status === "typing" && g.value,
830
+ speed: (k = e.typewriter) == null ? void 0 : k.speed,
831
+ cursor: ((T = e.typewriter) == null ? void 0 : T.cursor) !== !1,
832
+ cursorChar: (M = e.typewriter) == null ? void 0 : M.cursorChar,
833
+ pauseAfter: (m = e.typewriter) == null ? void 0 : m.pauseAfter,
834
+ onComplete: d
835
+ }, null, 8, ["text", "animate", "speed", "cursor", "cursorChar", "pauseAfter"]),
836
+ e.status === "confirmed" ? (i(), j(Le, {
837
+ key: 0,
838
+ value: Array.isArray(l.value) ? l.value.join(", ") : String(l.value),
839
+ suffix: e.field.suffix,
840
+ editable: b.value,
841
+ editLabel: e.editLabel,
842
+ onEdit: V
843
+ }, null, 8, ["value", "suffix", "editable", "editLabel"])) : K("", !0)
844
+ ]),
845
+ e.status === "active" || e.status === "editing" ? (i(), f("div", ot, [
846
+ (i(), j(le(o.value), {
847
+ fieldKey: e.field.key,
848
+ type: e.field.type,
849
+ placeholder: e.field.placeholder,
850
+ defaultValue: e.status === "editing" ? l.value : e.field.defaultValue,
851
+ suffix: e.field.suffix,
852
+ options: e.field.options,
853
+ otpLength: e.field.otpLength,
854
+ autoAdvance: e.field.autoAdvance,
855
+ resendLabel: e.field.resendLabel,
856
+ resendDelay: e.field.resendDelay,
857
+ sanitise: e.field.sanitise,
858
+ inputClassName: e.field.inputClassName,
859
+ disabled: y.value,
860
+ onConfirm: h,
861
+ onChange: v,
862
+ onFocus: $[0] || ($[0] = (c) => n("focus", e.field.key)),
863
+ onBlur: $[1] || ($[1] = (c) => n("blur", e.field.key, c)),
864
+ onRequest: $[2] || ($[2] = (c) => e.field.onRequest && e.field.onRequest()),
865
+ onVerify: $[3] || ($[3] = (c) => e.field.onVerify && e.field.onVerify(c))
866
+ }, null, 40, ["fieldKey", "type", "placeholder", "defaultValue", "suffix", "options", "otpLength", "autoAdvance", "resendLabel", "resendDelay", "sanitise", "inputClassName", "disabled"]))
867
+ ])) : K("", !0),
868
+ Z($e, { message: r.value }, null, 8, ["message"])
869
+ ], 2);
155
870
  };
156
- return (v, o) => (f(), y("div", we, [
157
- $("div", be, [
158
- $("span", ke, k(n.status === "typing" ? p.value : n.field.prompt), 1),
159
- n.status === "confirmed" ? (f(), y("span", Fe, k(c.value), 1)) : F("", !0),
160
- n.status === "confirmed" && n.editable && !n.locked ? (f(), y("button", {
161
- key: 1,
162
- type: "button",
163
- class: "ns-edit-btn",
164
- onClick: o[0] || (o[0] = (B) => l("edit", n.field.key))
165
- }, k(n.editLabel), 1)) : F("", !0)
166
- ]),
167
- n.status === "active" || n.status === "editing" ? (f(), y("div", he, [
168
- $("input", {
169
- ref_key: "inputRef",
170
- ref: u,
171
- type: n.field.type === "email" ? "email" : n.field.type === "password" ? "password" : "text",
172
- class: "ns-input",
173
- disabled: h.value,
174
- value: c.value,
175
- onInput: R,
176
- onFocus: o[1] || (o[1] = (B) => l("focus", n.field.key)),
177
- onBlur: o[2] || (o[2] = (B) => l("blur", n.field.key, c.value)),
178
- onKeydown: G(J(D, ["prevent"]), ["enter"])
179
- }, null, 40, Ce)
180
- ])) : F("", !0),
181
- Q(ge, { message: i.value }, null, 8, ["message"])
182
- ]));
183
871
  }
184
- }), $e = /* @__PURE__ */ L(xe, [["__scopeId", "data-v-d4b482a6"]]), Ie = {
872
+ }), it = /* @__PURE__ */ G(rt, [["__scopeId", "data-v-7fe5da13"]]), ut = {
185
873
  key: 1,
186
874
  class: "ns-form-body"
187
- }, Se = /* @__PURE__ */ _({
875
+ }, ct = /* @__PURE__ */ N({
188
876
  __name: "NarrativeForm",
189
877
  props: {
190
878
  fields: {},
@@ -200,120 +888,270 @@ const ae = { class: "ns-welcome fade-in" }, ie = { class: "ns-welcome-title" },
200
888
  strings: {},
201
889
  reducedMotion: { type: Boolean }
202
890
  },
203
- setup(n) {
204
- const e = n, t = x(() => e.fields ? e.fields : e.formConfig ? e.formConfig.fields : []), l = x(() => {
205
- if (e.welcome) return e.welcome;
206
- if (e.formConfig && "welcome" in e.formConfig) return e.formConfig.welcome;
207
- }), u = x(() => {
208
- if (e.done) return e.done;
209
- if (e.formConfig && "done" in e.formConfig) return e.formConfig.done;
210
- }), p = x(() => {
211
- var d;
891
+ setup(e) {
892
+ const s = e, t = x(() => s.fields ? s.fields : s.formConfig ? s.formConfig.fields : []), n = x(() => {
893
+ if (s.welcome) return s.welcome;
894
+ if (s.formConfig && "welcome" in s.formConfig) return s.formConfig.welcome;
895
+ }), a = x(() => {
896
+ if (s.done) return s.done;
897
+ if (s.formConfig && "done" in s.formConfig) return s.formConfig.done;
898
+ }), o = x(() => {
899
+ var c;
212
900
  return {
213
- ...e.typewriter,
214
- enabled: e.reducedMotion ? !1 : ((d = e.typewriter) == null ? void 0 : d.enabled) ?? !0
901
+ ...s.typewriter,
902
+ enabled: s.reducedMotion ? !1 : ((c = s.typewriter) == null ? void 0 : c.enabled) ?? !0
215
903
  };
216
- }), c = x(() => le(e.strings)), {
217
- snapshot: i,
218
- startTyping: h,
219
- activateField: I,
220
- confirmField: R,
221
- editField: D,
904
+ }), l = x(() => ce(s.strings)), {
905
+ snapshot: r,
906
+ startTyping: y,
907
+ activateField: b,
908
+ confirmField: g,
909
+ editField: d,
222
910
  reconfirmField: v,
223
- getMeta: o
224
- } = se(t.value), B = x(() => {
225
- var d;
226
- return ((d = l.value) == null ? void 0 : d.show) !== !1 && l.value !== void 0;
227
- }), S = g(!B.value), W = g(!1), K = () => {
228
- if (!S.value || W.value || t.value.length === 0) return;
229
- W.value = !0;
230
- const d = t.value.find((a) => i.value.statuses[a.key] !== "confirmed");
231
- d && h(d.key);
911
+ getMeta: h
912
+ } = fe(t.value), V = x(() => {
913
+ var c;
914
+ return ((c = n.value) == null ? void 0 : c.show) !== !1 && n.value !== void 0;
915
+ }), u = C(!V.value), $ = C(!1), k = () => {
916
+ if (!u.value || $.value || t.value.length === 0) return;
917
+ $.value = !0;
918
+ const c = t.value.find((p) => r.value.statuses[p.key] !== "confirmed");
919
+ c && y(c.key);
232
920
  };
233
- E(S, K), H(K);
234
- const P = (d, a) => {
235
- var m;
236
- i.value.statuses[d] === "editing" ? v(d, a) : R(d, a), (m = e.callbacks) != null && m.onFieldComplete && e.callbacks.onFieldComplete(d, a, 0);
237
- const T = t.value.findIndex((r) => r.key === d);
238
- for (let r = T + 1; r < t.value.length; r++) {
239
- const s = t.value[r];
240
- if (!(!s || i.value.statuses[s.key] === "confirmed")) {
241
- h(s.key);
921
+ q(u, k), O(k);
922
+ const T = (c, p) => {
923
+ var B;
924
+ r.value.statuses[c] === "editing" ? v(c, p) : g(c, p), (B = s.callbacks) != null && B.onFieldComplete && s.callbacks.onFieldComplete(c, p, 0);
925
+ const A = t.value.findIndex((F) => F.key === c);
926
+ for (let F = A + 1; F < t.value.length; F++) {
927
+ const w = t.value[F];
928
+ if (!(!w || r.value.statuses[w.key] === "confirmed")) {
929
+ y(w.key);
242
930
  break;
243
931
  }
244
932
  }
245
- }, A = x(() => t.value.filter((d) => {
246
- const a = i.value.statuses[d.key];
247
- return a === "typing" || a === "active" || a === "confirmed" || a === "editing";
248
- })), M = g(null);
249
- return E(() => A.value.length, () => {
250
- O(() => {
251
- M.value && (M.value.scrollTop = M.value.scrollHeight);
933
+ }, M = x(() => t.value.filter((c) => {
934
+ const p = r.value.statuses[c.key];
935
+ return p === "typing" || p === "active" || p === "confirmed" || p === "editing";
936
+ })), m = C(null);
937
+ return q(() => M.value.length, () => {
938
+ ae(() => {
939
+ m.value && (m.value.scrollTop = m.value.scrollHeight);
252
940
  });
253
- }), (d, a) => (f(), y("div", {
941
+ }), (c, p) => (i(), f("div", {
254
942
  class: "ns-root",
255
943
  ref_key: "scrollContainerRef",
256
- ref: M
944
+ ref: m
257
945
  }, [
258
- !S.value && l.value ? (f(), V(ue, {
946
+ !u.value && n.value ? (i(), j(ge, {
259
947
  key: 0,
260
- welcome: l.value,
261
- typewriter: p.value,
262
- onStart: a[0] || (a[0] = (C) => S.value = !0)
263
- }, null, 8, ["welcome", "typewriter"])) : F("", !0),
264
- S.value ? (f(), y("div", Ie, [
265
- (f(!0), y(X, null, Y(A.value, (C) => {
266
- var T;
267
- return f(), V($e, {
268
- key: C.key,
269
- field: C,
270
- status: b(i).statuses[C.key] ?? "idle",
271
- value: ((T = e.values) == null ? void 0 : T[C.key]) ?? b(i).values[C.key],
272
- allValues: b(i).values,
273
- typewriter: p.value,
274
- editable: e.editable,
948
+ welcome: n.value,
949
+ typewriter: o.value,
950
+ onStart: p[0] || (p[0] = (D) => u.value = !0)
951
+ }, null, 8, ["welcome", "typewriter"])) : K("", !0),
952
+ u.value ? (i(), f("div", ut, [
953
+ (i(!0), f(P, null, U(M.value, (D) => {
954
+ var A;
955
+ return i(), j(it, {
956
+ key: D.key,
957
+ field: D,
958
+ status: L(r).statuses[D.key] ?? "idle",
959
+ value: ((A = s.values) == null ? void 0 : A[D.key]) ?? L(r).values[D.key],
960
+ allValues: L(r).values,
961
+ typewriter: o.value,
962
+ editable: s.editable,
275
963
  locked: !1,
276
- editLabel: e.editLabel ?? c.value.editLabel,
277
- onTypingComplete: b(I),
278
- onConfirm: P,
279
- onEdit: a[1] || (a[1] = (m) => {
280
- var r, s;
281
- b(D)(m), (s = (r = e.callbacks) == null ? void 0 : r.onEdit) == null || s.call(r, m);
964
+ editLabel: s.editLabel ?? l.value.editLabel,
965
+ onTypingComplete: L(b),
966
+ onConfirm: T,
967
+ onEdit: p[1] || (p[1] = (B) => {
968
+ var F, w;
969
+ L(d)(B), (w = (F = s.callbacks) == null ? void 0 : F.onEdit) == null || w.call(F, B);
282
970
  }),
283
- onError: a[2] || (a[2] = (m, r) => {
284
- var s, w;
285
- return (w = (s = e.callbacks) == null ? void 0 : s.onError) == null ? void 0 : w.call(s, m, r);
971
+ onError: p[2] || (p[2] = (B, F) => {
972
+ var w, I;
973
+ return (I = (w = s.callbacks) == null ? void 0 : w.onError) == null ? void 0 : I.call(w, B, F);
286
974
  }),
287
- onChange: a[3] || (a[3] = (m, r) => {
288
- var s, w;
289
- return (w = (s = e.callbacks) == null ? void 0 : s.onChange) == null ? void 0 : w.call(s, m, r);
975
+ onChange: p[3] || (p[3] = (B, F) => {
976
+ var w, I;
977
+ return (I = (w = s.callbacks) == null ? void 0 : w.onChange) == null ? void 0 : I.call(w, B, F);
290
978
  }),
291
- onFocus: a[4] || (a[4] = (m) => {
292
- var r, s;
293
- return (s = (r = e.callbacks) == null ? void 0 : r.onFieldFocus) == null ? void 0 : s.call(r, m);
979
+ onFocus: p[4] || (p[4] = (B) => {
980
+ var F, w;
981
+ return (w = (F = s.callbacks) == null ? void 0 : F.onFieldFocus) == null ? void 0 : w.call(F, B);
294
982
  }),
295
- onBlur: a[5] || (a[5] = (m, r) => {
296
- var s, w;
297
- return (w = (s = e.callbacks) == null ? void 0 : s.onFieldBlur) == null ? void 0 : w.call(s, m, r);
983
+ onBlur: p[5] || (p[5] = (B, F) => {
984
+ var w, I;
985
+ return (I = (w = s.callbacks) == null ? void 0 : w.onFieldBlur) == null ? void 0 : I.call(w, B, F);
298
986
  })
299
987
  }, null, 8, ["field", "status", "value", "allValues", "typewriter", "editable", "editLabel", "onTypingComplete"]);
300
988
  }), 128))
301
- ])) : F("", !0),
302
- b(i).isComplete && u.value ? (f(), V(fe, {
989
+ ])) : K("", !0),
990
+ L(r).isComplete && a.value ? (i(), j(ke, {
303
991
  key: 2,
304
- done: u.value,
305
- values: b(i).values,
306
- meta: b(o)(),
307
- typewriter: p.value
308
- }, null, 8, ["done", "values", "meta", "typewriter"])) : F("", !0)
992
+ done: a.value,
993
+ values: L(r).values,
994
+ meta: L(h)(),
995
+ typewriter: o.value
996
+ }, null, 8, ["done", "values", "meta", "typewriter"])) : K("", !0)
309
997
  ], 512));
310
998
  }
311
- }), Be = /* @__PURE__ */ L(Se, [["__scopeId", "data-v-33050240"]]);
999
+ }), gt = /* @__PURE__ */ G(ct, [["__scopeId", "data-v-33050240"]]), ht = /* @__PURE__ */ N({
1000
+ __name: "ThemeProvider",
1001
+ props: {
1002
+ theme: { default: () => ({}) }
1003
+ },
1004
+ setup(e) {
1005
+ const s = e, t = {
1006
+ background: "--ns-bg",
1007
+ textColor: "--ns-text",
1008
+ inputBorderColor: "--ns-border",
1009
+ placeholderColor: "--ns-placeholder-color",
1010
+ errorColor: "--ns-error",
1011
+ filledColor: "--ns-filled-color",
1012
+ cursorColor: "--ns-cursor-color",
1013
+ successColor: "--ns-success-color",
1014
+ loadingColor: "--ns-loading-color",
1015
+ fontFamily: "--ns-font-family",
1016
+ uiFontFamily: "--ns-ui-font",
1017
+ fontSize: "--ns-font-size",
1018
+ mobileFontSize: "--ns-mobile-font-size",
1019
+ inputFontStyle: "--ns-input-font-style",
1020
+ lineGap: "--ns-line-gap",
1021
+ pagePadding: "--ns-page-padding",
1022
+ buttonRadius: "--ns-btn-radius",
1023
+ buttonBackground: "--ns-btn-bg",
1024
+ buttonColor: "--ns-btn-color",
1025
+ enterBtnSize: "--ns-enter-size",
1026
+ chipBorderRadius: "--ns-chip-radius",
1027
+ chipBorderColor: "--ns-chip-border",
1028
+ chipActiveBackground: "--ns-chip-active-bg",
1029
+ chipActiveColor: "--ns-chip-active-color",
1030
+ chipFontStyle: "--ns-chip-font-style"
1031
+ }, n = C(!1);
1032
+ let a = null;
1033
+ const o = (b) => {
1034
+ n.value = b.matches;
1035
+ };
1036
+ O(() => {
1037
+ typeof window < "u" && (a = window.matchMedia("(prefers-color-scheme: dark)"), n.value = a.matches, a.addEventListener("change", o));
1038
+ }), H(() => {
1039
+ a && a.removeEventListener("change", o);
1040
+ });
1041
+ const l = x(() => s.theme.mode === "dark" ? !0 : s.theme.mode === "auto" ? n.value : !1), r = x(() => l.value && s.theme.dark ? { ...s.theme, ...s.theme.dark } : s.theme), y = x(() => {
1042
+ const b = {};
1043
+ for (const [g, d] of Object.entries(t)) {
1044
+ const v = r.value[g];
1045
+ typeof v == "string" && v.length > 0 && (b[d] = v);
1046
+ }
1047
+ return b;
1048
+ });
1049
+ return J("themeContext", x(() => ({
1050
+ theme: r.value,
1051
+ isDark: l.value
1052
+ }))), (b, g) => (i(), f("div", {
1053
+ style: se(y.value),
1054
+ class: R(l.value ? "ns-root--dark" : void 0)
1055
+ }, [
1056
+ Q(b.$slots, "default")
1057
+ ], 6));
1058
+ }
1059
+ }), dt = {
1060
+ key: 0,
1061
+ class: "ns-toast-container",
1062
+ "aria-live": "polite"
1063
+ }, ft = {
1064
+ key: 0,
1065
+ class: "ns-toast-icon"
1066
+ }, mt = { class: "ns-toast-message" }, vt = ["onClick"], bt = /* @__PURE__ */ N({
1067
+ __name: "ToastProvider",
1068
+ setup(e) {
1069
+ const s = C([]), t = (a, o = !1, l = "⚠") => {
1070
+ const r = Math.random().toString(36).substring(2, 9);
1071
+ s.value.push({ id: r, message: a, icon: o, iconChar: l }), setTimeout(() => {
1072
+ s.value = s.value.filter((y) => y.id !== r);
1073
+ }, 3e3);
1074
+ }, n = (a) => {
1075
+ s.value = s.value.filter((o) => o.id !== a);
1076
+ };
1077
+ return J("toastContext", { showToast: t, hideToast: n }), (a, o) => (i(), f(P, null, [
1078
+ Q(a.$slots, "default"),
1079
+ s.value.length > 0 ? (i(), f("div", dt, [
1080
+ (i(!0), f(P, null, U(s.value, (l) => (i(), f("div", {
1081
+ key: l.id,
1082
+ class: "ns-toast ns-animate-fade-up"
1083
+ }, [
1084
+ l.icon ? (i(), f("span", ft, S(l.iconChar), 1)) : K("", !0),
1085
+ E("span", mt, S(l.message), 1),
1086
+ E("button", {
1087
+ type: "button",
1088
+ class: "ns-toast-close",
1089
+ onClick: (r) => n(l.id),
1090
+ "aria-label": "Close"
1091
+ }, " × ", 8, vt)
1092
+ ]))), 128))
1093
+ ])) : K("", !0)
1094
+ ], 64));
1095
+ }
1096
+ });
1097
+ function Ct(e) {
1098
+ const s = C(L(e.formConfig) ?? null), t = C(!!L(e.fieldsUrl) && !L(e.formConfig)), n = C(null), a = C(0);
1099
+ return q(
1100
+ [
1101
+ () => L(e.fieldsUrl),
1102
+ () => L(e.fieldsUrlHeaders),
1103
+ () => L(e.formConfig),
1104
+ a
1105
+ ],
1106
+ async ([l, r, y]) => {
1107
+ var b;
1108
+ if (y) {
1109
+ s.value = y, t.value = !1, n.value = null;
1110
+ return;
1111
+ }
1112
+ if (l) {
1113
+ t.value = !0, n.value = null;
1114
+ try {
1115
+ const g = await de(l, { headers: r });
1116
+ s.value = g;
1117
+ } catch (g) {
1118
+ const d = g instanceof Error ? g : new Error(String(g));
1119
+ n.value = d, (b = e.onFetchError) == null || b.call(e, d);
1120
+ } finally {
1121
+ t.value = !1;
1122
+ }
1123
+ }
1124
+ },
1125
+ { immediate: !0 }
1126
+ ), { config: s, loading: t, error: n, retry: () => {
1127
+ L(e.fieldsUrl) && !L(e.formConfig) && a.value++;
1128
+ } };
1129
+ }
312
1130
  export {
313
- fe as DoneScreen,
314
- ge as ErrorMessage,
315
- $e as Line,
316
- Be as NarrativeForm,
317
- ue as WelcomeScreen,
318
- se as useFormState
1131
+ Re as ChipsField,
1132
+ Be as Cursor,
1133
+ et as DateField,
1134
+ ke as DoneScreen,
1135
+ Te as EditIcon,
1136
+ nt as EmailField,
1137
+ Je as EnterButton,
1138
+ $e as ErrorMessage,
1139
+ Le as FilledValue,
1140
+ z as InlineInput,
1141
+ it as Line,
1142
+ Me as MultiChipsField,
1143
+ gt as NarrativeForm,
1144
+ lt as NumberField,
1145
+ _e as OtpField,
1146
+ Ye as PasswordField,
1147
+ Ve as Prose,
1148
+ Oe as SelectField,
1149
+ at as TelField,
1150
+ tt as TextField,
1151
+ ht as ThemeProvider,
1152
+ bt as ToastProvider,
1153
+ ge as WelcomeScreen,
1154
+ Ct as useDynamicForm,
1155
+ fe as useFormState,
1156
+ De as useTypewriter
319
1157
  };