@mieweb/forms-editor 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,698 +1,1288 @@
1
- // src/QuestionnaireEditor.jsx
2
- import React14, { useEffect as useEffect3, useRef as useRef2 } from "react";
1
+ import E, { useState as xe, useRef as rr, useEffect as ee, useMemo as re, useCallback as be } from "react";
2
+ import { useFormStore as q, useFieldsArray as Ie, useUIApi as H, EYECLOSED_ICON as Ar, EYEEDIT_ICON as Dr, PLUSSQUARE_ICON as Pr, DATALOG_ICON as Fr, X_ICON as $r, fieldTypes as le, useFormApi as tr, isVisible as Lr, getFieldComponent as Mr } from "@mieweb/forms-engine";
3
+ import { AnimatePresence as Wr, motion as K } from "framer-motion";
4
+ import qr from "js-yaml";
5
+ import './index.css';var pe = { exports: {} }, se = {};
6
+ /**
7
+ * @license React
8
+ * react-jsx-runtime.production.min.js
9
+ *
10
+ * Copyright (c) Facebook, Inc. and its affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
15
+ var ze;
16
+ function Ur() {
17
+ if (ze) return se;
18
+ ze = 1;
19
+ var t = E, n = Symbol.for("react.element"), s = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, o = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, u = { key: !0, ref: !0, __self: !0, __source: !0 };
20
+ function b(c, f, g) {
21
+ var m, p = {}, h = null, T = null;
22
+ g !== void 0 && (h = "" + g), f.key !== void 0 && (h = "" + f.key), f.ref !== void 0 && (T = f.ref);
23
+ for (m in f) i.call(f, m) && !u.hasOwnProperty(m) && (p[m] = f[m]);
24
+ if (c && c.defaultProps) for (m in f = c.defaultProps, f) p[m] === void 0 && (p[m] = f[m]);
25
+ return { $$typeof: n, type: c, key: h, ref: T, props: p, _owner: o.current };
26
+ }
27
+ return se.Fragment = s, se.jsx = b, se.jsxs = b, se;
28
+ }
29
+ var ie = {};
30
+ /**
31
+ * @license React
32
+ * react-jsx-runtime.development.js
33
+ *
34
+ * Copyright (c) Facebook, Inc. and its affiliates.
35
+ *
36
+ * This source code is licensed under the MIT license found in the
37
+ * LICENSE file in the root directory of this source tree.
38
+ */
39
+ var Ge;
40
+ function Yr() {
41
+ return Ge || (Ge = 1, process.env.NODE_ENV !== "production" && (function() {
42
+ var t = E, n = Symbol.for("react.element"), s = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), o = Symbol.for("react.strict_mode"), u = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), c = Symbol.for("react.context"), f = Symbol.for("react.forward_ref"), g = Symbol.for("react.suspense"), m = Symbol.for("react.suspense_list"), p = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), T = Symbol.for("react.offscreen"), v = Symbol.iterator, S = "@@iterator";
43
+ function k(e) {
44
+ if (e === null || typeof e != "object")
45
+ return null;
46
+ var a = v && e[v] || e[S];
47
+ return typeof a == "function" ? a : null;
48
+ }
49
+ var L = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
50
+ function _(e) {
51
+ {
52
+ for (var a = arguments.length, l = new Array(a > 1 ? a - 1 : 0), x = 1; x < a; x++)
53
+ l[x - 1] = arguments[x];
54
+ F("error", e, l);
55
+ }
56
+ }
57
+ function F(e, a, l) {
58
+ {
59
+ var x = L.ReactDebugCurrentFrame, N = x.getStackAddendum();
60
+ N !== "" && (a += "%s", l = l.concat([N]));
61
+ var R = l.map(function(w) {
62
+ return String(w);
63
+ });
64
+ R.unshift("Warning: " + a), Function.prototype.apply.call(console[e], console, R);
65
+ }
66
+ }
67
+ var O = !1, he = !1, ve = !1, ge = !1, X = !1, oe;
68
+ oe = Symbol.for("react.module.reference");
69
+ function J(e) {
70
+ return !!(typeof e == "string" || typeof e == "function" || e === i || e === u || X || e === o || e === g || e === m || ge || e === T || O || he || ve || typeof e == "object" && e !== null && (e.$$typeof === h || e.$$typeof === p || e.$$typeof === b || e.$$typeof === c || e.$$typeof === f || // This needs to include all possible module reference object
71
+ // types supported by any Flight configuration anywhere since
72
+ // we don't know which Flight build this will end up being used
73
+ // with.
74
+ e.$$typeof === oe || e.getModuleId !== void 0));
75
+ }
76
+ function ce(e, a, l) {
77
+ var x = e.displayName;
78
+ if (x)
79
+ return x;
80
+ var N = a.displayName || a.name || "";
81
+ return N !== "" ? l + "(" + N + ")" : l;
82
+ }
83
+ function te(e) {
84
+ return e.displayName || "Context";
85
+ }
86
+ function B(e) {
87
+ if (e == null)
88
+ return null;
89
+ if (typeof e.tag == "number" && _("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
90
+ return e.displayName || e.name || null;
91
+ if (typeof e == "string")
92
+ return e;
93
+ switch (e) {
94
+ case i:
95
+ return "Fragment";
96
+ case s:
97
+ return "Portal";
98
+ case u:
99
+ return "Profiler";
100
+ case o:
101
+ return "StrictMode";
102
+ case g:
103
+ return "Suspense";
104
+ case m:
105
+ return "SuspenseList";
106
+ }
107
+ if (typeof e == "object")
108
+ switch (e.$$typeof) {
109
+ case c:
110
+ var a = e;
111
+ return te(a) + ".Consumer";
112
+ case b:
113
+ var l = e;
114
+ return te(l._context) + ".Provider";
115
+ case f:
116
+ return ce(e, e.render, "ForwardRef");
117
+ case p:
118
+ var x = e.displayName || null;
119
+ return x !== null ? x : B(e.type) || "Memo";
120
+ case h: {
121
+ var N = e, R = N._payload, w = N._init;
122
+ try {
123
+ return B(w(R));
124
+ } catch {
125
+ return null;
126
+ }
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+ var d = Object.assign, C = 0, I, Y, A, U, y, z, ne;
132
+ function ye() {
133
+ }
134
+ ye.__reactDisabledLog = !0;
135
+ function je() {
136
+ {
137
+ if (C === 0) {
138
+ I = console.log, Y = console.info, A = console.warn, U = console.error, y = console.group, z = console.groupCollapsed, ne = console.groupEnd;
139
+ var e = {
140
+ configurable: !0,
141
+ enumerable: !0,
142
+ value: ye,
143
+ writable: !0
144
+ };
145
+ Object.defineProperties(console, {
146
+ info: e,
147
+ log: e,
148
+ warn: e,
149
+ error: e,
150
+ group: e,
151
+ groupCollapsed: e,
152
+ groupEnd: e
153
+ });
154
+ }
155
+ C++;
156
+ }
157
+ }
158
+ function lr() {
159
+ {
160
+ if (C--, C === 0) {
161
+ var e = {
162
+ configurable: !0,
163
+ enumerable: !0,
164
+ writable: !0
165
+ };
166
+ Object.defineProperties(console, {
167
+ log: d({}, e, {
168
+ value: I
169
+ }),
170
+ info: d({}, e, {
171
+ value: Y
172
+ }),
173
+ warn: d({}, e, {
174
+ value: A
175
+ }),
176
+ error: d({}, e, {
177
+ value: U
178
+ }),
179
+ group: d({}, e, {
180
+ value: y
181
+ }),
182
+ groupCollapsed: d({}, e, {
183
+ value: z
184
+ }),
185
+ groupEnd: d({}, e, {
186
+ value: ne
187
+ })
188
+ });
189
+ }
190
+ C < 0 && _("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
191
+ }
192
+ }
193
+ var we = L.ReactCurrentDispatcher, Ee;
194
+ function de(e, a, l) {
195
+ {
196
+ if (Ee === void 0)
197
+ try {
198
+ throw Error();
199
+ } catch (N) {
200
+ var x = N.stack.trim().match(/\n( *(at )?)/);
201
+ Ee = x && x[1] || "";
202
+ }
203
+ return `
204
+ ` + Ee + e;
205
+ }
206
+ }
207
+ var ke = !1, ue;
208
+ {
209
+ var or = typeof WeakMap == "function" ? WeakMap : Map;
210
+ ue = new or();
211
+ }
212
+ function Oe(e, a) {
213
+ if (!e || ke)
214
+ return "";
215
+ {
216
+ var l = ue.get(e);
217
+ if (l !== void 0)
218
+ return l;
219
+ }
220
+ var x;
221
+ ke = !0;
222
+ var N = Error.prepareStackTrace;
223
+ Error.prepareStackTrace = void 0;
224
+ var R;
225
+ R = we.current, we.current = null, je();
226
+ try {
227
+ if (a) {
228
+ var w = function() {
229
+ throw Error();
230
+ };
231
+ if (Object.defineProperty(w.prototype, "props", {
232
+ set: function() {
233
+ throw Error();
234
+ }
235
+ }), typeof Reflect == "object" && Reflect.construct) {
236
+ try {
237
+ Reflect.construct(w, []);
238
+ } catch (W) {
239
+ x = W;
240
+ }
241
+ Reflect.construct(e, [], w);
242
+ } else {
243
+ try {
244
+ w.call();
245
+ } catch (W) {
246
+ x = W;
247
+ }
248
+ e.call(w.prototype);
249
+ }
250
+ } else {
251
+ try {
252
+ throw Error();
253
+ } catch (W) {
254
+ x = W;
255
+ }
256
+ e();
257
+ }
258
+ } catch (W) {
259
+ if (W && x && typeof W.stack == "string") {
260
+ for (var j = W.stack.split(`
261
+ `), M = x.stack.split(`
262
+ `), D = j.length - 1, P = M.length - 1; D >= 1 && P >= 0 && j[D] !== M[P]; )
263
+ P--;
264
+ for (; D >= 1 && P >= 0; D--, P--)
265
+ if (j[D] !== M[P]) {
266
+ if (D !== 1 || P !== 1)
267
+ do
268
+ if (D--, P--, P < 0 || j[D] !== M[P]) {
269
+ var V = `
270
+ ` + j[D].replace(" at new ", " at ");
271
+ return e.displayName && V.includes("<anonymous>") && (V = V.replace("<anonymous>", e.displayName)), typeof e == "function" && ue.set(e, V), V;
272
+ }
273
+ while (D >= 1 && P >= 0);
274
+ break;
275
+ }
276
+ }
277
+ } finally {
278
+ ke = !1, we.current = R, lr(), Error.prepareStackTrace = N;
279
+ }
280
+ var Z = e ? e.displayName || e.name : "", G = Z ? de(Z) : "";
281
+ return typeof e == "function" && ue.set(e, G), G;
282
+ }
283
+ function cr(e, a, l) {
284
+ return Oe(e, !1);
285
+ }
286
+ function dr(e) {
287
+ var a = e.prototype;
288
+ return !!(a && a.isReactComponent);
289
+ }
290
+ function fe(e, a, l) {
291
+ if (e == null)
292
+ return "";
293
+ if (typeof e == "function")
294
+ return Oe(e, dr(e));
295
+ if (typeof e == "string")
296
+ return de(e);
297
+ switch (e) {
298
+ case g:
299
+ return de("Suspense");
300
+ case m:
301
+ return de("SuspenseList");
302
+ }
303
+ if (typeof e == "object")
304
+ switch (e.$$typeof) {
305
+ case f:
306
+ return cr(e.render);
307
+ case p:
308
+ return fe(e.type, a, l);
309
+ case h: {
310
+ var x = e, N = x._payload, R = x._init;
311
+ try {
312
+ return fe(R(N), a, l);
313
+ } catch {
314
+ }
315
+ }
316
+ }
317
+ return "";
318
+ }
319
+ var ae = Object.prototype.hasOwnProperty, Ae = {}, De = L.ReactDebugCurrentFrame;
320
+ function me(e) {
321
+ if (e) {
322
+ var a = e._owner, l = fe(e.type, e._source, a ? a.type : null);
323
+ De.setExtraStackFrame(l);
324
+ } else
325
+ De.setExtraStackFrame(null);
326
+ }
327
+ function ur(e, a, l, x, N) {
328
+ {
329
+ var R = Function.call.bind(ae);
330
+ for (var w in e)
331
+ if (R(e, w)) {
332
+ var j = void 0;
333
+ try {
334
+ if (typeof e[w] != "function") {
335
+ var M = Error((x || "React class") + ": " + l + " type `" + w + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[w] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
336
+ throw M.name = "Invariant Violation", M;
337
+ }
338
+ j = e[w](a, w, x, l, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
339
+ } catch (D) {
340
+ j = D;
341
+ }
342
+ j && !(j instanceof Error) && (me(N), _("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", x || "React class", l, w, typeof j), me(null)), j instanceof Error && !(j.message in Ae) && (Ae[j.message] = !0, me(N), _("Failed %s type: %s", l, j.message), me(null));
343
+ }
344
+ }
345
+ }
346
+ var fr = Array.isArray;
347
+ function Ne(e) {
348
+ return fr(e);
349
+ }
350
+ function mr(e) {
351
+ {
352
+ var a = typeof Symbol == "function" && Symbol.toStringTag, l = a && e[Symbol.toStringTag] || e.constructor.name || "Object";
353
+ return l;
354
+ }
355
+ }
356
+ function pr(e) {
357
+ try {
358
+ return Pe(e), !1;
359
+ } catch {
360
+ return !0;
361
+ }
362
+ }
363
+ function Pe(e) {
364
+ return "" + e;
365
+ }
366
+ function Fe(e) {
367
+ if (pr(e))
368
+ return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", mr(e)), Pe(e);
369
+ }
370
+ var $e = L.ReactCurrentOwner, br = {
371
+ key: !0,
372
+ ref: !0,
373
+ __self: !0,
374
+ __source: !0
375
+ }, Le, Me;
376
+ function xr(e) {
377
+ if (ae.call(e, "ref")) {
378
+ var a = Object.getOwnPropertyDescriptor(e, "ref").get;
379
+ if (a && a.isReactWarning)
380
+ return !1;
381
+ }
382
+ return e.ref !== void 0;
383
+ }
384
+ function hr(e) {
385
+ if (ae.call(e, "key")) {
386
+ var a = Object.getOwnPropertyDescriptor(e, "key").get;
387
+ if (a && a.isReactWarning)
388
+ return !1;
389
+ }
390
+ return e.key !== void 0;
391
+ }
392
+ function vr(e, a) {
393
+ typeof e.ref == "string" && $e.current;
394
+ }
395
+ function gr(e, a) {
396
+ {
397
+ var l = function() {
398
+ Le || (Le = !0, _("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", a));
399
+ };
400
+ l.isReactWarning = !0, Object.defineProperty(e, "key", {
401
+ get: l,
402
+ configurable: !0
403
+ });
404
+ }
405
+ }
406
+ function yr(e, a) {
407
+ {
408
+ var l = function() {
409
+ Me || (Me = !0, _("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", a));
410
+ };
411
+ l.isReactWarning = !0, Object.defineProperty(e, "ref", {
412
+ get: l,
413
+ configurable: !0
414
+ });
415
+ }
416
+ }
417
+ var jr = function(e, a, l, x, N, R, w) {
418
+ var j = {
419
+ // This tag allows us to uniquely identify this as a React Element
420
+ $$typeof: n,
421
+ // Built-in properties that belong on the element
422
+ type: e,
423
+ key: a,
424
+ ref: l,
425
+ props: w,
426
+ // Record the component responsible for creating this element.
427
+ _owner: R
428
+ };
429
+ return j._store = {}, Object.defineProperty(j._store, "validated", {
430
+ configurable: !1,
431
+ enumerable: !1,
432
+ writable: !0,
433
+ value: !1
434
+ }), Object.defineProperty(j, "_self", {
435
+ configurable: !1,
436
+ enumerable: !1,
437
+ writable: !1,
438
+ value: x
439
+ }), Object.defineProperty(j, "_source", {
440
+ configurable: !1,
441
+ enumerable: !1,
442
+ writable: !1,
443
+ value: N
444
+ }), Object.freeze && (Object.freeze(j.props), Object.freeze(j)), j;
445
+ };
446
+ function wr(e, a, l, x, N) {
447
+ {
448
+ var R, w = {}, j = null, M = null;
449
+ l !== void 0 && (Fe(l), j = "" + l), hr(a) && (Fe(a.key), j = "" + a.key), xr(a) && (M = a.ref, vr(a, N));
450
+ for (R in a)
451
+ ae.call(a, R) && !br.hasOwnProperty(R) && (w[R] = a[R]);
452
+ if (e && e.defaultProps) {
453
+ var D = e.defaultProps;
454
+ for (R in D)
455
+ w[R] === void 0 && (w[R] = D[R]);
456
+ }
457
+ if (j || M) {
458
+ var P = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
459
+ j && gr(w, P), M && yr(w, P);
460
+ }
461
+ return jr(e, j, M, N, x, $e.current, w);
462
+ }
463
+ }
464
+ var Ce = L.ReactCurrentOwner, We = L.ReactDebugCurrentFrame;
465
+ function Q(e) {
466
+ if (e) {
467
+ var a = e._owner, l = fe(e.type, e._source, a ? a.type : null);
468
+ We.setExtraStackFrame(l);
469
+ } else
470
+ We.setExtraStackFrame(null);
471
+ }
472
+ var Re;
473
+ Re = !1;
474
+ function Te(e) {
475
+ return typeof e == "object" && e !== null && e.$$typeof === n;
476
+ }
477
+ function qe() {
478
+ {
479
+ if (Ce.current) {
480
+ var e = B(Ce.current.type);
481
+ if (e)
482
+ return `
3
483
 
4
- // src/components/Header.jsx
5
- import React2, { useState } from "react";
6
- import { useFormStore, useFieldsArray, useUIApi, useUIStore } from "@mieweb/forms-engine";
484
+ Check the render method of \`` + e + "`.";
485
+ }
486
+ return "";
487
+ }
488
+ }
489
+ function Er(e) {
490
+ return "";
491
+ }
492
+ var Ue = {};
493
+ function kr(e) {
494
+ {
495
+ var a = qe();
496
+ if (!a) {
497
+ var l = typeof e == "string" ? e : e.displayName || e.name;
498
+ l && (a = `
7
499
 
8
- // src/components/DataViewer.jsx
9
- import React from "react";
10
- import { AnimatePresence, motion } from "framer-motion";
11
- import yaml from "js-yaml";
12
- function DataViewer({
13
- open,
14
- onClose,
15
- data,
16
- title = "Data Viewer",
17
- placement = "center",
500
+ Check the top-level render call using <` + l + ">.");
501
+ }
502
+ return a;
503
+ }
504
+ }
505
+ function Ye(e, a) {
506
+ {
507
+ if (!e._store || e._store.validated || e.key != null)
508
+ return;
509
+ e._store.validated = !0;
510
+ var l = kr(a);
511
+ if (Ue[l])
512
+ return;
513
+ Ue[l] = !0;
514
+ var x = "";
515
+ e && e._owner && e._owner !== Ce.current && (x = " It was passed a child from " + B(e._owner.type) + "."), Q(e), _('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', l, x), Q(null);
516
+ }
517
+ }
518
+ function Ve(e, a) {
519
+ {
520
+ if (typeof e != "object")
521
+ return;
522
+ if (Ne(e))
523
+ for (var l = 0; l < e.length; l++) {
524
+ var x = e[l];
525
+ Te(x) && Ye(x, a);
526
+ }
527
+ else if (Te(e))
528
+ e._store && (e._store.validated = !0);
529
+ else if (e) {
530
+ var N = k(e);
531
+ if (typeof N == "function" && N !== e.entries)
532
+ for (var R = N.call(e), w; !(w = R.next()).done; )
533
+ Te(w.value) && Ye(w.value, a);
534
+ }
535
+ }
536
+ }
537
+ function Nr(e) {
538
+ {
539
+ var a = e.type;
540
+ if (a == null || typeof a == "string")
541
+ return;
542
+ var l;
543
+ if (typeof a == "function")
544
+ l = a.propTypes;
545
+ else if (typeof a == "object" && (a.$$typeof === f || // Note: Memo only checks outer props here.
546
+ // Inner props are checked in the reconciler.
547
+ a.$$typeof === p))
548
+ l = a.propTypes;
549
+ else
550
+ return;
551
+ if (l) {
552
+ var x = B(a);
553
+ ur(l, e.props, "prop", x, e);
554
+ } else if (a.PropTypes !== void 0 && !Re) {
555
+ Re = !0;
556
+ var N = B(a);
557
+ _("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", N || "Unknown");
558
+ }
559
+ typeof a.getDefaultProps == "function" && !a.getDefaultProps.isReactClassApproved && _("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
560
+ }
561
+ }
562
+ function Cr(e) {
563
+ {
564
+ for (var a = Object.keys(e.props), l = 0; l < a.length; l++) {
565
+ var x = a[l];
566
+ if (x !== "children" && x !== "key") {
567
+ Q(e), _("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", x), Q(null);
568
+ break;
569
+ }
570
+ }
571
+ e.ref !== null && (Q(e), _("Invalid attribute `ref` supplied to `React.Fragment`."), Q(null));
572
+ }
573
+ }
574
+ var Be = {};
575
+ function Je(e, a, l, x, N, R) {
576
+ {
577
+ var w = J(e);
578
+ if (!w) {
579
+ var j = "";
580
+ (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (j += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
581
+ var M = Er();
582
+ M ? j += M : j += qe();
583
+ var D;
584
+ e === null ? D = "null" : Ne(e) ? D = "array" : e !== void 0 && e.$$typeof === n ? (D = "<" + (B(e.type) || "Unknown") + " />", j = " Did you accidentally export a JSX literal instead of a component?") : D = typeof e, _("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", D, j);
585
+ }
586
+ var P = wr(e, a, l, N, R);
587
+ if (P == null)
588
+ return P;
589
+ if (w) {
590
+ var V = a.children;
591
+ if (V !== void 0)
592
+ if (x)
593
+ if (Ne(V)) {
594
+ for (var Z = 0; Z < V.length; Z++)
595
+ Ve(V[Z], e);
596
+ Object.freeze && Object.freeze(V);
597
+ } else
598
+ _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
599
+ else
600
+ Ve(V, e);
601
+ }
602
+ if (ae.call(a, "key")) {
603
+ var G = B(e), W = Object.keys(a).filter(function(Or) {
604
+ return Or !== "key";
605
+ }), Se = W.length > 0 ? "{key: someKey, " + W.join(": ..., ") + ": ...}" : "{key: someKey}";
606
+ if (!Be[G + Se]) {
607
+ var Ir = W.length > 0 ? "{" + W.join(": ..., ") + ": ...}" : "{}";
608
+ _(`A props object containing a "key" prop is being spread into JSX:
609
+ let props = %s;
610
+ <%s {...props} />
611
+ React keys must be passed directly to JSX without using spread:
612
+ let props = %s;
613
+ <%s key={someKey} {...props} />`, Se, G, Ir, G), Be[G + Se] = !0;
614
+ }
615
+ }
616
+ return e === i ? Cr(P) : Nr(P), P;
617
+ }
618
+ }
619
+ function Rr(e, a, l) {
620
+ return Je(e, a, l, !0);
621
+ }
622
+ function Tr(e, a, l) {
623
+ return Je(e, a, l, !1);
624
+ }
625
+ var Sr = Tr, _r = Rr;
626
+ ie.Fragment = i, ie.jsx = Sr, ie.jsxs = _r;
627
+ })()), ie;
628
+ }
629
+ var Ke;
630
+ function Vr() {
631
+ return Ke || (Ke = 1, process.env.NODE_ENV === "production" ? pe.exports = Ur() : pe.exports = Yr()), pe.exports;
632
+ }
633
+ var r = Vr();
634
+ function nr({
635
+ open: t,
636
+ onClose: n,
637
+ data: s,
638
+ title: i = "Data Viewer",
639
+ placement: o = "center",
18
640
  // "center" | "bottom"
19
- pretty = 2,
20
- defaultMode = "yaml",
641
+ pretty: u = 2,
642
+ defaultMode: b = "yaml",
21
643
  // "json" | "yaml"
22
- fileBaseName = "form-data",
23
- contentClassName = ""
644
+ fileBaseName: c = "form-data",
645
+ contentClassName: f = ""
24
646
  }) {
25
- const isCenter = placement === "center";
26
- const [mode, setMode] = React.useState(defaultMode === "yaml" ? "yaml" : "json");
27
- const viewerText = React.useMemo(() => {
28
- const indent = Math.max(2, pretty | 0);
647
+ const g = o === "center", [m, p] = E.useState(b === "yaml" ? "yaml" : "json"), h = E.useMemo(() => {
648
+ const k = Math.max(2, u | 0);
29
649
  try {
30
- return mode === "yaml" ? yaml.dump(data ?? {}, {
31
- indent,
650
+ return m === "yaml" ? qr.dump(s ?? {}, {
651
+ indent: k,
32
652
  lineWidth: 80,
33
- noRefs: true,
34
- forceQuotes: true,
35
- skipInvalid: true
36
- }) : JSON.stringify(data ?? {}, null, indent);
653
+ noRefs: !0,
654
+ forceQuotes: !0,
655
+ skipInvalid: !0
656
+ }) : JSON.stringify(s ?? {}, null, k);
37
657
  } catch {
38
- return mode === "yaml" ? "# Failed to render YAML" : String(data);
658
+ return m === "yaml" ? "# Failed to render YAML" : String(s);
39
659
  }
40
- }, [data, mode, pretty]);
41
- const stop = (e) => e.stopPropagation();
42
- const download = (e) => {
43
- stop(e);
44
- const isYaml = mode === "yaml";
45
- const blob = new Blob([viewerText], { type: isYaml ? "text/yaml" : "application/json" });
46
- const url = URL.createObjectURL(blob);
47
- const a = document.createElement("a");
48
- a.href = url;
49
- a.download = `${fileBaseName}.${isYaml ? "yml" : "json"}`;
50
- a.click();
51
- URL.revokeObjectURL(url);
52
- };
53
- const copy = async (e) => {
54
- stop(e);
660
+ }, [s, m, u]), T = (k) => k.stopPropagation(), v = (k) => {
661
+ T(k);
662
+ const L = m === "yaml", _ = new Blob([h], { type: L ? "text/yaml" : "application/json" }), F = URL.createObjectURL(_), O = document.createElement("a");
663
+ O.href = F, O.download = `${c}.${L ? "yml" : "json"}`, O.click(), URL.revokeObjectURL(F);
664
+ }, S = async (k) => {
665
+ T(k);
55
666
  try {
56
- await navigator.clipboard.writeText(viewerText);
667
+ await navigator.clipboard.writeText(h);
57
668
  } catch {
58
669
  }
59
670
  };
60
- return /* @__PURE__ */ React.createElement(AnimatePresence, null, open && /* @__PURE__ */ React.createElement(
61
- motion.div,
671
+ return /* @__PURE__ */ r.jsx(Wr, { children: t && /* @__PURE__ */ r.jsx(
672
+ K.div,
62
673
  {
63
674
  className: "fixed inset-0 z-[60] flex items-center justify-center",
64
675
  initial: { opacity: 0 },
65
676
  animate: { opacity: 1 },
66
677
  exit: { opacity: 0 },
67
- onMouseDown: onClose,
678
+ onMouseDown: n,
68
679
  "aria-modal": "true",
69
- role: "dialog"
70
- },
71
- /* @__PURE__ */ React.createElement("div", { className: "w-full h-full flex items-end sm:items-center justify-center sm:max-w-4xl" }, /* @__PURE__ */ React.createElement(
72
- motion.div,
73
- {
74
- onMouseDown: stop,
75
- initial: { y: isCenter ? 20 : "100%", opacity: isCenter ? 0 : 1, scale: isCenter ? 0.98 : 1 },
76
- animate: { y: 0, opacity: 1, scale: 1 },
77
- exit: { y: isCenter ? 20 : "100%", opacity: isCenter ? 0 : 1, scale: isCenter ? 0.98 : 1 },
78
- transition: { type: "spring", stiffness: 160, damping: 20 },
79
- className: isCenter ? "w-full sm:max-w-2xl sm:rounded-2xl rounded-t-2xl bg-white shadow-lg border border-black/10 max-h-[80vh] overflow-hidden" : "w-full mx-auto bg-black/5 border border-black/15 px-6 py-4 rounded-2xl backdrop-blur-xl overflow-hidden"
80
- },
81
- /* @__PURE__ */ React.createElement("div", { className: `flex items-center justify-between ${isCenter ? "px-4 py-3 border-b border-black/10" : ""}` }, /* @__PURE__ */ React.createElement("h3", { className: "font-semibold" }, title, " (", mode.toUpperCase(), ")"), /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement("div", { className: "inline-flex rounded-lg border border-black/10 overflow-hidden" }, /* @__PURE__ */ React.createElement(
82
- "button",
680
+ role: "dialog",
681
+ children: /* @__PURE__ */ r.jsx("div", { className: "w-full h-full flex items-end sm:items-center justify-center sm:max-w-4xl", children: /* @__PURE__ */ r.jsxs(
682
+ K.div,
83
683
  {
84
- className: `px-3 py-1 text-sm ${mode === "yaml" ? "bg-black/6" : "bg-gray-200 hover:bg-black/5"}`,
85
- "aria-pressed": mode === "yaml",
86
- onClick: (e) => {
87
- stop(e);
88
- setMode("yaml");
89
- }
90
- },
91
- "YAML"
92
- ), /* @__PURE__ */ React.createElement(
93
- "button",
94
- {
95
- className: `px-3 py-1 text-sm ${mode === "json" ? "bg-black/6" : "bg-gray-200 hover:bg-black/5"}`,
96
- "aria-pressed": mode === "json",
97
- onClick: (e) => {
98
- stop(e);
99
- setMode("json");
100
- }
101
- },
102
- "JSON"
103
- )), /* @__PURE__ */ React.createElement("button", { className: "px-3 py-1 rounded-lg border border-black/10 hover:bg-black/5 text-sm", onClick: copy }, "Copy"), /* @__PURE__ */ React.createElement("button", { className: "px-3 py-1 rounded-lg border border-black/10 hover:bg-black/5 text-sm", onClick: download }, "Download"), /* @__PURE__ */ React.createElement(
104
- "button",
105
- {
106
- className: "px-3 py-1 rounded-lg border border-black/10 hover:bg-black/5 text-sm",
107
- onClick: (e) => {
108
- stop(e);
109
- onClose == null ? void 0 : onClose();
110
- }
111
- },
112
- "Close"
113
- ))),
114
- /* @__PURE__ */ React.createElement("div", { className: isCenter ? `p-4 overflow-auto max-h-[70vh] ${contentClassName}` : `mt-2 p-2 rounded-lg overflow-y-auto max-h-96 ${contentClassName}` }, /* @__PURE__ */ React.createElement("pre", { className: "whitespace-pre-wrap break-words text-sm text-gray-700" }, viewerText))
115
- ))
116
- ));
684
+ onMouseDown: T,
685
+ initial: { y: g ? 20 : "100%", opacity: g ? 0 : 1, scale: g ? 0.98 : 1 },
686
+ animate: { y: 0, opacity: 1, scale: 1 },
687
+ exit: { y: g ? 20 : "100%", opacity: g ? 0 : 1, scale: g ? 0.98 : 1 },
688
+ transition: { type: "spring", stiffness: 160, damping: 20 },
689
+ className: g ? "w-full sm:max-w-2xl sm:rounded-2xl rounded-t-2xl bg-white shadow-lg border border-black/10 max-h-[80vh] overflow-hidden" : "w-full mx-auto bg-black/5 border border-black/15 px-6 py-4 rounded-2xl backdrop-blur-xl overflow-hidden",
690
+ children: [
691
+ /* @__PURE__ */ r.jsxs("div", { className: `flex items-center justify-between ${g ? "px-4 py-3 border-b border-black/10" : ""}`, children: [
692
+ /* @__PURE__ */ r.jsxs("h3", { className: "font-semibold", children: [
693
+ i,
694
+ " (",
695
+ m.toUpperCase(),
696
+ ")"
697
+ ] }),
698
+ /* @__PURE__ */ r.jsxs("div", { className: "flex items-center gap-2", children: [
699
+ /* @__PURE__ */ r.jsxs("div", { className: "inline-flex rounded-lg border border-black/10 overflow-hidden", children: [
700
+ /* @__PURE__ */ r.jsx(
701
+ "button",
702
+ {
703
+ className: `px-3 py-1 text-sm ${m === "yaml" ? "bg-black/6" : "bg-gray-200 hover:bg-black/5"}`,
704
+ "aria-pressed": m === "yaml",
705
+ onClick: (k) => {
706
+ T(k), p("yaml");
707
+ },
708
+ children: "YAML"
709
+ }
710
+ ),
711
+ /* @__PURE__ */ r.jsx(
712
+ "button",
713
+ {
714
+ className: `px-3 py-1 text-sm ${m === "json" ? "bg-black/6" : "bg-gray-200 hover:bg-black/5"}`,
715
+ "aria-pressed": m === "json",
716
+ onClick: (k) => {
717
+ T(k), p("json");
718
+ },
719
+ children: "JSON"
720
+ }
721
+ )
722
+ ] }),
723
+ /* @__PURE__ */ r.jsx("button", { className: "px-3 py-1 rounded-lg border border-black/10 hover:bg-black/5 text-sm", onClick: S, children: "Copy" }),
724
+ /* @__PURE__ */ r.jsx("button", { className: "px-3 py-1 rounded-lg border border-black/10 hover:bg-black/5 text-sm", onClick: v, children: "Download" }),
725
+ /* @__PURE__ */ r.jsx(
726
+ "button",
727
+ {
728
+ className: "px-3 py-1 rounded-lg border border-black/10 hover:bg-black/5 text-sm",
729
+ onClick: (k) => {
730
+ T(k), n == null || n();
731
+ },
732
+ children: "Close"
733
+ }
734
+ )
735
+ ] })
736
+ ] }),
737
+ /* @__PURE__ */ r.jsx("div", { className: g ? `p-4 overflow-auto max-h-[70vh] ${f}` : `mt-2 p-2 rounded-lg overflow-y-auto max-h-96 ${f}`, children: /* @__PURE__ */ r.jsx("pre", { className: "whitespace-pre-wrap break-words text-sm text-gray-700", children: h }) })
738
+ ]
739
+ }
740
+ ) })
741
+ }
742
+ ) });
117
743
  }
118
-
119
- // src/components/Header.jsx
120
- function Header() {
121
- const [showData, setShowData] = useState(false);
122
- const replaceAll = useFormStore((s) => s.replaceAll);
123
- const fieldsArray = useFieldsArray();
124
- const ui = useUIApi();
125
- const isPreview = ui.state.isPreview;
126
- const importData = (data) => {
744
+ function Br() {
745
+ const [t, n] = xe(!1), s = q((g) => g.replaceAll), i = Ie(), o = H(), u = o.state.isPreview, b = (g) => {
127
746
  try {
128
- const text = String(data).replace(/^\uFEFF/, "").trim();
129
- const parsed = JSON.parse(text);
130
- const arr = Array.isArray(parsed) ? parsed : parsed == null ? void 0 : parsed.fields;
131
- if (!Array.isArray(arr)) throw new Error("Expected [] or { fields: [] }");
132
- replaceAll(arr);
133
- ui.selectedFieldId.clear();
134
- ui.preview.set(false);
135
- } catch (err) {
136
- alert((err == null ? void 0 : err.message) || "Invalid JSON format");
747
+ const m = String(g).replace(/^\uFEFF/, "").trim(), p = JSON.parse(m), h = Array.isArray(p) ? p : p == null ? void 0 : p.fields;
748
+ if (!Array.isArray(h)) throw new Error("Expected [] or { fields: [] }");
749
+ s(h), o.selectedFieldId.clear(), o.preview.set(!1);
750
+ } catch (m) {
751
+ alert((m == null ? void 0 : m.message) || "Invalid JSON format");
137
752
  }
753
+ }, c = () => {
754
+ o.preview.set(!0), o.selectedFieldId.clear();
755
+ }, f = () => {
756
+ o.preview.set(!1);
138
757
  };
139
- const onPreview = () => {
140
- ui.preview.set(true);
141
- ui.selectedFieldId.clear();
142
- };
143
- const onEdit = () => {
144
- ui.preview.set(false);
145
- };
146
- return /* @__PURE__ */ React2.createElement("header", { className: "sticky top-0 z-49 bg-transparent mx-auto" }, /* @__PURE__ */ React2.createElement("div", { className: "py-6 text-center" }, /* @__PURE__ */ React2.createElement("h1", { className: "text-3xl sm:text-4xl tracking-tight" }, "Questionnaire Builder"), /* @__PURE__ */ React2.createElement("p", { className: "mt-1 text-sm text-black/60" }, "Build dynamic questionnaires with JSON config and FHIR export")), /* @__PURE__ */ React2.createElement("div", { className: "max-w-6xl mx-auto px-4" }, /* @__PURE__ */ React2.createElement("div", { className: "grid grid-cols-2 rounded-xl border border-black/10 bg-white shadow-sm" }, /* @__PURE__ */ React2.createElement(
147
- "button",
148
- {
149
- className: `py-3 rounded-xl text-sm font-medium ${!isPreview ? "bg-black/5" : ""}`,
150
- onClick: onEdit
151
- },
152
- "Builder"
153
- ), /* @__PURE__ */ React2.createElement(
154
- "button",
155
- {
156
- className: `py-3 rounded-xl text-sm font-medium ${isPreview ? "bg-black/5" : ""}`,
157
- onClick: onPreview
158
- },
159
- "Preview"
160
- )), /* @__PURE__ */ React2.createElement("div", { className: "mt-4 flex flex-wrap gap-2 items-center justify-end" }, /* @__PURE__ */ React2.createElement("label", { className: "px-4 py-2 rounded-xl border border-black/15 bg-white hover:bg-black/5 cursor-pointer text-sm" }, "Import", /* @__PURE__ */ React2.createElement(
161
- "input",
162
- {
163
- className: "hidden",
164
- type: "file",
165
- accept: ".json,application/json",
166
- onChange: (e) => {
167
- var _a;
168
- const file = (_a = e.target.files) == null ? void 0 : _a[0];
169
- if (!file) return;
170
- const reader = new FileReader();
171
- reader.onload = (ev) => {
172
- var _a2;
173
- return importData(((_a2 = ev.target) == null ? void 0 : _a2.result) ?? "");
174
- };
175
- reader.readAsText(file);
176
- e.target.value = "";
758
+ return /* @__PURE__ */ r.jsxs("header", { className: "sticky top-0 z-49 bg-transparent mx-auto", children: [
759
+ /* @__PURE__ */ r.jsxs("div", { className: "py-6 text-center", children: [
760
+ /* @__PURE__ */ r.jsx("h1", { className: "text-3xl sm:text-4xl tracking-tight", children: "Questionnaire Builder" }),
761
+ /* @__PURE__ */ r.jsx("p", { className: "mt-1 text-sm text-black/60", children: "Build dynamic questionnaires with JSON config and FHIR export" })
762
+ ] }),
763
+ /* @__PURE__ */ r.jsxs("div", { className: "max-w-6xl mx-auto px-4", children: [
764
+ /* @__PURE__ */ r.jsxs("div", { className: "grid grid-cols-2 rounded-xl border border-black/10 bg-white shadow-sm", children: [
765
+ /* @__PURE__ */ r.jsx(
766
+ "button",
767
+ {
768
+ className: `py-3 rounded-xl text-sm font-medium ${u ? "" : "bg-black/10"}`,
769
+ onClick: f,
770
+ children: "Builder"
771
+ }
772
+ ),
773
+ /* @__PURE__ */ r.jsx(
774
+ "button",
775
+ {
776
+ className: `py-3 rounded-xl text-sm font-medium ${u ? "bg-black/10" : ""}`,
777
+ onClick: c,
778
+ children: "Preview"
779
+ }
780
+ )
781
+ ] }),
782
+ /* @__PURE__ */ r.jsxs("div", { className: "mt-4 flex flex-wrap gap-2 items-center justify-end", children: [
783
+ /* @__PURE__ */ r.jsxs("label", { className: "px-4 py-2 rounded-xl border border-black/15 bg-white hover:bg-black/5 cursor-pointer text-sm", children: [
784
+ "Import",
785
+ /* @__PURE__ */ r.jsx(
786
+ "input",
787
+ {
788
+ className: "hidden",
789
+ type: "file",
790
+ accept: ".json,application/json",
791
+ onChange: (g) => {
792
+ var h;
793
+ const m = (h = g.target.files) == null ? void 0 : h[0];
794
+ if (!m) return;
795
+ const p = new FileReader();
796
+ p.onload = (T) => {
797
+ var v;
798
+ return b(((v = T.target) == null ? void 0 : v.result) ?? "");
799
+ }, p.readAsText(m), g.target.value = "";
800
+ }
801
+ }
802
+ )
803
+ ] }),
804
+ /* @__PURE__ */ r.jsx(
805
+ "button",
806
+ {
807
+ className: "px-4 py-2 rounded-xl border border-black/15 bg-white hover:bg-black/5 text-sm",
808
+ onClick: () => n(!0),
809
+ children: "Data Viewer"
810
+ }
811
+ )
812
+ ] })
813
+ ] }),
814
+ /* @__PURE__ */ r.jsx(
815
+ nr,
816
+ {
817
+ open: t,
818
+ onClose: () => n(!1),
819
+ data: i,
820
+ title: "Form Data",
821
+ placement: "bottom",
822
+ contentClassName: "custom-scrollbar"
177
823
  }
178
- }
179
- )), /* @__PURE__ */ React2.createElement(
180
- "button",
181
- {
182
- className: "px-4 py-2 rounded-xl border border-black/15 bg-white hover:bg-black/5 text-sm",
183
- onClick: () => setShowData(true)
184
- },
185
- "Data Viewer"
186
- ))), /* @__PURE__ */ React2.createElement(
187
- DataViewer,
188
- {
189
- open: showData,
190
- onClose: () => setShowData(false),
191
- data: fieldsArray,
192
- title: "Form Data",
193
- placement: "bottom",
194
- contentClassName: "custom-scrollbar"
195
- }
196
- ));
824
+ )
825
+ ] });
197
826
  }
198
-
199
- // src/components/MobileToolBar.jsx
200
- import React3, { useState as useState2, useEffect, useRef } from "react";
201
- import { motion as motion2 } from "framer-motion";
202
- import { DATALOG_ICON, EYEEDIT_ICON, EYECLOSED_ICON, PLUSSQUARE_ICON, X_ICON } from "@mieweb/forms-engine";
203
- import { useFormStore as useFormStore2, useFieldsArray as useFieldsArray2, useUIApi as useUIApi2, fieldTypes } from "@mieweb/forms-engine";
204
- function MobileToolBar() {
205
- const [isToolBarExpanded, setIsToolBarExpanded] = useState2(false);
206
- const [isLogExpanded, setIsLogExpanded] = useState2(false);
207
- const containerRef = useRef(null);
208
- const addField = useFormStore2((s) => s.addField);
209
- const fieldsArray = useFieldsArray2();
210
- const ui = useUIApi2();
211
- const isPreview = ui.state.isPreview;
212
- const handleToolBarExpanded = () => {
213
- setIsToolBarExpanded((v) => !v);
214
- setIsLogExpanded(false);
827
+ function Jr() {
828
+ const [t, n] = xe(!1), [s, i] = xe(!1), o = rr(null), u = q((h) => h.addField), b = Ie(), c = H(), f = c.state.isPreview, g = () => {
829
+ n((h) => !h), i(!1);
830
+ }, m = () => {
831
+ i((h) => !h), n(!1);
832
+ }, p = () => {
833
+ c.preview.toggle(), n(!1), i(!1);
215
834
  };
216
- const handleLogExpanded = () => {
217
- setIsLogExpanded((v) => !v);
218
- setIsToolBarExpanded(false);
219
- };
220
- const handlePreviewMode = () => {
221
- ui.preview.toggle();
222
- setIsToolBarExpanded(false);
223
- setIsLogExpanded(false);
224
- };
225
- useEffect(() => {
226
- if (!isToolBarExpanded || isLogExpanded) return;
227
- const handleDocDown = (event) => {
228
- const el = containerRef.current;
229
- if (el && !el.contains(event.target)) {
230
- setIsToolBarExpanded(false);
231
- setIsLogExpanded(false);
232
- }
835
+ return ee(() => {
836
+ if (!t || s) return;
837
+ const h = (T) => {
838
+ const v = o.current;
839
+ v && !v.contains(T.target) && (n(!1), i(!1));
233
840
  };
234
- document.addEventListener("pointerdown", handleDocDown);
235
- return () => document.removeEventListener("pointerdown", handleDocDown);
236
- }, [isToolBarExpanded, isLogExpanded]);
237
- return /* @__PURE__ */ React3.createElement("div", { className: "MobileToolBar fixed bottom-0 left-0 w-full text-stone-900 shadow-lg z-10" }, /* @__PURE__ */ React3.createElement(
238
- motion2.div,
239
- {
240
- initial: { y: "100%" },
241
- animate: { y: "0%" },
242
- transition: { duration: 0.8, ease: [0.25, 0.1, 0.25, 1] },
243
- className: `flex ${!isPreview ? "justify-around" : "justify-center"} pb-5 max-w-xl sm:max-w-4xl mx-auto`
244
- },
245
- /* @__PURE__ */ React3.createElement(
246
- motion2.button,
841
+ return document.addEventListener("pointerdown", h), () => document.removeEventListener("pointerdown", h);
842
+ }, [t, s]), /* @__PURE__ */ r.jsxs("div", { className: "MobileToolBar fixed bottom-0 left-0 w-full text-stone-900 shadow-lg z-10", children: [
843
+ /* @__PURE__ */ r.jsxs(
844
+ K.div,
247
845
  {
248
- onClick: handlePreviewMode,
249
- initial: { opacity: 1, scale: 1, x: "0%" },
250
- animate: {
251
- opacity: isToolBarExpanded || isLogExpanded ? 0 : 1,
252
- scale: isToolBarExpanded || isLogExpanded ? 0 : 1,
253
- x: !isPreview ? "0%" : "120%"
254
- },
255
- className: `relative cursor-pointer ${!isPreview ? "" : "mx-29"} bg-black/5 rounded-2xl p-3 backdrop-blur-xl`
256
- },
257
- !isPreview ? /* @__PURE__ */ React3.createElement(EYECLOSED_ICON, { className: "h-12 w-12" }) : /* @__PURE__ */ React3.createElement(EYEEDIT_ICON, { className: "h-12 w-12" })
846
+ initial: { y: "100%" },
847
+ animate: { y: "0%" },
848
+ transition: { duration: 0.8, ease: [0.25, 0.1, 0.25, 1] },
849
+ className: `flex ${f ? "justify-center" : "justify-around"} pb-5 max-w-xl sm:max-w-4xl mx-auto`,
850
+ children: [
851
+ /* @__PURE__ */ r.jsx(
852
+ K.button,
853
+ {
854
+ onClick: p,
855
+ initial: { opacity: 1, scale: 1, x: "0%" },
856
+ animate: {
857
+ opacity: t || s ? 0 : 1,
858
+ scale: t || s ? 0 : 1,
859
+ x: f ? "120%" : "0%"
860
+ },
861
+ className: `relative cursor-pointer ${f ? "mx-29" : ""} bg-black/5 rounded-2xl p-3 backdrop-blur-xl`,
862
+ children: f ? /* @__PURE__ */ r.jsx(Dr, { className: "h-12 w-12" }) : /* @__PURE__ */ r.jsx(Ar, { className: "h-12 w-12" })
863
+ }
864
+ ),
865
+ !f && /* @__PURE__ */ r.jsx(
866
+ K.button,
867
+ {
868
+ onClick: g,
869
+ initial: { opacity: 1, scale: 1 },
870
+ animate: {
871
+ opacity: t || s ? 0 : 1,
872
+ scale: t || s ? 0 : 1
873
+ },
874
+ className: "relative cursor-pointer bg-black/5 rounded-2xl p-3 backdrop-blur-xl",
875
+ children: /* @__PURE__ */ r.jsx(Pr, { className: "h-12 w-12" })
876
+ }
877
+ ),
878
+ /* @__PURE__ */ r.jsx(
879
+ K.button,
880
+ {
881
+ onClick: m,
882
+ initial: { opacity: 1, scale: 1, x: "0%" },
883
+ animate: {
884
+ opacity: s || t ? 0 : 1,
885
+ scale: s || t ? 0 : 1,
886
+ x: f ? "-120%" : "0%"
887
+ },
888
+ className: `relative cursor-pointer ${f ? "mx-29" : ""} bg-black/5 rounded-2xl p-3 backdrop-blur-xl`,
889
+ children: /* @__PURE__ */ r.jsx(Fr, { className: "h-12 w-12" })
890
+ }
891
+ )
892
+ ]
893
+ }
258
894
  ),
259
- !isPreview && /* @__PURE__ */ React3.createElement(
260
- motion2.button,
895
+ /* @__PURE__ */ r.jsx(
896
+ nr,
261
897
  {
262
- onClick: handleToolBarExpanded,
263
- initial: { opacity: 1, scale: 1 },
264
- animate: {
265
- opacity: isToolBarExpanded || isLogExpanded ? 0 : 1,
266
- scale: isToolBarExpanded || isLogExpanded ? 0 : 1
267
- },
268
- className: "relative cursor-pointer bg-black/5 rounded-2xl p-3 backdrop-blur-xl"
269
- },
270
- /* @__PURE__ */ React3.createElement(PLUSSQUARE_ICON, { className: "h-12 w-12" })
898
+ open: s,
899
+ onClose: () => i(!1),
900
+ data: b,
901
+ title: "Form Data",
902
+ placement: "bottom",
903
+ contentClassName: "custom-scrollbar"
904
+ }
271
905
  ),
272
- /* @__PURE__ */ React3.createElement(
273
- motion2.button,
906
+ /* @__PURE__ */ r.jsx(
907
+ K.div,
274
908
  {
275
- onClick: handleLogExpanded,
276
- initial: { opacity: 1, scale: 1, x: "0%" },
909
+ ref: o,
910
+ onPointerDown: (h) => h.stopPropagation(),
911
+ initial: { opacity: 0, y: "100%", scale: 0 },
277
912
  animate: {
278
- opacity: isLogExpanded || isToolBarExpanded ? 0 : 1,
279
- scale: isLogExpanded || isToolBarExpanded ? 0 : 1,
280
- x: !isPreview ? "0%" : "-120%"
913
+ opacity: t ? 1 : 0,
914
+ y: t ? "0%" : "100%",
915
+ scale: t ? 1 : 0.6
281
916
  },
282
- className: `relative cursor-pointer ${!isPreview ? "" : "mx-29"} bg-black/5 rounded-2xl p-3 backdrop-blur-xl`
283
- },
284
- /* @__PURE__ */ React3.createElement(DATALOG_ICON, { className: "h-12 w-12" })
917
+ transition: { type: "spring", stiffness: 150, damping: 20 },
918
+ className: "MobileToolBar-Modal fixed bottom-0 w-full mx-auto bg-black/5 border-black/15 border px-9 py-4 mb-2 rounded-2xl backdrop-blur-xl overflow-y-scroll",
919
+ children: /* @__PURE__ */ r.jsxs("div", { className: "grid grid-cols-1 gap-2", children: [
920
+ /* @__PURE__ */ r.jsx("button", { className: "flex w-full justify-end", onClick: () => n(!1), children: /* @__PURE__ */ r.jsx($r, {}) }),
921
+ Object.keys(le).map((h) => /* @__PURE__ */ r.jsxs(
922
+ "button",
923
+ {
924
+ className: "px-4 pl-6 py-2 text-black text-left rounded hover:bg-slate-50",
925
+ onClick: () => {
926
+ u(h), n(!1);
927
+ },
928
+ children: [
929
+ "Add ",
930
+ le[h].label
931
+ ]
932
+ },
933
+ h
934
+ ))
935
+ ] })
936
+ }
285
937
  )
286
- ), /* @__PURE__ */ React3.createElement(
287
- DataViewer,
288
- {
289
- open: isLogExpanded,
290
- onClose: () => setIsLogExpanded(false),
291
- data: fieldsArray,
292
- title: "Form Data",
293
- placement: "bottom",
294
- contentClassName: "custom-scrollbar"
295
- }
296
- ), /* @__PURE__ */ React3.createElement(
297
- motion2.div,
298
- {
299
- ref: containerRef,
300
- onPointerDown: (e) => e.stopPropagation(),
301
- initial: { opacity: 0, y: "100%", scale: 0 },
302
- animate: {
303
- opacity: isToolBarExpanded ? 1 : 0,
304
- y: isToolBarExpanded ? "0%" : "100%",
305
- scale: isToolBarExpanded ? 1 : 0.6
306
- },
307
- transition: { type: "spring", stiffness: 150, damping: 20 },
308
- className: "MobileToolBar-Modal fixed bottom-0 w-full mx-auto bg-black/5 border-black/15 border px-9 py-4 mb-2 rounded-2xl backdrop-blur-xl overflow-y-scroll"
309
- },
310
- /* @__PURE__ */ React3.createElement("div", { className: "grid grid-cols-1 gap-2" }, /* @__PURE__ */ React3.createElement("button", { className: "flex w-full justify-end", onClick: () => setIsToolBarExpanded(false) }, /* @__PURE__ */ React3.createElement(X_ICON, null)), Object.keys(fieldTypes).map((type) => /* @__PURE__ */ React3.createElement(
938
+ ] });
939
+ }
940
+ const He = Object.entries(le).map(([t, n]) => ({
941
+ type: t,
942
+ label: n.label
943
+ })), zr = ({ isPreview: t = !1 }) => {
944
+ if (t) return null;
945
+ const n = q((i) => i.addField), s = re(() => {
946
+ const i = {};
947
+ for (const { type: o } of He) i[o] = () => n(o);
948
+ return i;
949
+ }, [n]);
950
+ return /* @__PURE__ */ r.jsxs("div", { className: "p-4 bg-white border border-gray-200 rounded-lg shadow-sm", children: [
951
+ /* @__PURE__ */ r.jsx("h3", { className: "text-lg font-semibold mb-3", children: "Tools" }),
952
+ /* @__PURE__ */ r.jsx("div", { className: "grid grid-cols-1 gap-2", children: He.map(({ type: i, label: o }) => /* @__PURE__ */ r.jsxs(
311
953
  "button",
312
954
  {
313
- key: type,
314
- className: "px-4 pl-6 py-2 text-black text-left rounded hover:bg-slate-50",
315
- onClick: () => {
316
- addField(type);
317
- setIsToolBarExpanded(false);
318
- }
955
+ className: "px-3 py-2 text-left border border-black/10 rounded-md hover:bg-slate-50",
956
+ onClick: s[i],
957
+ children: [
958
+ "Add ",
959
+ o
960
+ ]
319
961
  },
320
- "Add ",
321
- fieldTypes[type].label
322
- )))
323
- ));
324
- }
325
-
326
- // src/components/desktopLayout/Layout.jsx
327
- import React13 from "react";
328
-
329
- // src/components/desktopLayout/toolPanel/ToolPanel.jsx
330
- import React4, { useMemo } from "react";
331
- import { fieldTypes as fieldTypes2, useFormStore as useFormStore3 } from "@mieweb/forms-engine";
332
- var TOOL_ITEMS = Object.entries(fieldTypes2).map(([type, cfg]) => ({
333
- type,
334
- label: cfg.label
335
- }));
336
- var ToolPanelImpl = ({ isPreview = false }) => {
337
- if (isPreview) return null;
338
- const addField = useFormStore3((s) => s.addField);
339
- const handlers = useMemo(() => {
340
- const m = {};
341
- for (const { type } of TOOL_ITEMS) m[type] = () => addField(type);
342
- return m;
343
- }, [addField]);
344
- return /* @__PURE__ */ React4.createElement("div", { className: "p-4 bg-white border border-gray-200 rounded-lg shadow-sm" }, /* @__PURE__ */ React4.createElement("h3", { className: "text-lg font-semibold mb-3" }, "Tools"), /* @__PURE__ */ React4.createElement("div", { className: "grid grid-cols-1 gap-2" }, TOOL_ITEMS.map(({ type, label }) => /* @__PURE__ */ React4.createElement(
345
- "button",
346
- {
347
- key: type,
348
- className: "px-3 py-2 text-left border border-black/10 rounded-md hover:bg-slate-50",
349
- onClick: handlers[type]
350
- },
351
- "Add ",
352
- label
353
- ))));
354
- };
355
- var ToolPanel = React4.memo(ToolPanelImpl, (prev, next) => prev.isPreview === next.isPreview);
356
- var ToolPanel_default = ToolPanel;
357
-
358
- // src/components/desktopLayout/editPanel/EditPanel.jsx
359
- import React11 from "react";
360
-
361
- // src/components/desktopLayout/editPanel/types/NonSectionEditor.jsx
362
- import React8, { useCallback, useMemo as useMemo2 } from "react";
363
-
364
- // src/components/desktopLayout/editPanel/types/CommonEditor.jsx
365
- import React6 from "react";
366
-
367
- // src/components/desktopLayout/editPanel/types/DraftIdEditor.jsx
368
- import React5 from "react";
369
- function DraftIdEditor({
370
- id = "",
371
- label = "ID",
372
- onCommit,
373
- validate,
374
- placeholder = "Enter unique ID\u2026",
375
- className = ""
962
+ i
963
+ )) })
964
+ ] });
965
+ }, Gr = E.memo(zr, (t, n) => t.isPreview === n.isPreview);
966
+ function ar({
967
+ id: t = "",
968
+ label: n = "ID",
969
+ onCommit: s,
970
+ validate: i,
971
+ placeholder: o = "Enter unique ID…",
972
+ className: u = ""
376
973
  }) {
377
- const [draft, setDraft] = React5.useState(id ?? "");
378
- const [err, setErr] = React5.useState("");
379
- React5.useEffect(() => {
380
- setDraft(id ?? "");
381
- setErr("");
382
- }, [id]);
383
- const commit = React5.useCallback(() => {
384
- const next = String(draft ?? "").trim();
385
- if (!next) {
386
- setErr("ID cannot be empty.");
387
- setDraft(id ?? "");
974
+ const [b, c] = E.useState(t ?? ""), [f, g] = E.useState("");
975
+ E.useEffect(() => {
976
+ c(t ?? ""), g("");
977
+ }, [t]);
978
+ const m = E.useCallback(() => {
979
+ const p = String(b ?? "").trim();
980
+ if (!p) {
981
+ g("ID cannot be empty."), c(t ?? "");
388
982
  return;
389
983
  }
390
- if (next === (id ?? "")) return;
391
- if (typeof validate === "function") {
392
- const msg = validate(next, id ?? "");
393
- if (msg) {
394
- setErr(msg);
395
- return;
396
- }
397
- }
398
- onCommit == null ? void 0 : onCommit(next);
399
- }, [draft, id, onCommit, validate]);
400
- return /* @__PURE__ */ React5.createElement("div", { className }, /* @__PURE__ */ React5.createElement("label", { className: "block text-sm mb-1" }, label), /* @__PURE__ */ React5.createElement(
401
- "input",
402
- {
403
- className: "w-full px-3 py-2 border border-black/20 rounded",
404
- value: draft,
405
- onChange: (e) => {
406
- if (err) setErr("");
407
- setDraft(e.target.value);
408
- },
409
- onBlur: commit,
410
- onKeyDown: (e) => {
411
- if (e.key === "Enter") {
412
- e.preventDefault();
413
- commit();
984
+ if (p !== (t ?? "")) {
985
+ if (typeof i == "function") {
986
+ const h = i(p, t ?? "");
987
+ if (h) {
988
+ g(h);
989
+ return;
414
990
  }
415
- },
416
- placeholder
417
- }
418
- ), err ? /* @__PURE__ */ React5.createElement("p", { className: "text-xs text-red-600 mt-1" }, err) : null);
419
- }
420
-
421
- // src/components/desktopLayout/editPanel/types/CommonEditor.jsx
422
- function CommonEditor({ f, onUpdateField }) {
423
- return /* @__PURE__ */ React6.createElement("div", { className: "space-y-3" }, /* @__PURE__ */ React6.createElement(
424
- DraftIdEditor,
425
- {
426
- id: f.id ?? "",
427
- onCommit: (next) => onUpdateField == null ? void 0 : onUpdateField("id", next)
428
- }
429
- ), /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("label", { className: "block text-sm mb-1" }, "Label / Question"), /* @__PURE__ */ React6.createElement(
430
- "input",
431
- {
432
- className: "w-full px-3 py-2 border border-black/20 rounded",
433
- value: f.question || "",
434
- onChange: (e) => onUpdateField("question", e.target.value),
435
- placeholder: "Enter question text"
436
- }
437
- )), /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("label", { className: "inline-flex items-center gap-2 text-sm" }, /* @__PURE__ */ React6.createElement(
438
- "input",
439
- {
440
- type: "checkbox",
441
- checked: !!f.required,
442
- onChange: (e) => onUpdateField("required", e.target.checked)
443
- }
444
- ), "Required")), /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("label", { className: "block text-sm mb-1" }, "Sublabel (optional)"), /* @__PURE__ */ React6.createElement(
445
- "textarea",
446
- {
447
- className: "w-full px-3 py-2 border border-black/20 rounded",
448
- value: f.sublabel || "",
449
- onChange: (e) => onUpdateField("sublabel", e.target.value),
450
- placeholder: "Helper text / description"
991
+ }
992
+ s == null || s(p);
451
993
  }
452
- )));
994
+ }, [b, t, s, i]);
995
+ return /* @__PURE__ */ r.jsxs("div", { className: u, children: [
996
+ /* @__PURE__ */ r.jsx("label", { className: "block text-sm mb-1", children: n }),
997
+ /* @__PURE__ */ r.jsx(
998
+ "input",
999
+ {
1000
+ className: "w-full px-3 py-2 border border-black/20 rounded",
1001
+ value: b,
1002
+ onChange: (p) => {
1003
+ f && g(""), c(p.target.value);
1004
+ },
1005
+ onBlur: m,
1006
+ onKeyDown: (p) => {
1007
+ p.key === "Enter" && (p.preventDefault(), m());
1008
+ },
1009
+ placeholder: o
1010
+ }
1011
+ ),
1012
+ f ? /* @__PURE__ */ r.jsx("p", { className: "text-xs text-red-600 mt-1", children: f }) : null
1013
+ ] });
453
1014
  }
454
- var CommonEditor_default = CommonEditor;
455
-
456
- // src/components/desktopLayout/editPanel/types/OptionListEditor.jsx
457
- import React7 from "react";
458
-
459
- // ../../node_modules/uuid/dist/esm/stringify.js
460
- var byteToHex = [];
461
- for (let i = 0; i < 256; ++i) {
462
- byteToHex.push((i + 256).toString(16).slice(1));
1015
+ function sr({ f: t, onUpdateField: n }) {
1016
+ return /* @__PURE__ */ r.jsxs("div", { className: "space-y-3", children: [
1017
+ /* @__PURE__ */ r.jsx(
1018
+ ar,
1019
+ {
1020
+ id: t.id ?? "",
1021
+ onCommit: (s) => n == null ? void 0 : n("id", s)
1022
+ }
1023
+ ),
1024
+ /* @__PURE__ */ r.jsxs("div", { children: [
1025
+ /* @__PURE__ */ r.jsx("label", { className: "block text-sm mb-1", children: "Label / Question" }),
1026
+ /* @__PURE__ */ r.jsx(
1027
+ "input",
1028
+ {
1029
+ className: "w-full px-3 py-2 border border-black/20 rounded",
1030
+ value: t.question || "",
1031
+ onChange: (s) => n("question", s.target.value),
1032
+ placeholder: "Enter question text"
1033
+ }
1034
+ )
1035
+ ] }),
1036
+ /* @__PURE__ */ r.jsx("div", { children: /* @__PURE__ */ r.jsxs("label", { className: "inline-flex items-center gap-2 text-sm", children: [
1037
+ /* @__PURE__ */ r.jsx(
1038
+ "input",
1039
+ {
1040
+ type: "checkbox",
1041
+ checked: !!t.required,
1042
+ onChange: (s) => n("required", s.target.checked)
1043
+ }
1044
+ ),
1045
+ "Required"
1046
+ ] }) }),
1047
+ /* @__PURE__ */ r.jsxs("div", { children: [
1048
+ /* @__PURE__ */ r.jsx("label", { className: "block text-sm mb-1", children: "Sublabel (optional)" }),
1049
+ /* @__PURE__ */ r.jsx(
1050
+ "textarea",
1051
+ {
1052
+ className: "w-full px-3 py-2 border border-black/20 rounded",
1053
+ value: t.sublabel || "",
1054
+ onChange: (s) => n("sublabel", s.target.value),
1055
+ placeholder: "Helper text / description"
1056
+ }
1057
+ )
1058
+ ] })
1059
+ ] });
463
1060
  }
464
- function unsafeStringify(arr, offset = 0) {
465
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
1061
+ const $ = [];
1062
+ for (let t = 0; t < 256; ++t)
1063
+ $.push((t + 256).toString(16).slice(1));
1064
+ function Kr(t, n = 0) {
1065
+ return ($[t[n + 0]] + $[t[n + 1]] + $[t[n + 2]] + $[t[n + 3]] + "-" + $[t[n + 4]] + $[t[n + 5]] + "-" + $[t[n + 6]] + $[t[n + 7]] + "-" + $[t[n + 8]] + $[t[n + 9]] + "-" + $[t[n + 10]] + $[t[n + 11]] + $[t[n + 12]] + $[t[n + 13]] + $[t[n + 14]] + $[t[n + 15]]).toLowerCase();
466
1066
  }
467
-
468
- // ../../node_modules/uuid/dist/esm/rng.js
469
- import { randomFillSync } from "crypto";
470
- var rnds8Pool = new Uint8Array(256);
471
- var poolPtr = rnds8Pool.length;
472
- function rng() {
473
- if (poolPtr > rnds8Pool.length - 16) {
474
- randomFillSync(rnds8Pool);
475
- poolPtr = 0;
1067
+ let _e;
1068
+ const Hr = new Uint8Array(16);
1069
+ function Xr() {
1070
+ if (!_e) {
1071
+ if (typeof crypto > "u" || !crypto.getRandomValues)
1072
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1073
+ _e = crypto.getRandomValues.bind(crypto);
476
1074
  }
477
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
1075
+ return _e(Hr);
478
1076
  }
479
-
480
- // ../../node_modules/uuid/dist/esm/native.js
481
- import { randomUUID } from "crypto";
482
- var native_default = { randomUUID };
483
-
484
- // ../../node_modules/uuid/dist/esm/v4.js
485
- function v4(options, buf, offset) {
486
- var _a;
487
- if (native_default.randomUUID && !buf && !options) {
488
- return native_default.randomUUID();
489
- }
490
- options = options || {};
491
- const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
492
- if (rnds.length < 16) {
1077
+ const Qr = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Xe = { randomUUID: Qr };
1078
+ function Zr(t, n, s) {
1079
+ var o;
1080
+ if (Xe.randomUUID && !t)
1081
+ return Xe.randomUUID();
1082
+ t = t || {};
1083
+ const i = t.random ?? ((o = t.rng) == null ? void 0 : o.call(t)) ?? Xr();
1084
+ if (i.length < 16)
493
1085
  throw new Error("Random bytes length must be >= 16");
494
- }
495
- rnds[6] = rnds[6] & 15 | 64;
496
- rnds[8] = rnds[8] & 63 | 128;
497
- if (buf) {
498
- offset = offset || 0;
499
- if (offset < 0 || offset + 16 > buf.length) {
500
- throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
501
- }
502
- for (let i = 0; i < 16; ++i) {
503
- buf[offset + i] = rnds[i];
504
- }
505
- return buf;
506
- }
507
- return unsafeStringify(rnds);
1086
+ return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, Kr(i);
508
1087
  }
509
- var v4_default = v4;
510
-
511
- // src/components/desktopLayout/editPanel/types/OptionListEditor.jsx
512
- function OptionListEditor({ field, onUpdateField }) {
513
- const opts = field.options || [];
514
- const addOption = () => {
515
- onUpdateField("options", [...opts, { id: v4_default(), value: "" }]);
516
- };
517
- const updateOption = (id, value) => {
518
- onUpdateField(
1088
+ function ir({ field: t, onUpdateField: n }) {
1089
+ const s = t.options || [], i = () => {
1090
+ n("options", [...s, { id: Zr(), value: "" }]);
1091
+ }, o = (b, c) => {
1092
+ n(
519
1093
  "options",
520
- opts.map((o) => o.id === id ? { ...o, value } : o)
1094
+ s.map((f) => f.id === b ? { ...f, value: c } : f)
521
1095
  );
522
- };
523
- const removeOption = (id) => {
524
- onUpdateField(
1096
+ }, u = (b) => {
1097
+ n(
525
1098
  "options",
526
- opts.filter((o) => o.id !== id)
1099
+ s.filter((c) => c.id !== b)
527
1100
  );
528
1101
  };
529
- return /* @__PURE__ */ React7.createElement("div", { className: "mt-3" }, /* @__PURE__ */ React7.createElement("div", { className: "text-sm font-medium mb-1" }, "Options"), opts.map((opt) => /* @__PURE__ */ React7.createElement("div", { key: opt.id, className: "flex items-center gap-2 mb-2" }, /* @__PURE__ */ React7.createElement(
530
- "input",
531
- {
532
- className: "flex-1 px-3 py-2 border border-black/20 rounded",
533
- value: opt.value,
534
- onChange: (e) => updateOption(opt.id, e.target.value),
535
- placeholder: "Option text"
536
- }
537
- ), /* @__PURE__ */ React7.createElement(
538
- "button",
539
- {
540
- onClick: () => removeOption(opt.id),
541
- className: "px-2 py-1 text-sm border border-black/20 rounded hover:bg-slate-50"
542
- },
543
- "Remove"
544
- ))), /* @__PURE__ */ React7.createElement(
545
- "button",
546
- {
547
- onClick: addOption,
548
- className: "mt-1 px-3 py-2 text-sm border border-black/20 rounded hover:bg-slate-50"
549
- },
550
- "+ Add Option"
551
- ));
1102
+ return /* @__PURE__ */ r.jsxs("div", { className: "mt-3", children: [
1103
+ /* @__PURE__ */ r.jsx("div", { className: "text-sm font-medium mb-1", children: "Options" }),
1104
+ s.map((b) => /* @__PURE__ */ r.jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
1105
+ /* @__PURE__ */ r.jsx(
1106
+ "input",
1107
+ {
1108
+ className: "flex-1 px-3 py-2 border border-black/20 rounded",
1109
+ value: b.value,
1110
+ onChange: (c) => o(b.id, c.target.value),
1111
+ placeholder: "Option text"
1112
+ }
1113
+ ),
1114
+ /* @__PURE__ */ r.jsx(
1115
+ "button",
1116
+ {
1117
+ onClick: () => u(b.id),
1118
+ className: "px-2 py-1 text-sm border border-black/20 rounded hover:bg-slate-50",
1119
+ children: "Remove"
1120
+ }
1121
+ )
1122
+ ] }, b.id)),
1123
+ /* @__PURE__ */ r.jsx(
1124
+ "button",
1125
+ {
1126
+ onClick: i,
1127
+ className: "mt-1 px-3 py-2 text-sm border border-black/20 rounded hover:bg-slate-50",
1128
+ children: "+ Add Option"
1129
+ }
1130
+ )
1131
+ ] });
552
1132
  }
553
-
554
- // src/components/desktopLayout/editPanel/types/NonSectionEditor.jsx
555
- import { useFormApi } from "@mieweb/forms-engine";
556
- function NonSectionEditor({ f }) {
557
- const api = useFormApi(f.id);
558
- const onUpdateField = useCallback(
559
- (key, value) => api.field.update(key, value),
560
- [api]
1133
+ function et({ f: t }) {
1134
+ const n = tr(t.id), s = be(
1135
+ (o, u) => n.field.update(o, u),
1136
+ [n]
1137
+ ), i = re(
1138
+ () => ["radio", "check", "selection"].includes(t.fieldType),
1139
+ [t.fieldType]
561
1140
  );
562
- const isChoice = useMemo2(
563
- () => ["radio", "check", "selection"].includes(f.fieldType),
564
- [f.fieldType]
565
- );
566
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement("h3", { className: "text-lg font-semibold mb-3" }, "Edit"), /* @__PURE__ */ React8.createElement(CommonEditor_default, { f, onUpdateField }), f.fieldType === "input" && /* @__PURE__ */ React8.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React8.createElement("div", { className: "text-sm font-medium mb-1" }, "Default Answer"), /* @__PURE__ */ React8.createElement(
567
- "input",
568
- {
569
- className: "w-full px-3 py-2 border border-black/20 rounded",
570
- value: f.answer || "",
571
- onChange: (e) => onUpdateField("answer", e.target.value),
572
- placeholder: "Default value"
573
- }
574
- )), isChoice && /* @__PURE__ */ React8.createElement(OptionListEditor, { field: f, onUpdateField }));
1141
+ return /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
1142
+ /* @__PURE__ */ r.jsx("h3", { className: "text-lg font-semibold mb-3", children: "Edit" }),
1143
+ /* @__PURE__ */ r.jsx(sr, { f: t, onUpdateField: s }),
1144
+ t.fieldType === "input" && /* @__PURE__ */ r.jsxs("div", { className: "mt-4", children: [
1145
+ /* @__PURE__ */ r.jsx("div", { className: "text-sm font-medium mb-1", children: "Default Answer" }),
1146
+ /* @__PURE__ */ r.jsx(
1147
+ "input",
1148
+ {
1149
+ className: "w-full px-3 py-2 border border-black/20 rounded",
1150
+ value: t.answer || "",
1151
+ onChange: (o) => s("answer", o.target.value),
1152
+ placeholder: "Default value"
1153
+ }
1154
+ )
1155
+ ] }),
1156
+ i && /* @__PURE__ */ r.jsx(ir, { field: t, onUpdateField: s })
1157
+ ] });
575
1158
  }
576
- var NonSectionEditor_default = NonSectionEditor;
577
-
578
- // src/components/desktopLayout/editPanel/types/SectionEditor.jsx
579
- import React9, { useState as useState3, useEffect as useEffect2, useMemo as useMemo3, useCallback as useCallback2 } from "react";
580
- import { fieldTypes as fieldTypes3, useFormStore as useFormStore4, useFormApi as useFormApi2 } from "@mieweb/forms-engine";
581
- function SectionEditor({ section, onActiveChildChange }) {
582
- var _a, _b, _c;
583
- const sectionApi = useFormApi2(section.id);
584
- const children = Array.isArray(section.fields) ? section.fields : [];
585
- const [activeChildId, setActiveChildId] = useState3(((_a = children[0]) == null ? void 0 : _a.id) || null);
586
- useEffect2(() => {
587
- var _a2;
588
- setActiveChildId(((_a2 = children[0]) == null ? void 0 : _a2.id) || null);
589
- }, [section.id]);
590
- useEffect2(() => {
591
- if (!children.length) {
592
- if (activeChildId !== null) setActiveChildId(null);
1159
+ function rt({ section: t, onActiveChildChange: n }) {
1160
+ var p, h, T;
1161
+ const s = tr(t.id), i = Array.isArray(t.fields) ? t.fields : [], [o, u] = xe(((p = i[0]) == null ? void 0 : p.id) || null);
1162
+ ee(() => {
1163
+ var v;
1164
+ u(((v = i[0]) == null ? void 0 : v.id) || null);
1165
+ }, [t.id]), ee(() => {
1166
+ if (!i.length) {
1167
+ o !== null && u(null);
593
1168
  return;
594
1169
  }
595
- const stillExists = children.some((c) => c.id === activeChildId);
596
- if (!stillExists) setActiveChildId(children[0].id);
597
- }, [children, activeChildId]);
598
- useEffect2(() => {
599
- onActiveChildChange == null ? void 0 : onActiveChildChange(section.id, activeChildId || null);
600
- }, [section.id, activeChildId, onActiveChildChange]);
601
- const onUpdateSection = useCallback2(
602
- (key, value) => sectionApi.field.update(key, value),
603
- [sectionApi]
604
- );
605
- const activeChild = useMemo3(
606
- () => children.find((c) => c.id === activeChildId) || null,
607
- [children, activeChildId]
608
- );
609
- const onUpdateChild = useCallback2(
610
- (key, value) => {
611
- if (!activeChild) return;
612
- if (key === "id") {
613
- const next = String(value ?? "").trim();
614
- if (!next) return;
615
- useFormStore4.getState().updateField(
616
- activeChild.id,
617
- { id: next },
618
- {
619
- sectionId: section.id,
620
- onIdChange: (newId, oldId) => {
621
- setActiveChildId((curr) => curr === oldId ? newId : curr);
1170
+ i.some((S) => S.id === o) || u(i[0].id);
1171
+ }, [i, o]), ee(() => {
1172
+ n == null || n(t.id, o || null);
1173
+ }, [t.id, o, n]);
1174
+ const b = be(
1175
+ (v, S) => s.field.update(v, S),
1176
+ [s]
1177
+ ), c = re(
1178
+ () => i.find((v) => v.id === o) || null,
1179
+ [i, o]
1180
+ ), f = be(
1181
+ (v, S) => {
1182
+ if (c) {
1183
+ if (v === "id") {
1184
+ const k = String(S ?? "").trim();
1185
+ if (!k) return;
1186
+ q.getState().updateField(
1187
+ c.id,
1188
+ { id: k },
1189
+ {
1190
+ sectionId: t.id,
1191
+ onIdChange: (L, _) => {
1192
+ u((F) => F === _ ? L : F);
1193
+ }
622
1194
  }
623
- }
1195
+ );
1196
+ return;
1197
+ }
1198
+ q.getState().updateField(
1199
+ c.id,
1200
+ { [v]: S },
1201
+ { sectionId: t.id }
624
1202
  );
625
- return;
626
1203
  }
627
- useFormStore4.getState().updateField(
628
- activeChild.id,
629
- { [key]: value },
630
- { sectionId: section.id }
631
- );
632
1204
  },
633
- [activeChild, section.id]
1205
+ [c, t.id]
1206
+ ), g = be(() => {
1207
+ c && q.getState().deleteField(c.id, { sectionId: t.id });
1208
+ }, [c, t.id]), m = re(
1209
+ () => c && ["radio", "check", "selection"].includes(c.fieldType),
1210
+ [c]
634
1211
  );
635
- const onDeleteChild = useCallback2(() => {
636
- if (!activeChild) return;
637
- useFormStore4.getState().deleteField(activeChild.id, { sectionId: section.id });
638
- }, [activeChild, section.id]);
639
- const isChoiceChild = useMemo3(
640
- () => activeChild && ["radio", "check", "selection"].includes(activeChild.fieldType),
641
- [activeChild]
642
- );
643
- return /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement("h3", { className: "text-lg font-semibold mb-3" }, "Edit Section"), /* @__PURE__ */ React9.createElement(
644
- DraftIdEditor,
645
- {
646
- id: section.id,
647
- onCommit: (next) => sectionApi.field.renameId(next)
648
- }
649
- ), /* @__PURE__ */ React9.createElement("div", { className: "mt-3" }, /* @__PURE__ */ React9.createElement("label", { className: "block text-sm mb-1" }, "Section Title"), /* @__PURE__ */ React9.createElement(
650
- "input",
651
- {
652
- className: "w-full px-3 py-2 border border-black/20 rounded",
653
- value: section.title || "",
654
- onChange: (e) => onUpdateSection("title", e.target.value),
655
- placeholder: "Section title"
656
- }
657
- )), /* @__PURE__ */ React9.createElement("div", { className: "mt-6" }, /* @__PURE__ */ React9.createElement("div", { className: "text-sm font-semibold mb-2" }, "Fields in this section"), children.length === 0 ? /* @__PURE__ */ React9.createElement("div", { className: "text-sm text-gray-500" }, "No fields yet. Use the section\u2019s mini toolbar to add fields.") : /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement("div", { className: "flex flex-wrap gap-2 mb-3" }, children.map((c) => {
658
- var _a2, _b2;
659
- return /* @__PURE__ */ React9.createElement(
660
- "button",
1212
+ return /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
1213
+ /* @__PURE__ */ r.jsx("h3", { className: "text-lg font-semibold mb-3", children: "Edit Section" }),
1214
+ /* @__PURE__ */ r.jsx(
1215
+ ar,
661
1216
  {
662
- key: c.id,
663
- className: [
664
- "px-3 py-1.5 text-sm rounded border",
665
- activeChildId === c.id ? "bg-black/5 border-black/20" : "bg-white border-black/10 hover:bg-slate-50"
666
- ].join(" "),
667
- onClick: () => setActiveChildId(c.id),
668
- title: c.question || c.fieldType
669
- },
670
- ((_a2 = c.question) == null ? void 0 : _a2.trim()) || ((_b2 = fieldTypes3[c.fieldType]) == null ? void 0 : _b2.label) || "Field"
671
- );
672
- })), activeChild && /* @__PURE__ */ React9.createElement("div", { className: "mt-2" }, /* @__PURE__ */ React9.createElement("div", { className: "text-sm font-semibold mb-2" }, "Editing: ", ((_b = activeChild.question) == null ? void 0 : _b.trim()) || ((_c = fieldTypes3[activeChild.fieldType]) == null ? void 0 : _c.label)), /* @__PURE__ */ React9.createElement(CommonEditor_default, { f: activeChild, onUpdateField: onUpdateChild }), activeChild.fieldType === "input" && /* @__PURE__ */ React9.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React9.createElement("div", { className: "text-sm font-medium mb-1" }, "Default Answer"), /* @__PURE__ */ React9.createElement(
673
- "input",
674
- {
675
- className: "w-full px-3 py-2 border border-black/20 rounded",
676
- value: activeChild.answer || "",
677
- onChange: (e) => onUpdateChild("answer", e.target.value),
678
- placeholder: "Default value"
679
- }
680
- )), isChoiceChild && /* @__PURE__ */ React9.createElement(OptionListEditor, { field: activeChild, onUpdateField: onUpdateChild }), /* @__PURE__ */ React9.createElement(
681
- "button",
682
- {
683
- className: "mt-3 px-3 py-2 text-sm text-red-400 border rounded",
684
- onClick: onDeleteChild
685
- },
686
- "Delete this field"
687
- )))));
1217
+ id: t.id,
1218
+ onCommit: (v) => s.field.renameId(v)
1219
+ }
1220
+ ),
1221
+ /* @__PURE__ */ r.jsxs("div", { className: "mt-3", children: [
1222
+ /* @__PURE__ */ r.jsx("label", { className: "block text-sm mb-1", children: "Section Title" }),
1223
+ /* @__PURE__ */ r.jsx(
1224
+ "input",
1225
+ {
1226
+ className: "w-full px-3 py-2 border border-black/20 rounded",
1227
+ value: t.title || "",
1228
+ onChange: (v) => b("title", v.target.value),
1229
+ placeholder: "Section title"
1230
+ }
1231
+ )
1232
+ ] }),
1233
+ /* @__PURE__ */ r.jsxs("div", { className: "mt-6", children: [
1234
+ /* @__PURE__ */ r.jsx("div", { className: "text-sm font-semibold mb-2", children: "Fields in this section" }),
1235
+ i.length === 0 ? /* @__PURE__ */ r.jsx("div", { className: "text-sm text-gray-500", children: "No fields yet. Use the section’s mini toolbar to add fields." }) : /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
1236
+ /* @__PURE__ */ r.jsx("div", { className: "flex flex-wrap gap-2 mb-3", children: i.map((v) => {
1237
+ var S, k;
1238
+ return /* @__PURE__ */ r.jsx(
1239
+ "button",
1240
+ {
1241
+ className: [
1242
+ "px-3 py-1.5 text-sm rounded border",
1243
+ o === v.id ? "bg-black/5 border-black/20" : "bg-white border-black/10 hover:bg-slate-50"
1244
+ ].join(" "),
1245
+ onClick: () => u(v.id),
1246
+ title: v.question || v.fieldType,
1247
+ children: ((S = v.question) == null ? void 0 : S.trim()) || ((k = le[v.fieldType]) == null ? void 0 : k.label) || "Field"
1248
+ },
1249
+ v.id
1250
+ );
1251
+ }) }),
1252
+ c && /* @__PURE__ */ r.jsxs("div", { className: "mt-2", children: [
1253
+ /* @__PURE__ */ r.jsxs("div", { className: "text-sm font-semibold mb-2", children: [
1254
+ "Editing: ",
1255
+ ((h = c.question) == null ? void 0 : h.trim()) || ((T = le[c.fieldType]) == null ? void 0 : T.label)
1256
+ ] }),
1257
+ /* @__PURE__ */ r.jsx(sr, { f: c, onUpdateField: f }),
1258
+ c.fieldType === "input" && /* @__PURE__ */ r.jsxs("div", { className: "mt-4", children: [
1259
+ /* @__PURE__ */ r.jsx("div", { className: "text-sm font-medium mb-1", children: "Default Answer" }),
1260
+ /* @__PURE__ */ r.jsx(
1261
+ "input",
1262
+ {
1263
+ className: "w-full px-3 py-2 border border-black/20 rounded",
1264
+ value: c.answer || "",
1265
+ onChange: (v) => f("answer", v.target.value),
1266
+ placeholder: "Default value"
1267
+ }
1268
+ )
1269
+ ] }),
1270
+ m && /* @__PURE__ */ r.jsx(ir, { field: c, onUpdateField: f }),
1271
+ /* @__PURE__ */ r.jsx(
1272
+ "button",
1273
+ {
1274
+ className: "mt-3 px-3 py-2 text-sm text-red-400 border rounded",
1275
+ onClick: g,
1276
+ children: "Delete this field"
1277
+ }
1278
+ )
1279
+ ] })
1280
+ ] })
1281
+ ] })
1282
+ ] });
688
1283
  }
689
- var SectionEditor_default = SectionEditor;
690
-
691
- // src/components/desktopLayout/editPanel/types/LogicEditor.jsx
692
- import React10 from "react";
693
- import { useUIApi as useUIApi3, useFormStore as useFormStore5 } from "@mieweb/forms-engine";
694
- function getOperatorsForFieldType(fieldType) {
695
- switch (fieldType) {
1284
+ function Qe(t) {
1285
+ switch (t) {
696
1286
  case "input":
697
1287
  return ["equals", "contains"];
698
1288
  case "radio":
@@ -704,417 +1294,363 @@ function getOperatorsForFieldType(fieldType) {
704
1294
  return ["equals"];
705
1295
  }
706
1296
  }
707
- function normOption(opt) {
708
- if (opt && typeof opt === "object") {
709
- const id = opt.id ?? String(opt.value ?? "");
710
- const value = String(opt.value ?? opt.label ?? opt.id ?? "");
711
- return { id, value };
1297
+ function Ze(t) {
1298
+ if (t && typeof t == "object") {
1299
+ const s = t.id ?? String(t.value ?? ""), i = String(t.value ?? t.label ?? t.id ?? "");
1300
+ return { id: s, value: i };
712
1301
  }
713
- const s = String(opt ?? "");
714
- return { id: s, value: s };
1302
+ const n = String(t ?? "");
1303
+ return { id: n, value: n };
715
1304
  }
716
- function LogicEditor() {
717
- var _a, _b, _c;
718
- const ui = useUIApi3();
719
- const byId = useFormStore5((s) => s.byId);
720
- const setEnableWhen = useFormStore5((s) => s.setEnableWhen);
721
- const updateField = useFormStore5((s) => s.updateField);
722
- const selectedId = ((_a = ui == null ? void 0 : ui.selectedFieldId) == null ? void 0 : _a.value) ?? null;
723
- const rawParentId = ((_b = ui == null ? void 0 : ui.selectedChildId) == null ? void 0 : _b.ParentId) ?? null;
724
- const rawChildId = ((_c = ui == null ? void 0 : ui.selectedChildId) == null ? void 0 : _c.ChildId) ?? null;
725
- const selectedField = selectedId ? byId[selectedId] : null;
726
- const isSectionCtx = (selectedField == null ? void 0 : selectedField.fieldType) === "section";
727
- const sectionChildren = React10.useMemo(() => {
728
- if (!isSectionCtx) return [];
729
- const arr = Array.isArray(selectedField == null ? void 0 : selectedField.fields) ? selectedField.fields : [];
730
- return arr;
731
- }, [isSectionCtx, selectedField]);
732
- const childValidForSection = React10.useMemo(() => {
733
- if (!isSectionCtx || !rawChildId) return false;
734
- return sectionChildren.some((c) => c.id === rawChildId);
735
- }, [isSectionCtx, rawChildId, sectionChildren]);
736
- const initialTarget = React10.useMemo(() => {
737
- if (!isSectionCtx) return "";
738
- if (childValidForSection) return `child:${rawChildId}`;
739
- return "";
740
- }, [isSectionCtx, childValidForSection, rawChildId]);
741
- const [target, setTarget] = React10.useState(initialTarget);
742
- React10.useEffect(() => {
743
- setTarget(initialTarget);
744
- }, [initialTarget]);
745
- React10.useEffect(() => {
746
- if (!isSectionCtx) return;
747
- if (target && target.startsWith("child:")) {
748
- const cid = target.slice(6);
749
- ui.selectedChildId.set(selectedId, cid);
750
- } else {
751
- ui.selectedChildId.set(null, null);
752
- }
753
- }, [isSectionCtx, target, selectedId, ui]);
754
- const isChildScope = Boolean(isSectionCtx && target && target.startsWith("child:"));
755
- const effectiveChildId = isChildScope ? target.slice(6) : null;
756
- const effectiveId = isChildScope ? effectiveChildId : selectedId;
757
- const field = React10.useMemo(() => {
758
- if (!effectiveId) return null;
759
- if (isChildScope) {
760
- return sectionChildren.find((c) => c.id === effectiveChildId) ?? null;
761
- }
762
- return byId[effectiveId] ?? null;
763
- }, [byId, effectiveId, isChildScope, effectiveChildId, sectionChildren]);
764
- const targets = React10.useMemo(() => {
765
- var _a2, _b2, _c2;
766
- const out = [];
767
- for (const f of Object.values(byId)) {
768
- if (!f) continue;
769
- if (f.fieldType === "section" && Array.isArray(f.fields)) {
770
- const sectTitle = ((_a2 = f.title) == null ? void 0 : _a2.trim()) || "Section";
771
- f.fields.forEach((c) => {
772
- var _a3;
773
- out.push({
774
- id: c.id,
775
- parentId: f.id,
776
- label: `${sectTitle} \u203A ${((_a3 = c.question) == null ? void 0 : _a3.trim()) || c.id}`,
777
- fieldType: c.fieldType,
778
- options: Array.isArray(c.options) ? c.options : []
1305
+ function tt() {
1306
+ var ce, te, B;
1307
+ const t = H(), n = q((d) => d.byId), s = q((d) => d.setEnableWhen), i = q((d) => d.updateField), o = ((ce = t == null ? void 0 : t.selectedFieldId) == null ? void 0 : ce.value) ?? null;
1308
+ (te = t == null ? void 0 : t.selectedChildId) == null || te.ParentId;
1309
+ const u = ((B = t == null ? void 0 : t.selectedChildId) == null ? void 0 : B.ChildId) ?? null, b = o ? n[o] : null, c = (b == null ? void 0 : b.fieldType) === "section", f = E.useMemo(() => c ? Array.isArray(b == null ? void 0 : b.fields) ? b.fields : [] : [], [c, b]), g = E.useMemo(() => !c || !u ? !1 : f.some((d) => d.id === u), [c, u, f]), m = E.useMemo(() => c && g ? `child:${u}` : "", [c, g, u]), [p, h] = E.useState(m);
1310
+ E.useEffect(() => {
1311
+ h(m);
1312
+ }, [m]), E.useEffect(() => {
1313
+ if (c)
1314
+ if (p && p.startsWith("child:")) {
1315
+ const d = p.slice(6);
1316
+ t.selectedChildId.set(o, d);
1317
+ } else
1318
+ t.selectedChildId.set(null, null);
1319
+ }, [c, p, o, t]);
1320
+ const T = !!(c && p && p.startsWith("child:")), v = T ? p.slice(6) : null, S = T ? v : o, k = E.useMemo(() => S ? T ? f.find((d) => d.id === v) ?? null : n[S] ?? null : null, [n, S, T, v, f]), L = E.useMemo(() => {
1321
+ var C, I, Y;
1322
+ const d = [];
1323
+ for (const A of Object.values(n))
1324
+ if (A)
1325
+ if (A.fieldType === "section" && Array.isArray(A.fields)) {
1326
+ const U = ((C = A.title) == null ? void 0 : C.trim()) || "Section";
1327
+ A.fields.forEach((y) => {
1328
+ var z;
1329
+ d.push({
1330
+ id: y.id,
1331
+ parentId: A.id,
1332
+ label: `${U} › ${((z = y.question) == null ? void 0 : z.trim()) || y.id}`,
1333
+ fieldType: y.fieldType,
1334
+ options: Array.isArray(y.options) ? y.options : []
1335
+ });
779
1336
  });
780
- });
781
- } else {
782
- out.push({
783
- id: f.id,
784
- parentId: null,
785
- label: ((_b2 = f.question) == null ? void 0 : _b2.trim()) || ((_c2 = f.title) == null ? void 0 : _c2.trim()) || f.id,
786
- fieldType: f.fieldType,
787
- options: Array.isArray(f.options) ? f.options : []
788
- });
789
- }
790
- }
791
- return out;
792
- }, [byId]);
793
- const findTarget = React10.useCallback(
794
- (tid) => targets.find((t) => t.id === tid) || null,
795
- [targets]
796
- );
797
- const writeEnableWhen = React10.useCallback(
798
- (next) => {
799
- if (!effectiveId) return;
800
- const normalized = next && Array.isArray(next.conditions) ? { logic: next.logic || "AND", conditions: next.conditions } : void 0;
801
- if (isChildScope && selectedId) {
802
- updateField(effectiveId, { enableWhen: normalized }, { sectionId: selectedId });
803
- } else {
804
- setEnableWhen(effectiveId, normalized);
805
- }
1337
+ } else
1338
+ d.push({
1339
+ id: A.id,
1340
+ parentId: null,
1341
+ label: ((I = A.question) == null ? void 0 : I.trim()) || ((Y = A.title) == null ? void 0 : Y.trim()) || A.id,
1342
+ fieldType: A.fieldType,
1343
+ options: Array.isArray(A.options) ? A.options : []
1344
+ });
1345
+ return d;
1346
+ }, [n]), _ = E.useCallback(
1347
+ (d) => L.find((C) => C.id === d) || null,
1348
+ [L]
1349
+ ), F = E.useCallback(
1350
+ (d) => {
1351
+ if (!S) return;
1352
+ const C = d && Array.isArray(d.conditions) ? { logic: d.logic || "AND", conditions: d.conditions } : void 0;
1353
+ T && o ? i(S, { enableWhen: C }, { sectionId: o }) : s(S, C);
806
1354
  },
807
- [effectiveId, isChildScope, selectedId, setEnableWhen, updateField]
808
- );
809
- const ew = React10.useMemo(() => {
810
- return (field == null ? void 0 : field.enableWhen) && Array.isArray(field.enableWhen.conditions) ? { logic: field.enableWhen.logic || "AND", conditions: field.enableWhen.conditions } : { logic: "AND", conditions: [] };
811
- }, [field]);
812
- const addCond = React10.useCallback(() => {
813
- const next = {
814
- logic: ew.logic || "AND",
1355
+ [S, T, o, s, i]
1356
+ ), O = E.useMemo(() => k != null && k.enableWhen && Array.isArray(k.enableWhen.conditions) ? { logic: k.enableWhen.logic || "AND", conditions: k.enableWhen.conditions } : { logic: "AND", conditions: [] }, [k]), he = E.useCallback(() => {
1357
+ const d = {
1358
+ logic: O.logic || "AND",
815
1359
  conditions: [
816
- ...Array.isArray(ew.conditions) ? ew.conditions : [],
1360
+ ...Array.isArray(O.conditions) ? O.conditions : [],
817
1361
  { targetId: "", operator: "equals", value: "" }
818
1362
  ]
819
1363
  };
820
- writeEnableWhen(next);
821
- }, [ew, writeEnableWhen]);
822
- const clear = React10.useCallback(() => writeEnableWhen(null), [writeEnableWhen]);
823
- const removeCond = React10.useCallback(
824
- (idx) => {
825
- const base = Array.isArray(ew.conditions) ? ew.conditions : [];
826
- const nextConds = base.filter((_, i) => i !== idx);
827
- writeEnableWhen({ ...ew, conditions: nextConds });
1364
+ F(d);
1365
+ }, [O, F]), ve = E.useCallback(() => F(null), [F]), ge = E.useCallback(
1366
+ (d) => {
1367
+ const I = (Array.isArray(O.conditions) ? O.conditions : []).filter((Y, A) => A !== d);
1368
+ F({ ...O, conditions: I });
828
1369
  },
829
- [ew, writeEnableWhen]
830
- );
831
- const updateCond = React10.useCallback(
832
- (idx, patch) => {
833
- const base = Array.isArray(ew.conditions) ? ew.conditions : [];
834
- const nextConds = [...base];
835
- const curr = nextConds[idx] || { targetId: "", operator: "equals", value: "" };
836
- const updated = { ...curr, ...patch };
837
- if ("targetId" in patch) {
838
- const meta = findTarget(updated.targetId);
839
- const ops = getOperatorsForFieldType(meta == null ? void 0 : meta.fieldType);
840
- if (!ops.includes(updated.operator)) updated.operator = ops[0] || "equals";
841
- const opts = Array.isArray(meta == null ? void 0 : meta.options) ? meta.options.map(normOption) : [];
842
- if (opts.length > 0) {
843
- const valid = new Set(opts.map((o) => o.id));
844
- if (!valid.has(updated.value)) updated.value = "";
845
- }
1370
+ [O, F]
1371
+ ), X = E.useCallback(
1372
+ (d, C) => {
1373
+ const Y = [...Array.isArray(O.conditions) ? O.conditions : []], U = { ...Y[d] || { targetId: "", operator: "equals", value: "" }, ...C };
1374
+ if ("targetId" in C) {
1375
+ const y = _(U.targetId), z = Qe(y == null ? void 0 : y.fieldType);
1376
+ z.includes(U.operator) || (U.operator = z[0] || "equals");
1377
+ const ne = Array.isArray(y == null ? void 0 : y.options) ? y.options.map(Ze) : [];
1378
+ ne.length > 0 && (new Set(ne.map((je) => je.id)).has(U.value) || (U.value = ""));
846
1379
  }
847
- nextConds[idx] = updated;
848
- writeEnableWhen({ ...ew, conditions: nextConds });
849
- },
850
- [ew, findTarget, writeEnableWhen]
851
- );
852
- const filteredTargets = React10.useMemo(
853
- () => targets.filter((t) => t.id !== effectiveId),
854
- [targets, effectiveId]
855
- );
856
- const isDisabled = !field || !effectiveId;
857
- return /* @__PURE__ */ React10.createElement("div", { className: "space-y-2" }, isSectionCtx && /* @__PURE__ */ React10.createElement("div", { className: "flex gap-2 items-center" }, /* @__PURE__ */ React10.createElement("label", { className: "text-sm" }, "Target:"), /* @__PURE__ */ React10.createElement(
858
- "select",
859
- {
860
- className: "border p-1 rounded",
861
- value: target,
862
- onChange: (e) => setTarget(e.target.value)
1380
+ Y[d] = U, F({ ...O, conditions: Y });
863
1381
  },
864
- /* @__PURE__ */ React10.createElement("option", { value: "" }, "Section (this)"),
865
- sectionChildren.map((c) => {
866
- var _a2, _b2;
867
- return /* @__PURE__ */ React10.createElement("option", { key: c.id, value: `child:${c.id}` }, ((_a2 = c.question) == null ? void 0 : _a2.trim()) || ((_b2 = c.title) == null ? void 0 : _b2.trim()) || c.id);
1382
+ [O, _, F]
1383
+ ), oe = E.useMemo(
1384
+ () => L.filter((d) => d.id !== S),
1385
+ [L, S]
1386
+ ), J = !k || !S;
1387
+ return /* @__PURE__ */ r.jsxs("div", { className: "space-y-2", children: [
1388
+ c && /* @__PURE__ */ r.jsxs("div", { className: "flex gap-2 items-center", children: [
1389
+ /* @__PURE__ */ r.jsx("label", { className: "text-sm", children: "Target:" }),
1390
+ /* @__PURE__ */ r.jsxs(
1391
+ "select",
1392
+ {
1393
+ className: "border p-1 rounded",
1394
+ value: p,
1395
+ onChange: (d) => h(d.target.value),
1396
+ children: [
1397
+ /* @__PURE__ */ r.jsx("option", { value: "", children: "Section (this)" }),
1398
+ f.map((d) => {
1399
+ var C, I;
1400
+ return /* @__PURE__ */ r.jsx("option", { value: `child:${d.id}`, children: ((C = d.question) == null ? void 0 : C.trim()) || ((I = d.title) == null ? void 0 : I.trim()) || d.id }, d.id);
1401
+ })
1402
+ ]
1403
+ }
1404
+ )
1405
+ ] }),
1406
+ /* @__PURE__ */ r.jsxs("div", { className: "flex gap-2 items-center", children: [
1407
+ /* @__PURE__ */ r.jsx("label", { className: "text-sm", children: "Logic:" }),
1408
+ /* @__PURE__ */ r.jsxs(
1409
+ "select",
1410
+ {
1411
+ value: O.logic || "AND",
1412
+ onChange: (d) => F({ ...O, logic: d.target.value }),
1413
+ className: "border p-1 rounded",
1414
+ disabled: J,
1415
+ children: [
1416
+ /* @__PURE__ */ r.jsx("option", { value: "AND", children: "AND" }),
1417
+ /* @__PURE__ */ r.jsx("option", { value: "OR", children: "OR" })
1418
+ ]
1419
+ }
1420
+ ),
1421
+ /* @__PURE__ */ r.jsx("button", { type: "button", className: "px-2 py-1 border rounded", onClick: he, disabled: J, children: "+ Condition" }),
1422
+ /* @__PURE__ */ r.jsx("button", { type: "button", className: "px-2 py-1 border rounded", onClick: ve, disabled: J, children: "Clear" })
1423
+ ] }),
1424
+ (Array.isArray(O.conditions) ? O.conditions : []).map((d, C) => {
1425
+ const I = _(d.targetId), Y = Qe(I == null ? void 0 : I.fieldType), A = Array.isArray(I == null ? void 0 : I.options) ? I.options.map(Ze) : [], U = A.length > 0;
1426
+ return /* @__PURE__ */ r.jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-7 gap-2 items-center opacity-100", children: [
1427
+ /* @__PURE__ */ r.jsx(
1428
+ "button",
1429
+ {
1430
+ type: "button",
1431
+ onClick: () => ge(C),
1432
+ className: "px-2 py-1 border rounded sm:col-span-1",
1433
+ title: "Remove condition",
1434
+ disabled: J,
1435
+ children: "✕"
1436
+ }
1437
+ ),
1438
+ /* @__PURE__ */ r.jsxs(
1439
+ "select",
1440
+ {
1441
+ className: "border p-1 rounded sm:col-span-3",
1442
+ value: d.targetId,
1443
+ onChange: (y) => X(C, { targetId: y.target.value }),
1444
+ disabled: J,
1445
+ children: [
1446
+ /* @__PURE__ */ r.jsx("option", { value: "", children: "— Select field —" }),
1447
+ oe.map((y) => /* @__PURE__ */ r.jsx("option", { value: y.id, children: y.label }, y.id))
1448
+ ]
1449
+ }
1450
+ ),
1451
+ /* @__PURE__ */ r.jsx(
1452
+ "select",
1453
+ {
1454
+ className: "border p-1 rounded sm:col-span-1",
1455
+ value: d.operator,
1456
+ onChange: (y) => X(C, { operator: y.target.value }),
1457
+ disabled: J || !I,
1458
+ children: (I ? Y : ["equals"]).map((y) => /* @__PURE__ */ r.jsx("option", { value: y, children: y }, y))
1459
+ }
1460
+ ),
1461
+ U ? /* @__PURE__ */ r.jsxs(
1462
+ "select",
1463
+ {
1464
+ className: "border p-1 rounded sm:col-span-2",
1465
+ value: d.value,
1466
+ onChange: (y) => X(C, { value: y.target.value }),
1467
+ disabled: J || !I,
1468
+ children: [
1469
+ /* @__PURE__ */ r.jsx("option", { value: "", children: "— Select option —" }),
1470
+ A.map((y) => /* @__PURE__ */ r.jsx("option", { value: y.id, children: y.value }, y.id))
1471
+ ]
1472
+ }
1473
+ ) : /* @__PURE__ */ r.jsx(
1474
+ "input",
1475
+ {
1476
+ className: "border p-1 rounded sm:col-span-2",
1477
+ placeholder: "Enter value",
1478
+ value: d.value,
1479
+ onChange: (y) => X(C, { value: y.target.value }),
1480
+ disabled: J || !I
1481
+ }
1482
+ )
1483
+ ] }, C);
868
1484
  })
869
- )), /* @__PURE__ */ React10.createElement("div", { className: "flex gap-2 items-center" }, /* @__PURE__ */ React10.createElement("label", { className: "text-sm" }, "Logic:"), /* @__PURE__ */ React10.createElement(
870
- "select",
871
- {
872
- value: ew.logic || "AND",
873
- onChange: (e) => writeEnableWhen({ ...ew, logic: e.target.value }),
874
- className: "border p-1 rounded",
875
- disabled: isDisabled
876
- },
877
- /* @__PURE__ */ React10.createElement("option", { value: "AND" }, "AND"),
878
- /* @__PURE__ */ React10.createElement("option", { value: "OR" }, "OR")
879
- ), /* @__PURE__ */ React10.createElement("button", { type: "button", className: "px-2 py-1 border rounded", onClick: addCond, disabled: isDisabled }, "+ Condition"), /* @__PURE__ */ React10.createElement("button", { type: "button", className: "px-2 py-1 border rounded", onClick: clear, disabled: isDisabled }, "Clear")), (Array.isArray(ew.conditions) ? ew.conditions : []).map((c, i) => {
880
- const meta = findTarget(c.targetId);
881
- const allowedOps = getOperatorsForFieldType(meta == null ? void 0 : meta.fieldType);
882
- const optList = Array.isArray(meta == null ? void 0 : meta.options) ? meta.options.map(normOption) : [];
883
- const hasOptions = optList.length > 0;
884
- return /* @__PURE__ */ React10.createElement("div", { key: i, className: "grid grid-cols-1 sm:grid-cols-7 gap-2 items-center opacity-100" }, /* @__PURE__ */ React10.createElement(
885
- "button",
886
- {
887
- type: "button",
888
- onClick: () => removeCond(i),
889
- className: "px-2 py-1 border rounded sm:col-span-1",
890
- title: "Remove condition",
891
- disabled: isDisabled
892
- },
893
- "\u2715"
894
- ), /* @__PURE__ */ React10.createElement(
895
- "select",
896
- {
897
- className: "border p-1 rounded sm:col-span-3",
898
- value: c.targetId,
899
- onChange: (e) => updateCond(i, { targetId: e.target.value }),
900
- disabled: isDisabled
901
- },
902
- /* @__PURE__ */ React10.createElement("option", { value: "" }, "\u2014 Select field \u2014"),
903
- filteredTargets.map((t) => /* @__PURE__ */ React10.createElement("option", { key: t.id, value: t.id }, t.label))
904
- ), /* @__PURE__ */ React10.createElement(
905
- "select",
906
- {
907
- className: "border p-1 rounded sm:col-span-1",
908
- value: c.operator,
909
- onChange: (e) => updateCond(i, { operator: e.target.value }),
910
- disabled: isDisabled || !meta
911
- },
912
- (meta ? allowedOps : ["equals"]).map((op) => /* @__PURE__ */ React10.createElement("option", { key: op, value: op }, op))
913
- ), hasOptions ? /* @__PURE__ */ React10.createElement(
914
- "select",
915
- {
916
- className: "border p-1 rounded sm:col-span-2",
917
- value: c.value,
918
- onChange: (e) => updateCond(i, { value: e.target.value }),
919
- disabled: isDisabled || !meta
920
- },
921
- /* @__PURE__ */ React10.createElement("option", { value: "" }, "\u2014 Select option \u2014"),
922
- optList.map((opt) => /* @__PURE__ */ React10.createElement("option", { key: opt.id, value: opt.id }, opt.value))
923
- ) : /* @__PURE__ */ React10.createElement(
924
- "input",
925
- {
926
- className: "border p-1 rounded sm:col-span-2",
927
- placeholder: "Enter value",
928
- value: c.value,
929
- onChange: (e) => updateCond(i, { value: e.target.value }),
930
- disabled: isDisabled || !meta
931
- }
932
- ));
933
- }));
1485
+ ] });
934
1486
  }
935
-
936
- // src/components/desktopLayout/editPanel/EditPanel.jsx
937
- import { useUIApi as useUIApi4, useFormStore as useFormStore6 } from "@mieweb/forms-engine";
938
- function EditPanel() {
939
- const ui = useUIApi4();
940
- const selectedField = useFormStore6(
941
- React11.useCallback(
942
- (s) => ui.selectedFieldId.value ? s.byId[ui.selectedFieldId.value] : null,
943
- [ui.selectedFieldId.value]
1487
+ function er() {
1488
+ const t = H(), n = q(
1489
+ E.useCallback(
1490
+ (c) => t.selectedFieldId.value ? c.byId[t.selectedFieldId.value] : null,
1491
+ [t.selectedFieldId.value]
944
1492
  )
945
- );
946
- const [tab, setTab] = React11.useState("EDIT");
947
- const handleActiveChildChange = React11.useCallback(
948
- (sectionId, childId) => {
949
- ui.selectedChildId.set(sectionId, childId);
1493
+ ), [s, i] = E.useState("EDIT"), o = E.useCallback(
1494
+ (c, f) => {
1495
+ t.selectedChildId.set(c, f);
950
1496
  },
951
- [ui.selectedChildId.set]
1497
+ [t.selectedChildId.set]
952
1498
  );
953
- React11.useEffect(() => {
954
- ui.selectedChildId.set(null, null);
955
- setTab("EDIT");
956
- }, [ui.selectedFieldId.value]);
957
- if (ui.state.isPreview) return null;
958
- const isNone = !selectedField;
959
- const isSection = (selectedField == null ? void 0 : selectedField.fieldType) === "section";
960
- return /* @__PURE__ */ React11.createElement(
1499
+ if (E.useEffect(() => {
1500
+ t.selectedChildId.set(null, null), i("EDIT");
1501
+ }, [t.selectedFieldId.value]), t.state.isPreview) return null;
1502
+ const u = !n, b = (n == null ? void 0 : n.fieldType) === "section";
1503
+ return /* @__PURE__ */ r.jsxs(
961
1504
  "div",
962
1505
  {
963
1506
  className: `p-4 bg-white border border-gray-200 rounded-lg shadow-sm overflow-y-auto custom-scrollbar
964
- ${selectedField ? "" : "max-h-32"} max-h-[calc(100svh-19rem)] lg:max-h-[calc(100dvh-15rem)]`
965
- },
966
- /* @__PURE__ */ React11.createElement(
967
- "div",
968
- {
969
- className: "sticky top-0 z-30 mb-4 inline-flex rounded-md border border-gray-200 overflow-hidden bg-white",
970
- role: "tablist"
971
- },
972
- /* @__PURE__ */ React11.createElement(
973
- "button",
974
- {
975
- type: "button",
976
- onClick: () => setTab("EDIT"),
977
- "aria-selected": tab === "EDIT",
978
- className: `px-3 py-1 text-sm ${tab === "EDIT" ? "bg-gray-100 font-semibold" : "bg-white"}`
979
- },
980
- "EDIT"
981
- ),
982
- /* @__PURE__ */ React11.createElement(
983
- "button",
984
- {
985
- type: "button",
986
- onClick: () => setTab("LOGIC"),
987
- "aria-selected": tab === "LOGIC",
988
- className: `px-3 py-1 text-sm border-l border-gray-200 ${tab === "LOGIC" ? "bg-gray-100 font-semibold" : "bg-white"}`
989
- },
990
- "LOGIC"
991
- )
992
- ),
993
- isNone && /* @__PURE__ */ React11.createElement("div", { className: "text-gray-600" }, /* @__PURE__ */ React11.createElement("h3", { className: "text-lg font-semibold mb-2" }, "Edit"), /* @__PURE__ */ React11.createElement("p", null, "Select a field in the center panel to edit its properties.")),
994
- !isNone && tab === "EDIT" && /* @__PURE__ */ React11.createElement(React11.Fragment, null, !isSection && /* @__PURE__ */ React11.createElement(NonSectionEditor_default, { f: selectedField }), isSection && /* @__PURE__ */ React11.createElement(
995
- SectionEditor_default,
996
- {
997
- section: selectedField,
998
- onActiveChildChange: handleActiveChildChange
999
- }
1000
- )),
1001
- !isNone && tab === "LOGIC" && /* @__PURE__ */ React11.createElement(LogicEditor, null)
1507
+ ${n ? "" : "max-h-32"} max-h-[calc(100svh-19rem)] lg:max-h-[calc(100dvh-15rem)]`,
1508
+ children: [
1509
+ /* @__PURE__ */ r.jsxs(
1510
+ "div",
1511
+ {
1512
+ className: "sticky top-0 z-30 mb-4 inline-flex rounded-md border border-gray-200 overflow-hidden bg-white",
1513
+ role: "tablist",
1514
+ children: [
1515
+ /* @__PURE__ */ r.jsx(
1516
+ "button",
1517
+ {
1518
+ type: "button",
1519
+ onClick: () => i("EDIT"),
1520
+ "aria-selected": s === "EDIT",
1521
+ className: `px-3 py-1 text-sm ${s === "EDIT" ? "bg-gray-100 font-semibold" : "bg-white"}`,
1522
+ children: "EDIT"
1523
+ }
1524
+ ),
1525
+ /* @__PURE__ */ r.jsx(
1526
+ "button",
1527
+ {
1528
+ type: "button",
1529
+ onClick: () => i("LOGIC"),
1530
+ "aria-selected": s === "LOGIC",
1531
+ className: `px-3 py-1 text-sm border-l border-gray-200 ${s === "LOGIC" ? "bg-gray-100 font-semibold" : "bg-white"}`,
1532
+ children: "LOGIC"
1533
+ }
1534
+ )
1535
+ ]
1536
+ }
1537
+ ),
1538
+ u && /* @__PURE__ */ r.jsxs("div", { className: "text-gray-600", children: [
1539
+ /* @__PURE__ */ r.jsx("h3", { className: "text-lg font-semibold mb-2", children: "Edit" }),
1540
+ /* @__PURE__ */ r.jsx("p", { children: "Select a field in the center panel to edit its properties." })
1541
+ ] }),
1542
+ !u && s === "EDIT" && /* @__PURE__ */ r.jsxs(r.Fragment, { children: [
1543
+ !b && /* @__PURE__ */ r.jsx(et, { f: n }),
1544
+ b && /* @__PURE__ */ r.jsx(
1545
+ rt,
1546
+ {
1547
+ section: n,
1548
+ onActiveChildChange: o
1549
+ }
1550
+ )
1551
+ ] }),
1552
+ !u && s === "LOGIC" && /* @__PURE__ */ r.jsx(tt, {})
1553
+ ]
1554
+ }
1002
1555
  );
1003
1556
  }
1004
-
1005
- // src/components/FormBuilderMain.jsx
1006
- import React12, { useMemo as useMemo4 } from "react";
1007
- import { fieldTypes as fieldTypes4, getFieldComponent, useFieldsArray as useFieldsArray3, useFormStore as useFormStore7, useUIApi as useUIApi5, isVisible } from "@mieweb/forms-engine";
1008
- function FormBuilderMain() {
1009
- const ui = useUIApi5();
1010
- const fields = useFieldsArray3();
1011
- const allFlat = useMemo4(() => {
1012
- const out = [];
1013
- (fields || []).forEach((f) => {
1014
- out.push(f);
1015
- if ((f == null ? void 0 : f.fieldType) === "section" && Array.isArray(f.fields)) out.push(...f.fields);
1016
- });
1017
- return out;
1018
- }, [fields]);
1019
- const visibleIds = useMemo4(() => {
1020
- const list = ui.state.isPreview ? fields.filter((f) => isVisible(f, allFlat)) : fields;
1021
- return list.map((f) => f.id);
1022
- }, [ui.state.isPreview, fields, allFlat]);
1023
- return /* @__PURE__ */ React12.createElement(
1557
+ function nt() {
1558
+ const t = H(), n = Ie(), s = re(() => {
1559
+ const o = [];
1560
+ return (n || []).forEach((u) => {
1561
+ o.push(u), (u == null ? void 0 : u.fieldType) === "section" && Array.isArray(u.fields) && o.push(...u.fields);
1562
+ }), o;
1563
+ }, [n]), i = re(() => (t.state.isPreview ? n.filter((u) => Lr(u, s)) : n).map((u) => u.id), [t.state.isPreview, n, s]);
1564
+ return /* @__PURE__ */ r.jsx(
1024
1565
  "div",
1025
1566
  {
1026
1567
  className: "w-full max-w-4xl mx-auto rounded-lg overflow-y-auto max-h-[calc(100svh-19rem)] lg:max-h-[calc(100dvh-15rem)] custom-scrollbar pr-2",
1027
- onClick: () => !ui.state.isPreview && ui.selectedFieldId.clear()
1028
- },
1029
- visibleIds.length === 0 ? /* @__PURE__ */ React12.createElement(EmptyState, null) : visibleIds.map((id) => /* @__PURE__ */ React12.createElement(FieldRow, { key: id, id }))
1568
+ onClick: () => !t.state.isPreview && t.selectedFieldId.clear(),
1569
+ children: i.length === 0 ? /* @__PURE__ */ r.jsx(st, {}) : i.map((o) => /* @__PURE__ */ r.jsx(at, { id: o }, o))
1570
+ }
1030
1571
  );
1031
1572
  }
1032
- var FieldRow = React12.memo(function FieldRow2({ id }) {
1033
- const field = useFormStore7(React12.useCallback((s) => s.byId[id], [id]));
1034
- if (!field) return null;
1035
- const FieldComponent = getFieldComponent(field.fieldType);
1036
- if (!FieldComponent) return null;
1037
- return /* @__PURE__ */ React12.createElement("div", { className: "mb-1.5", "data-field-type": field.fieldType, "data-field-id": field.id }, /* @__PURE__ */ React12.createElement(FieldComponent, { field }));
1573
+ const at = E.memo(function({ id: n }) {
1574
+ const s = q(E.useCallback((o) => o.byId[n], [n]));
1575
+ if (!s) return null;
1576
+ const i = Mr(s.fieldType);
1577
+ return i ? /* @__PURE__ */ r.jsx("div", { className: "mb-1.5", "data-field-type": s.fieldType, "data-field-id": s.id, children: /* @__PURE__ */ r.jsx(i, { field: s }) }) : null;
1038
1578
  });
1039
- function EmptyState() {
1040
- return /* @__PURE__ */ React12.createElement("div", { className: "flex flex-col items-center justify-center h-72 bg-gradient-to-br from-gray-50 to-gray-100 border-2 border-dashed border-blue-200 rounded-xl shadow-md text-center px-8 py-10" }, /* @__PURE__ */ React12.createElement("div", { className: "text-xl font-semibold text-gray-700 mb-2" }, "Start building your questionnaire"), /* @__PURE__ */ React12.createElement("div", { className: "text-base text-gray-500" }, "Add tools with ", /* @__PURE__ */ React12.createElement("span", { className: "font-semibold text-blue-500" }, "Tool Panel"), " on the left.", /* @__PURE__ */ React12.createElement("br", null), "Select fields to edit on the ", /* @__PURE__ */ React12.createElement("span", { className: "font-semibold text-blue-500" }, "Edit Panel"), " on the left."));
1579
+ function st() {
1580
+ return /* @__PURE__ */ r.jsxs("div", { className: "flex flex-col items-center justify-center h-72 bg-gradient-to-br from-gray-50 to-gray-100 border-2 border-dashed border-blue-200 rounded-xl shadow-md text-center px-8 py-10", children: [
1581
+ /* @__PURE__ */ r.jsx("div", { className: "text-xl font-semibold text-gray-700 mb-2", children: "Start building your questionnaire" }),
1582
+ /* @__PURE__ */ r.jsxs("div", { className: "text-base text-gray-500", children: [
1583
+ "Add tools with ",
1584
+ /* @__PURE__ */ r.jsx("span", { className: "font-semibold text-blue-500", children: "Tool Panel" }),
1585
+ " on the left.",
1586
+ /* @__PURE__ */ r.jsx("br", {}),
1587
+ "Select fields to edit on the ",
1588
+ /* @__PURE__ */ r.jsx("span", { className: "font-semibold text-blue-500", children: "Edit Panel" }),
1589
+ " on the left."
1590
+ ] })
1591
+ ] });
1041
1592
  }
1042
-
1043
- // src/components/desktopLayout/Layout.jsx
1044
- import { useUIApi as useUIApi6 } from "@mieweb/forms-engine";
1045
- function Layout({ selectedField }) {
1046
- const ui = useUIApi6();
1047
- const isPreview = ui.state.isPreview;
1048
- const isEditModalOpen = ui.state.isEditModalOpen;
1049
- const panelResetKey = ui.state.panelResetKey;
1050
- const editMode = !isPreview;
1051
- const cols = editMode ? "lg:grid-cols-[280px_minmax(0,1fr)_320px]" : "lg:grid-cols-[minmax(0,1fr)]";
1052
- return /* @__PURE__ */ React13.createElement("div", { className: "w-full max-w-6xl mx-auto px-4 h-fit rounded-lg mt-2" }, /* @__PURE__ */ React13.createElement("div", { className: `grid grid-cols-1 ${cols} gap-3 h-full items-start` }, editMode && /* @__PURE__ */ React13.createElement("div", { className: "hidden lg:block" }, /* @__PURE__ */ React13.createElement(ToolPanel_default, null)), /* @__PURE__ */ React13.createElement("div", null, /* @__PURE__ */ React13.createElement(FormBuilderMain, null)), editMode && /* @__PURE__ */ React13.createElement("div", { className: "hidden lg:block" }, /* @__PURE__ */ React13.createElement(EditPanel, { key: panelResetKey })), editMode && /* @__PURE__ */ React13.createElement("div", { className: "lg:hidden" }, isEditModalOpen && selectedField && /* @__PURE__ */ React13.createElement(
1053
- "div",
1054
- {
1055
- className: "fixed inset-0 top-5 z-50 flex items-center justify-center bg-transparent/30 backdrop-blur-sm p-4",
1056
- onClick: () => ui.modal.set(false)
1057
- },
1058
- /* @__PURE__ */ React13.createElement(
1593
+ function it({ selectedField: t }) {
1594
+ const n = H(), s = n.state.isPreview, i = n.state.isEditModalOpen, o = n.state.panelResetKey, u = !s, b = u ? "lg:grid-cols-[280px_minmax(0,1fr)_320px]" : "lg:grid-cols-[minmax(0,1fr)]";
1595
+ return /* @__PURE__ */ r.jsx("div", { className: "w-full max-w-6xl mx-auto px-4 h-fit rounded-lg mt-2", children: /* @__PURE__ */ r.jsxs("div", { className: `grid grid-cols-1 ${b} gap-3 h-full items-start`, children: [
1596
+ u && /* @__PURE__ */ r.jsx("div", { className: "hidden lg:block", children: /* @__PURE__ */ r.jsx(Gr, {}) }),
1597
+ /* @__PURE__ */ r.jsx("div", { children: /* @__PURE__ */ r.jsx(nt, {}) }),
1598
+ u && /* @__PURE__ */ r.jsx("div", { className: "hidden lg:block", children: /* @__PURE__ */ r.jsx(er, {}, o) }),
1599
+ u && /* @__PURE__ */ r.jsx("div", { className: "lg:hidden", children: i && t && /* @__PURE__ */ r.jsx(
1059
1600
  "div",
1060
1601
  {
1061
- className: "w-full max-w-md mx-auto relative bg-white rounded-lg overflow-hidden",
1062
- onClick: (e) => e.stopPropagation()
1063
- },
1064
- /* @__PURE__ */ React13.createElement(
1065
- "button",
1066
- {
1067
- className: "absolute top-3 right-7 text-gray-500",
1068
- onClick: () => ui.modal.set(false)
1069
- },
1070
- /* @__PURE__ */ React13.createElement("span", { className: "text-3xl" }, "\xD7")
1071
- ),
1072
- /* @__PURE__ */ React13.createElement(EditPanel, { key: panelResetKey })
1073
- )
1074
- ))));
1602
+ className: "fixed inset-0 top-5 z-50 flex items-center justify-center bg-transparent/30 backdrop-blur-sm p-4",
1603
+ onClick: () => n.modal.set(!1),
1604
+ children: /* @__PURE__ */ r.jsxs(
1605
+ "div",
1606
+ {
1607
+ className: "w-full max-w-md mx-auto relative bg-white rounded-lg overflow-hidden",
1608
+ onClick: (c) => c.stopPropagation(),
1609
+ children: [
1610
+ /* @__PURE__ */ r.jsx(
1611
+ "button",
1612
+ {
1613
+ className: "absolute top-3 right-7 text-gray-500",
1614
+ onClick: () => n.modal.set(!1),
1615
+ children: /* @__PURE__ */ r.jsx("span", { className: "text-3xl", children: "×" })
1616
+ }
1617
+ ),
1618
+ /* @__PURE__ */ r.jsx(er, {}, o)
1619
+ ]
1620
+ }
1621
+ )
1622
+ }
1623
+ ) })
1624
+ ] }) });
1075
1625
  }
1076
-
1077
- // src/QuestionnaireEditor.jsx
1078
- import {
1079
- useFormStore as useFormStore8,
1080
- useFormApi as useFormApi3,
1081
- useUIApi as useUIApi7,
1082
- useFieldsArray as useFieldsArray4
1083
- } from "@mieweb/forms-engine";
1084
- function QuestionnaireEditor({
1085
- initialFields,
1086
- onChange,
1087
- className = "",
1088
- showHeader = true,
1089
- showMobileToolbar = true,
1090
- startInPreview = false
1626
+ function ut({
1627
+ initialFields: t,
1628
+ onChange: n,
1629
+ className: s = "",
1630
+ showHeader: i = !0,
1631
+ showMobileToolbar: o = !0,
1632
+ startInPreview: u = !1
1091
1633
  }) {
1092
- const ui = useUIApi7();
1093
- const formStoreInitialized = useRef2(false);
1094
- useEffect3(() => {
1095
- if (formStoreInitialized.current) return;
1096
- if (Array.isArray(initialFields) && initialFields.length) {
1097
- useFormStore8.getState().replaceAll(initialFields);
1098
- }
1099
- ui.preview.set(!!startInPreview);
1100
- formStoreInitialized.current = true;
1101
- }, [initialFields, startInPreview, ui.preview]);
1102
- useEffect3(() => {
1103
- if (!onChange) return;
1104
- const unsub = useFormStore8.subscribe((s) => {
1105
- const arr = s.flatArray ? s.flatArray() : Object.values(s.byId);
1106
- onChange(arr);
1107
- });
1108
- return unsub;
1109
- }, [onChange]);
1110
- const selectedField = useFormStore8(
1111
- React14.useCallback(
1112
- (s) => ui.selectedFieldId.value ? s.byId[ui.selectedFieldId.value] : null,
1113
- [ui.selectedFieldId.value]
1634
+ const b = H(), c = rr(!1);
1635
+ ee(() => {
1636
+ c.current || (Array.isArray(t) && t.length && q.getState().replaceAll(t), b.preview.set(!!u), c.current = !0);
1637
+ }, [t, u, b.preview]), ee(() => n ? q.subscribe((m) => {
1638
+ const p = m.flatArray ? m.flatArray() : Object.values(m.byId);
1639
+ n(p);
1640
+ }) : void 0, [n]);
1641
+ const f = q(
1642
+ E.useCallback(
1643
+ (g) => b.selectedFieldId.value ? g.byId[b.selectedFieldId.value] : null,
1644
+ [b.selectedFieldId.value]
1114
1645
  )
1115
1646
  );
1116
- return /* @__PURE__ */ React14.createElement("div", { className: `qb-editor-root min-h-screen bg-gray-100 font-titillium ${className}` }, showHeader && /* @__PURE__ */ React14.createElement(Header, null), showMobileToolbar && /* @__PURE__ */ React14.createElement("div", { className: "lg:hidden" }, /* @__PURE__ */ React14.createElement(MobileToolBar, null)), /* @__PURE__ */ React14.createElement(Layout, { selectedField }));
1647
+ return /* @__PURE__ */ r.jsxs("div", { className: `qb-editor-root min-h-screen bg-gray-100 font-titillium ${s}`, children: [
1648
+ i && /* @__PURE__ */ r.jsx(Br, {}),
1649
+ o && /* @__PURE__ */ r.jsx("div", { className: "lg:hidden", children: /* @__PURE__ */ r.jsx(Jr, {}) }),
1650
+ /* @__PURE__ */ r.jsx(it, { selectedField: f })
1651
+ ] });
1117
1652
  }
1118
1653
  export {
1119
- QuestionnaireEditor
1654
+ ut as QuestionnaireEditor
1120
1655
  };
1656
+ //# sourceMappingURL=index.js.map