@superdoc-dev/template-builder 1.1.0 → 1.2.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,1105 +1,988 @@
1
- import { jsxs as o, jsx as r } from "react/jsx-runtime";
2
- import { useState as E, useEffect as oe, useMemo as pe, forwardRef as We, useRef as q, useCallback as S, useImperativeHandle as He } from "react";
3
- const Le = ({
4
- isVisible: n,
5
- position: l,
6
- availableFields: m,
7
- filteredFields: s,
8
- filterQuery: p,
9
- allowCreate: c,
10
- onSelect: N,
11
- onClose: H,
12
- onCreateField: G,
13
- existingFields: f = [],
14
- onSelectExisting: T
15
- }) => {
16
- const [y, I] = E(!1), [u, L] = E(""), [P, z] = E("inline"), [Q, ie] = E(!0), [X, g] = E(!0);
17
- oe(() => {
18
- n || (I(!1), L(""), z("inline"));
19
- }, [n]);
20
- const A = pe(() => ({
21
- position: "absolute",
22
- left: l?.left,
23
- top: l?.top,
24
- zIndex: 1e3,
25
- background: "white",
26
- border: "1px solid #ddd",
27
- borderRadius: "4px",
28
- boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
29
- padding: "8px 0",
30
- width: "280px"
31
- }), [l]), R = s ?? m, O = !!p;
32
- if (oe(() => {
33
- O && g(!0);
34
- }, [O]), !n) return null;
35
- const _ = async () => {
36
- const a = u.trim();
37
- if (!a) return;
38
- const V = {
39
- id: `custom_${Date.now()}`,
40
- label: a,
41
- mode: P
42
- };
43
- try {
44
- if (G) {
45
- const b = await G(V);
46
- N(b || V);
47
- } else
48
- N(V);
49
- } finally {
50
- I(!1), L(""), z("inline");
51
- }
52
- };
53
- return /* @__PURE__ */ o("div", { className: "superdoc-field-menu", style: A, children: [
54
- O && /* @__PURE__ */ r(
55
- "div",
56
- {
57
- style: {
58
- padding: "8px 16px",
59
- borderBottom: "1px solid #f0f0f0",
60
- marginBottom: "4px"
61
- },
62
- children: /* @__PURE__ */ o("div", { style: { fontSize: "12px", color: "#6b7280" }, children: [
63
- "Filtering results for",
64
- /* @__PURE__ */ r("span", { style: { fontWeight: 600, color: "#111827", marginLeft: "4px" }, children: p })
65
- ] })
66
- }
67
- ),
68
- c && !y && /* @__PURE__ */ r(
69
- "div",
70
- {
71
- className: "field-menu-item",
72
- onClick: () => I(!0),
73
- style: {
74
- padding: "8px 16px",
75
- cursor: "pointer",
76
- color: "#0066cc",
77
- fontWeight: 500
78
- },
79
- children: "+ Create New Field"
80
- }
81
- ),
82
- c && y && /* @__PURE__ */ o("div", { style: { padding: "8px 16px" }, children: [
83
- /* @__PURE__ */ r(
84
- "input",
85
- {
86
- type: "text",
87
- value: u,
88
- placeholder: "Field name...",
89
- onChange: (a) => L(a.target.value),
90
- onKeyDown: (a) => {
91
- a.key === "Enter" && _(), a.key === "Escape" && (I(!1), L(""), z("inline"));
92
- },
93
- autoFocus: !0,
94
- style: {
95
- width: "100%",
96
- padding: "4px 8px",
97
- border: "1px solid #ddd",
98
- borderRadius: "3px"
99
- }
100
- }
101
- ),
102
- /* @__PURE__ */ o(
103
- "div",
104
- {
105
- style: {
106
- marginTop: "8px",
107
- display: "flex",
108
- gap: "12px",
109
- fontSize: "13px"
110
- },
111
- children: [
112
- /* @__PURE__ */ o(
113
- "label",
114
- {
115
- style: {
116
- display: "flex",
117
- alignItems: "center",
118
- gap: "4px",
119
- cursor: "pointer"
120
- },
121
- children: [
122
- /* @__PURE__ */ r(
123
- "input",
124
- {
125
- type: "radio",
126
- value: "inline",
127
- checked: P === "inline",
128
- onChange: () => z("inline")
129
- }
130
- ),
131
- "Inline"
132
- ]
133
- }
134
- ),
135
- /* @__PURE__ */ o(
136
- "label",
137
- {
138
- style: {
139
- display: "flex",
140
- alignItems: "center",
141
- gap: "4px",
142
- cursor: "pointer"
143
- },
144
- children: [
145
- /* @__PURE__ */ r(
146
- "input",
147
- {
148
- type: "radio",
149
- value: "block",
150
- checked: P === "block",
151
- onChange: () => z("block")
152
- }
153
- ),
154
- "Block"
155
- ]
156
- }
157
- )
158
- ]
159
- }
160
- ),
161
- /* @__PURE__ */ o(
162
- "div",
163
- {
164
- style: {
165
- marginTop: "8px",
166
- display: "flex",
167
- gap: "8px"
168
- },
169
- children: [
170
- /* @__PURE__ */ r(
171
- "button",
172
- {
173
- onClick: _,
174
- disabled: !u.trim(),
175
- style: {
176
- padding: "4px 12px",
177
- background: u.trim() ? "#0066cc" : "#ccc",
178
- color: "white",
179
- border: "none",
180
- borderRadius: "3px",
181
- cursor: u.trim() ? "pointer" : "not-allowed"
182
- },
183
- children: "Create"
184
- }
185
- ),
186
- /* @__PURE__ */ r(
187
- "button",
188
- {
189
- onClick: () => {
190
- I(!1), L(""), z("inline");
191
- },
192
- style: {
193
- padding: "4px 12px",
194
- background: "white",
195
- border: "1px solid #ddd",
196
- borderRadius: "3px",
197
- cursor: "pointer"
198
- },
199
- children: "Cancel"
200
- }
201
- )
202
- ]
203
- }
204
- )
205
- ] }),
206
- c && m.length > 0 && /* @__PURE__ */ r(
207
- "div",
208
- {
209
- style: {
210
- borderTop: "1px solid #eee",
211
- margin: "4px 0"
212
- }
213
- }
214
- ),
215
- f.length > 0 && (() => {
216
- const a = /* @__PURE__ */ new Map();
217
- f.forEach((b) => {
218
- const Y = b.group || `individual-${b.id}`, ee = a.get(Y) || [];
219
- ee.push(b), a.set(Y, ee);
220
- });
221
- const V = Array.from(a.values()).map((b) => ({
222
- ...b[0],
223
- count: b.length
224
- }));
225
- return /* @__PURE__ */ o("div", { style: { borderBottom: "1px solid #f0f0f0" }, children: [
226
- /* @__PURE__ */ o(
227
- "button",
228
- {
229
- type: "button",
230
- onClick: () => ie(!Q),
231
- style: {
232
- width: "100%",
233
- display: "flex",
234
- alignItems: "center",
235
- justifyContent: "space-between",
236
- padding: "8px 16px",
237
- background: "transparent",
238
- border: "none",
239
- cursor: "pointer",
240
- fontWeight: 500,
241
- fontSize: "13px",
242
- color: "#374151",
243
- textAlign: "left"
244
- },
245
- children: [
246
- /* @__PURE__ */ o("span", { children: [
247
- "Existing Fields (",
248
- V.length,
249
- ")"
250
- ] }),
251
- /* @__PURE__ */ r(
252
- "span",
253
- {
254
- "aria-hidden": !0,
255
- style: {
256
- display: "inline-block",
257
- width: "8px",
258
- height: "8px",
259
- borderRight: "2px solid #666",
260
- borderBottom: "2px solid #666",
261
- transform: Q ? "rotate(45deg)" : "rotate(-45deg)",
262
- transition: "transform 0.2s ease"
263
- }
264
- }
265
- )
266
- ]
267
- }
268
- ),
269
- Q && /* @__PURE__ */ r("div", { style: { maxHeight: "300px", overflowY: "auto" }, children: V.map((b) => /* @__PURE__ */ o(
270
- "div",
271
- {
272
- className: "field-menu-item",
273
- onClick: () => T?.(b),
274
- style: {
275
- padding: "8px 16px",
276
- cursor: "pointer",
277
- display: "flex",
278
- alignItems: "flex-start",
279
- justifyContent: "space-between",
280
- gap: "8px"
281
- },
282
- children: [
283
- /* @__PURE__ */ o("div", { style: { flex: 1, minWidth: 0 }, children: [
284
- /* @__PURE__ */ r("div", { style: { fontWeight: 500, fontSize: "13px" }, children: b.alias || b.id }),
285
- /* @__PURE__ */ r(
286
- "div",
287
- {
288
- style: {
289
- fontSize: "11px",
290
- color: "#9ca3af",
291
- marginTop: "2px"
292
- },
293
- children: b.group ? `group (${b.count} fields)` : `ID: ${b.id}`
294
- }
295
- )
296
- ] }),
297
- /* @__PURE__ */ r(
298
- "span",
299
- {
300
- style: {
301
- fontSize: "11px",
302
- color: "#6b7280",
303
- padding: "2px 6px",
304
- background: "#f3f4f6",
305
- borderRadius: "3px",
306
- textTransform: "capitalize",
307
- flexShrink: 0
308
- },
309
- children: b.mode || "inline"
310
- }
311
- )
312
- ]
313
- },
314
- b.group || b.id
315
- )) })
316
- ] });
317
- })(),
318
- R.length === 0 ? /* @__PURE__ */ r(
319
- "div",
320
- {
321
- style: {
322
- padding: "16px",
323
- fontSize: "13px",
324
- color: "#6b7280",
325
- textAlign: "center"
326
- },
327
- children: "No matching fields"
328
- }
329
- ) : /* @__PURE__ */ o("div", { style: { borderBottom: "1px solid #f0f0f0" }, children: [
330
- /* @__PURE__ */ o(
331
- "button",
332
- {
333
- type: "button",
334
- onClick: () => g(!X),
335
- style: {
336
- width: "100%",
337
- display: "flex",
338
- alignItems: "center",
339
- justifyContent: "space-between",
340
- padding: "8px 16px",
341
- background: "transparent",
342
- border: "none",
343
- cursor: "pointer",
344
- fontWeight: 500,
345
- fontSize: "13px",
346
- color: "#374151",
347
- textAlign: "left"
348
- },
349
- children: [
350
- /* @__PURE__ */ o("span", { children: [
351
- "Available Fields (",
352
- R.length,
353
- ")"
354
- ] }),
355
- /* @__PURE__ */ r(
356
- "span",
357
- {
358
- "aria-hidden": !0,
359
- style: {
360
- display: "inline-block",
361
- width: "8px",
362
- height: "8px",
363
- borderRight: "2px solid #666",
364
- borderBottom: "2px solid #666",
365
- transform: X ? "rotate(45deg)" : "rotate(-45deg)",
366
- transition: "transform 0.2s ease"
367
- }
368
- }
369
- )
370
- ]
371
- }
372
- ),
373
- X && /* @__PURE__ */ r("div", { style: { maxHeight: "300px", overflowY: "auto" }, children: R.map((a) => /* @__PURE__ */ o(
374
- "div",
375
- {
376
- className: "field-menu-item",
377
- onClick: () => N(a),
378
- style: {
379
- padding: "8px 16px",
380
- cursor: "pointer",
381
- display: "flex",
382
- alignItems: "flex-start",
383
- justifyContent: "space-between",
384
- gap: "8px"
385
- },
386
- children: [
387
- /* @__PURE__ */ o("div", { style: { flex: 1, minWidth: 0 }, children: [
388
- /* @__PURE__ */ r("div", { style: { fontWeight: 500, fontSize: "13px" }, children: a.label || a.id }),
389
- /* @__PURE__ */ o(
390
- "div",
391
- {
392
- style: {
393
- fontSize: "11px",
394
- color: "#9ca3af",
395
- marginTop: "2px"
396
- },
397
- children: [
398
- "ID: ",
399
- a.id
400
- ]
401
- }
402
- )
403
- ] }),
404
- /* @__PURE__ */ r(
405
- "span",
406
- {
407
- style: {
408
- fontSize: "11px",
409
- color: "#6b7280",
410
- padding: "2px 6px",
411
- background: "#f3f4f6",
412
- borderRadius: "3px",
413
- textTransform: "capitalize",
414
- flexShrink: 0
415
- },
416
- children: a.mode || "inline"
417
- }
418
- )
419
- ]
420
- },
421
- a.id
422
- )) })
423
- ] }),
424
- /* @__PURE__ */ r(
425
- "div",
426
- {
427
- style: {
428
- borderTop: "1px solid #eee",
429
- marginTop: "4px"
430
- },
431
- children: /* @__PURE__ */ r(
432
- "button",
433
- {
434
- onClick: H,
435
- style: {
436
- width: "100%",
437
- padding: "6px 16px",
438
- background: "#f3f4f6",
439
- border: "none",
440
- borderRadius: "0 0 4px 4px",
441
- cursor: "pointer"
442
- },
443
- children: "Close"
444
- }
445
- )
446
- }
447
- )
448
- ] });
449
- }, Pe = (n) => {
450
- const l = n.split("-");
451
- return l.length > 2 ? l[l.length - 1].substring(0, 6) : n.substring(0, 6);
452
- }, ve = ({ field: n, onSelect: l, onDelete: m, isSelected: s, isGrouped: p = !1 }) => /* @__PURE__ */ o(
453
- "div",
454
- {
455
- onClick: () => l(n),
456
- style: {
457
- position: "relative",
458
- padding: "10px 12px",
459
- background: s ? "#eff6ff" : "#f9fafb",
460
- border: s ? "1px solid #3b82f6" : "1px solid #e5e7eb",
461
- borderRadius: "6px",
462
- cursor: "pointer",
463
- transition: "all 0.2s",
464
- fontSize: p ? "13px" : "14px"
465
- },
466
- onMouseEnter: (c) => {
467
- s || (c.currentTarget.style.background = "#f3f4f6");
468
- },
469
- onMouseLeave: (c) => {
470
- s || (c.currentTarget.style.background = "#f9fafb");
471
- },
472
- title: n.alias,
473
- children: [
474
- /* @__PURE__ */ r(
475
- "button",
476
- {
477
- onClick: (c) => {
478
- c.stopPropagation(), m(n.id);
479
- },
480
- style: {
481
- position: "absolute",
482
- top: "6px",
483
- right: "6px",
484
- padding: "4px",
485
- background: "transparent",
486
- border: "none",
487
- cursor: "pointer",
488
- color: "#9ca3af",
489
- transition: "color 0.2s",
490
- display: "flex",
491
- alignItems: "center",
492
- justifyContent: "center"
493
- },
494
- onMouseEnter: (c) => {
495
- c.currentTarget.style.color = "#ef4444";
496
- },
497
- onMouseLeave: (c) => {
498
- c.currentTarget.style.color = "#9ca3af";
499
- },
500
- title: "Delete field",
501
- children: /* @__PURE__ */ r("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ r(
502
- "path",
503
- {
504
- d: "M6 2V1.5C6 1.22386 6.22386 1 6.5 1H9.5C9.77614 1 10 1.22386 10 1.5V2M2 4H14M12.6667 4L12.1991 11.0129C12.129 12.065 12.0939 12.5911 11.8667 12.99C11.6666 13.3412 11.3648 13.6235 11.0011 13.7998C10.588 14 10.0607 14 9.00623 14H6.99377C5.93927 14 5.41202 14 4.99889 13.7998C4.63517 13.6235 4.33339 13.3412 4.13332 12.99C3.90607 12.5911 3.871 12.065 3.80086 11.0129L3.33333 4",
505
- stroke: "currentColor",
506
- strokeWidth: "1.5",
507
- strokeLinecap: "round",
508
- strokeLinejoin: "round"
509
- }
510
- ) })
511
- }
512
- ),
513
- /* @__PURE__ */ o("div", { style: { paddingRight: "24px" }, children: [
514
- /* @__PURE__ */ r(
515
- "div",
516
- {
517
- style: {
518
- fontWeight: "500",
519
- fontSize: p ? "12px" : "14px",
520
- color: p ? "#6b7280" : "#111827"
521
- },
522
- children: n.alias || n.id
523
- }
524
- ),
525
- /* @__PURE__ */ o(
526
- "div",
527
- {
528
- style: {
529
- display: "flex",
530
- alignItems: "center",
531
- gap: "6px",
532
- fontSize: "11px",
533
- color: "#9ca3af",
534
- marginTop: "2px"
535
- },
536
- children: [
537
- /* @__PURE__ */ o("span", { children: [
538
- "ID: ",
539
- n.id
540
- ] }),
541
- n.mode && /* @__PURE__ */ r(
542
- "span",
543
- {
544
- style: {
545
- fontSize: "9px",
546
- padding: "2px 5px",
547
- borderRadius: "3px",
548
- background: n.mode === "block" ? "#dbeafe" : "#f3f4f6",
549
- color: n.mode === "block" ? "#1e40af" : "#4b5563",
550
- fontWeight: "500"
551
- },
552
- children: n.mode
553
- }
554
- )
555
- ]
556
- }
557
- )
558
- ] })
559
- ]
560
- }
561
- ), Ae = ({ fields: n, onSelect: l, onDelete: m, selectedFieldId: s }) => {
562
- const [p, c] = E(/* @__PURE__ */ new Set()), { groupedFields: N, ungroupedFields: H } = pe(() => {
563
- const f = {}, T = [];
564
- return n.forEach((y) => {
565
- y.group ? (f[y.group] || (f[y.group] = []), f[y.group].push(y)) : T.push(y);
566
- }), { groupedFields: f, ungroupedFields: T };
567
- }, [n]), G = (f) => {
568
- c((T) => {
569
- const y = new Set(T);
570
- return y.has(f) ? y.delete(f) : y.add(f), y;
571
- });
572
- };
573
- return /* @__PURE__ */ o(
574
- "div",
575
- {
576
- className: "superdoc-field-list",
577
- style: {
578
- width: "250px",
579
- background: "white",
580
- border: "1px solid #e5e7eb",
581
- borderRadius: "8px",
582
- padding: "16px"
583
- },
584
- children: [
585
- /* @__PURE__ */ o("h3", { style: { margin: "0 0 16px 0", fontSize: "16px", fontWeight: "600" }, children: [
586
- "Template Fields (",
587
- n.length,
588
- ")"
589
- ] }),
590
- n.length === 0 ? /* @__PURE__ */ o(
591
- "div",
592
- {
593
- style: {
594
- color: "#9ca3af",
595
- fontSize: "14px",
596
- textAlign: "center",
597
- padding: "20px 0"
598
- },
599
- children: [
600
- "No fields yet. Type ",
601
- "{{",
602
- " to add a field."
603
- ]
604
- }
605
- ) : /* @__PURE__ */ o("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
606
- H.map((f) => /* @__PURE__ */ r(
607
- ve,
608
- {
609
- field: f,
610
- onSelect: l,
611
- onDelete: m,
612
- isSelected: s === f.id
613
- },
614
- f.id
615
- )),
616
- Object.entries(N).map(([f, T]) => {
617
- const y = p.has(f), I = T[0];
618
- return /* @__PURE__ */ o("div", { children: [
619
- /* @__PURE__ */ r(
620
- "div",
621
- {
622
- style: {
623
- position: "relative",
624
- padding: "12px",
625
- background: "#f9fafb",
626
- border: "1px solid #e5e7eb",
627
- borderRadius: "6px",
628
- cursor: "pointer",
629
- transition: "all 0.2s"
630
- },
631
- onClick: () => G(f),
632
- onMouseEnter: (u) => {
633
- u.currentTarget.style.background = "#f3f4f6";
634
- },
635
- onMouseLeave: (u) => {
636
- u.currentTarget.style.background = "#f9fafb";
637
- },
638
- children: /* @__PURE__ */ o("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
639
- /* @__PURE__ */ r("span", { style: { fontSize: "12px", color: "#6b7280" }, children: y ? "▼" : "▶" }),
640
- /* @__PURE__ */ o("div", { style: { flex: 1 }, children: [
641
- /* @__PURE__ */ r("div", { style: { fontWeight: "500", fontSize: "14px" }, children: I.alias }),
642
- /* @__PURE__ */ o(
643
- "div",
644
- {
645
- style: {
646
- fontSize: "11px",
647
- color: "#9ca3af",
648
- marginTop: "2px"
649
- },
650
- children: [
651
- "group: ",
652
- Pe(f),
653
- " (",
654
- T.length,
655
- " fields)"
656
- ]
657
- }
658
- )
659
- ] })
660
- ] })
661
- }
662
- ),
663
- y && /* @__PURE__ */ r(
664
- "div",
665
- {
666
- style: {
667
- marginLeft: "16px",
668
- marginTop: "4px",
669
- display: "flex",
670
- flexDirection: "column",
671
- gap: "4px"
672
- },
673
- children: T.map((u) => /* @__PURE__ */ r(
674
- ve,
675
- {
676
- field: u,
677
- onSelect: l,
678
- onDelete: m,
679
- isSelected: s === u.id,
680
- isGrouped: !0
681
- },
682
- u.id
683
- ))
684
- }
685
- )
686
- ] }, f);
687
- })
688
- ] })
689
- ]
690
- }
691
- );
692
- }, J = (n) => {
693
- const l = n.helpers?.structuredContentCommands;
694
- return l?.getStructuredContentTags ? (l.getStructuredContentTags(n.state) || []).map((s) => {
695
- const p = s?.node ?? s, c = p?.attrs ?? {}, H = (p?.type?.name || "").includes("Block") ? "block" : "inline";
696
- return {
697
- id: c.id,
698
- alias: c.alias || c.label || "",
699
- tag: c.tag,
700
- mode: H,
701
- group: l.getGroup?.(c.tag) ?? void 0
702
- };
703
- }) : [];
704
- }, Fe = (n, l) => {
705
- if (n === l) return !0;
706
- if (n.length !== l.length) return !1;
707
- for (let m = 0; m < n.length; m += 1) {
708
- const s = n[m], p = l[m];
709
- if (!p || s.id !== p.id || s.alias !== p.alias || s.tag !== p.tag || s.position !== p.position || s.mode !== p.mode || s.group !== p.group)
710
- return !1;
711
- }
712
- return !0;
713
- }, Ve = (n) => {
714
- if (!n) return null;
715
- if (n === !0)
716
- return {
717
- selector: "#superdoc-toolbar",
718
- config: {},
719
- renderDefaultContainer: !0
720
- };
721
- if (typeof n == "string")
722
- return {
723
- selector: n,
724
- config: {},
725
- renderDefaultContainer: !1
726
- };
727
- const { selector: l, ...m } = n;
728
- return {
729
- selector: l || "#superdoc-toolbar",
730
- config: m,
731
- renderDefaultContainer: l === void 0
732
- };
733
- }, re = 10, je = 250, Ge = 300, Ce = (n) => {
734
- const l = window.innerWidth - je - re, m = window.innerHeight - Ge - re, s = Math.min(n.left, l), p = Math.min(n.top, m);
735
- return new DOMRect(
736
- Math.max(s, re),
737
- Math.max(p, re),
738
- n.width,
739
- n.height
740
- );
741
- }, Oe = We(
742
- (n, l) => {
743
- const {
744
- document: m,
745
- fields: s = {},
746
- menu: p = {},
747
- list: c = {},
748
- toolbar: N,
749
- cspNonce: H,
750
- onReady: G,
751
- onTrigger: f,
752
- onFieldInsert: T,
753
- onFieldUpdate: y,
754
- onFieldDelete: I,
755
- onFieldsChange: u,
756
- onFieldSelect: L,
757
- onFieldCreate: P,
758
- onExport: z,
759
- className: Q,
760
- style: ie,
761
- documentHeight: X = "600px"
762
- } = n, [g, A] = E(s.initial || []), [R, O] = E(null), [_, a] = E(!1), [V, b] = E(), [Y, ee] = E(""), [we, ke] = E(() => s.available || []), se = q(null), w = q(null), M = q(null), fe = q(s);
763
- fe.current = s;
764
- const B = q(null), ge = q(_);
765
- oe(() => {
766
- ge.current = _;
767
- }, [_]);
768
- const te = p.trigger || "{{", le = fe.current.available || [], j = pe(() => Ve(N), [N]), me = S(
769
- (e) => {
770
- const t = e.trim().toLowerCase();
771
- return t ? le.filter((i) => i.label.toLowerCase().includes(t)) : le;
772
- },
773
- [le]
774
- ), de = S(
775
- (e) => {
776
- ee(e), ke(me(e));
777
- },
778
- [me]
779
- ), W = S(() => {
780
- de("");
781
- }, [de]), K = S(
782
- (e, t) => {
783
- if (!w.current?.activeEditor) return !1;
784
- const i = w.current.activeEditor, v = g, C = e === "inline" ? i.commands.insertStructuredContentInline?.({
785
- attrs: {
786
- alias: t.alias,
787
- tag: t.metadata ? JSON.stringify(t.metadata) : void 0
788
- },
789
- text: t.defaultValue || t.alias
790
- }) : i.commands.insertStructuredContentBlock?.({
791
- attrs: {
792
- alias: t.alias,
793
- tag: t.metadata ? JSON.stringify(t.metadata) : void 0
794
- },
795
- text: t.defaultValue || t.alias
796
- });
797
- if (C) {
798
- const x = J(i);
799
- A(x), u?.(x);
800
- const k = x.find(
801
- (F) => !v.some((d) => d.id === F.id)
802
- );
803
- k && T?.(k);
804
- }
805
- return C ?? !1;
806
- },
807
- [T, u, g]
808
- ), Z = S(
809
- (e, t) => {
810
- if (!w.current?.activeEditor) return !1;
811
- const v = w.current.activeEditor.commands.updateStructuredContentById?.(e, {
812
- attrs: t
813
- });
814
- return v && A((C) => {
815
- const x = C.map((F) => F.id === e ? { ...F, ...t } : F);
816
- u?.(x);
817
- const k = x.find((F) => F.id === e);
818
- return k && y?.(k), x;
819
- }), v ?? !1;
820
- },
821
- [y, u]
822
- ), ae = S(
823
- (e) => {
824
- const t = w.current?.activeEditor;
825
- if (!t) {
826
- let d = !1;
827
- return A((h) => {
828
- if (!h.some((D) => D.id === e)) return h;
829
- const U = h.filter((D) => D.id !== e);
830
- return d = !0, u?.(U), I?.(e), U;
831
- }), d && O((h) => h === e ? null : h), d;
832
- }
833
- const v = g.find((d) => d.id === e)?.group;
834
- let C = !1;
835
- try {
836
- C = t.commands.deleteStructuredContentById?.(e) ?? !1;
837
- } catch (d) {
838
- console.warn("[TemplateBuilder] Failed to delete structured content:", e, d), C = !1;
839
- }
840
- let x = J(t);
841
- const k = x.some((d) => d.id === e);
842
- if (!C && k && (x = x.filter((d) => d.id !== e)), v) {
843
- const d = x.filter((h) => h.group === v);
844
- if (d.length === 1) {
845
- const h = d[0];
846
- t.commands.updateStructuredContentById?.(h.id, {
847
- attrs: { tag: void 0 }
848
- }), x = J(t);
849
- }
850
- }
851
- let F = !1;
852
- return A((d) => {
853
- if (Fe(d, x))
854
- return d;
855
- const h = d.some((D) => D.id === e), U = x.some((D) => D.id === e);
856
- return h && !U && (F = !0), u?.(x), F && I?.(e), x;
857
- }), F && O((d) => d === e ? null : d), C || F;
858
- },
859
- [I, u, g]
860
- ), $ = S(
861
- (e) => {
862
- if (!w.current?.activeEditor) return;
863
- w.current.activeEditor.commands.selectStructuredContentById?.(e), O(e);
864
- const i = g.find((v) => v.id === e);
865
- i && L?.(i);
866
- },
867
- [g, L]
868
- ), ce = S(
869
- (e) => {
870
- if (!e) return;
871
- const t = J(e);
872
- A((i) => Fe(i, t) ? i : (u?.(t), t));
873
- },
874
- [u]
875
- );
876
- oe(() => {
877
- if (!se.current) return;
878
- let e = !1, t = null;
879
- return (async () => {
880
- const { SuperDoc: v } = await import("superdoc");
881
- if (e) return;
882
- const C = {
883
- comments: !1,
884
- ...j && {
885
- toolbar: {
886
- selector: j.selector,
887
- toolbarGroups: j.config.toolbarGroups || ["center"],
888
- excludeItems: j.config.excludeItems || [],
889
- ...j.config
890
- }
891
- }
892
- }, x = () => {
893
- if (!e) {
894
- if (t?.activeEditor) {
895
- const k = t.activeEditor;
896
- k.on("update", ({ editor: F }) => {
897
- const { state: d } = F, { from: h } = d.selection;
898
- if (h >= te.length) {
899
- const ue = h - te.length;
900
- if (d.doc.textBetween(ue, h) === te) {
901
- const he = F.view.coordsAtPos(h), be = Ce(new DOMRect(he.left, he.top, 0, 0)), ye = () => {
902
- const ne = w.current?.activeEditor;
903
- if (!ne) return;
904
- const ze = ne.state.selection.from, Be = ne.state.tr.delete(ue, ze);
905
- ne.view.dispatch(Be);
906
- };
907
- M.current = ye, B.current = h, b(be), a(!0), W(), f?.({
908
- position: { from: ue, to: h },
909
- bounds: be,
910
- cleanup: ye
911
- });
912
- return;
913
- }
914
- }
915
- if (!ge.current)
916
- return;
917
- if (B.current == null) {
918
- a(!1), W();
919
- return;
920
- }
921
- if (h < B.current) {
922
- a(!1), B.current = null, W();
923
- return;
924
- }
925
- const U = d.doc.textBetween(B.current, h);
926
- de(U);
927
- const D = F.view.coordsAtPos(h), Ne = Ce(new DOMRect(D.left, D.top, 0, 0));
928
- b(Ne);
929
- }), k.on("update", () => {
930
- ce(k);
931
- }), ce(k);
932
- }
933
- G?.();
934
- }
935
- };
936
- t = new v({
937
- selector: se.current,
938
- document: m?.source,
939
- documentMode: m?.mode || "editing",
940
- modules: C,
941
- toolbar: j?.selector,
942
- cspNonce: H,
943
- onReady: x
944
- }), w.current = t;
945
- })(), () => {
946
- e = !0, M.current = null, B.current = null, t && typeof t.destroy == "function" && t.destroy(), w.current = null;
947
- };
948
- }, [m?.source, m?.mode, te, ce, G, f, j, H]);
949
- const Se = S(
950
- async (e) => {
951
- M.current && (M.current(), M.current = null), B.current = null, W();
952
- const t = e.mode || "inline";
953
- if (e.id.startsWith("custom_") && P) {
954
- const i = await P(e);
955
- if (i) {
956
- const v = i.mode || t;
957
- K(v, {
958
- alias: i.label,
959
- metadata: i.metadata,
960
- defaultValue: i.defaultValue
961
- }), a(!1);
962
- return;
963
- }
964
- }
965
- K(t, {
966
- alias: e.label,
967
- metadata: e.metadata,
968
- defaultValue: e.defaultValue
969
- }), a(!1);
970
- },
971
- [K, P, W]
972
- ), Te = S(
973
- (e) => {
974
- M.current && (M.current(), M.current = null), B.current = null, W();
975
- const t = w.current?.activeEditor;
976
- if (!t) return;
977
- const i = t.helpers?.structuredContentCommands;
978
- if (!i) return;
979
- const v = e.group || `group-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`, C = i.createTagObject?.({
980
- group: v
981
- });
982
- if ((e.mode || "inline") === "inline" ? t.commands.insertStructuredContentInline?.({
983
- attrs: {
984
- alias: e.alias,
985
- tag: C
986
- },
987
- text: e.alias
988
- }) : t.commands.insertStructuredContentBlock?.({
989
- attrs: {
990
- alias: e.alias,
991
- tag: C
992
- },
993
- text: e.alias
994
- })) {
995
- e.group || Z(e.id, { tag: C }), a(!1);
996
- const F = J(t);
997
- A(F), u?.(F);
998
- }
999
- },
1000
- [Z, W, u]
1001
- ), Ee = S(() => {
1002
- a(!1), B.current = null, W(), M.current && (M.current(), M.current = null);
1003
- }, [W]), Ie = S(() => {
1004
- if (!w.current?.activeEditor || g.length === 0) return;
1005
- const e = g.findIndex((i) => i.id === R), t = e >= 0 ? (e + 1) % g.length : 0;
1006
- $(g[t].id);
1007
- }, [g, R, $]), Me = S(() => {
1008
- if (!w.current?.activeEditor || g.length === 0) return;
1009
- const e = g.findIndex((i) => i.id === R), t = e > 0 ? e - 1 : g.length - 1;
1010
- $(g[t].id);
1011
- }, [g, R, $]), Re = S(
1012
- async (e) => {
1013
- const { fileName: t = "document", triggerDownload: i = !0 } = e || {}, v = await w.current?.export({
1014
- exportType: ["docx"],
1015
- exportedName: t,
1016
- triggerDownload: i
1017
- }), C = w.current?.activeEditor;
1018
- if (C) {
1019
- const x = J(C);
1020
- z?.({ fields: x, blob: i ? void 0 : v, fileName: t });
1021
- }
1022
- return v;
1023
- },
1024
- [z]
1025
- );
1026
- He(l, () => ({
1027
- insertField: (e) => K("inline", e),
1028
- insertBlockField: (e) => K("block", e),
1029
- updateField: Z,
1030
- deleteField: ae,
1031
- selectField: $,
1032
- nextField: Ie,
1033
- previousField: Me,
1034
- getFields: () => g,
1035
- exportTemplate: Re,
1036
- getSuperDoc: () => w.current
1037
- }));
1038
- const De = p.component || Le, xe = c.component || Ae;
1039
- return /* @__PURE__ */ o("div", { className: `superdoc-template-builder ${Q || ""}`, style: ie, children: [
1040
- /* @__PURE__ */ o("div", { style: { display: "flex", gap: "20px" }, children: [
1041
- c.position === "left" && /* @__PURE__ */ r("div", { className: "superdoc-template-builder-sidebar", children: /* @__PURE__ */ r(
1042
- xe,
1043
- {
1044
- fields: g,
1045
- onSelect: (e) => $(e.id),
1046
- onDelete: ae,
1047
- onUpdate: (e) => Z(e.id, e),
1048
- selectedFieldId: R || void 0
1049
- }
1050
- ) }),
1051
- /* @__PURE__ */ o("div", { className: "superdoc-template-builder-document", style: { flex: 1 }, children: [
1052
- j?.renderDefaultContainer && /* @__PURE__ */ r(
1053
- "div",
1054
- {
1055
- id: "superdoc-toolbar",
1056
- className: "superdoc-template-builder-toolbar",
1057
- "data-testid": "template-builder-toolbar"
1058
- }
1059
- ),
1060
- /* @__PURE__ */ r(
1061
- "div",
1062
- {
1063
- ref: se,
1064
- className: "superdoc-template-builder-editor",
1065
- style: { height: X },
1066
- "data-testid": "template-builder-editor"
1067
- }
1068
- )
1069
- ] }),
1070
- c.position === "right" && /* @__PURE__ */ r("div", { className: "superdoc-template-builder-sidebar", children: /* @__PURE__ */ r(
1071
- xe,
1072
- {
1073
- fields: g,
1074
- onSelect: (e) => $(e.id),
1075
- onDelete: ae,
1076
- onUpdate: (e) => Z(e.id, e),
1077
- selectedFieldId: R || void 0
1078
- }
1079
- ) })
1080
- ] }),
1081
- /* @__PURE__ */ r(
1082
- De,
1083
- {
1084
- isVisible: _,
1085
- position: V,
1086
- availableFields: s.available || [],
1087
- filteredFields: we,
1088
- filterQuery: Y,
1089
- allowCreate: s.allowCreate || !1,
1090
- onSelect: Se,
1091
- onClose: Ee,
1092
- onCreateField: P,
1093
- existingFields: g,
1094
- onSelectExisting: Te
1095
- }
1096
- )
1097
- ] });
1098
- }
1099
- );
1100
- Oe.displayName = "SuperDocTemplateBuilder";
1101
- export {
1102
- Ae as FieldList,
1103
- Le as FieldMenu,
1104
- Oe as default
1
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFields: a, filterQuery: s, allowCreate: c, onSelect: l, onClose: u, onCreateField: d, existingFields: f = [], onSelectExisting: ne }) => {
4
+ let [p, m] = useState(!1), [h, g] = useState(""), [_, v] = useState("inline"), [y, b] = useState(!0), [x, S] = useState(!0);
5
+ useEffect(() => {
6
+ e || (m(!1), g(""), v("inline"));
7
+ }, [e]);
8
+ let C = useMemo(() => ({
9
+ position: "absolute",
10
+ left: t?.left,
11
+ top: t?.top,
12
+ zIndex: 1e3,
13
+ background: "white",
14
+ border: "1px solid #ddd",
15
+ borderRadius: "4px",
16
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
17
+ padding: "8px 0",
18
+ width: "280px"
19
+ }), [t]), w = a ?? r, T = !!s;
20
+ if (useEffect(() => {
21
+ T && S(!0);
22
+ }, [T]), !e) return null;
23
+ let E = async () => {
24
+ let e = h.trim();
25
+ if (!e) return;
26
+ let t = {
27
+ id: `custom_${Date.now()}`,
28
+ label: e,
29
+ mode: _
30
+ };
31
+ try {
32
+ l(d && await d(t) || t);
33
+ } finally {
34
+ m(!1), g(""), v("inline");
35
+ }
36
+ };
37
+ return /* @__PURE__ */ jsxs("div", {
38
+ className: "superdoc-field-menu",
39
+ style: C,
40
+ children: [
41
+ T && /* @__PURE__ */ jsx("div", {
42
+ style: {
43
+ padding: "8px 16px",
44
+ borderBottom: "1px solid #f0f0f0",
45
+ marginBottom: "4px"
46
+ },
47
+ children: /* @__PURE__ */ jsxs("div", {
48
+ style: {
49
+ fontSize: "12px",
50
+ color: "#6b7280"
51
+ },
52
+ children: ["Filtering results for", /* @__PURE__ */ jsx("span", {
53
+ style: {
54
+ fontWeight: 600,
55
+ color: "#111827",
56
+ marginLeft: "4px"
57
+ },
58
+ children: s
59
+ })]
60
+ })
61
+ }),
62
+ c && !p && /* @__PURE__ */ jsx("div", {
63
+ className: "field-menu-item",
64
+ onClick: () => m(!0),
65
+ style: {
66
+ padding: "8px 16px",
67
+ cursor: "pointer",
68
+ color: "#0066cc",
69
+ fontWeight: 500
70
+ },
71
+ children: "+ Create New Field"
72
+ }),
73
+ c && p && /* @__PURE__ */ jsxs("div", {
74
+ style: { padding: "8px 16px" },
75
+ children: [
76
+ /* @__PURE__ */ jsx("input", {
77
+ type: "text",
78
+ value: h,
79
+ placeholder: "Field name...",
80
+ onChange: (e) => g(e.target.value),
81
+ onKeyDown: (e) => {
82
+ e.key === "Enter" && E(), e.key === "Escape" && (m(!1), g(""), v("inline"));
83
+ },
84
+ autoFocus: !0,
85
+ style: {
86
+ width: "100%",
87
+ padding: "4px 8px",
88
+ border: "1px solid #ddd",
89
+ borderRadius: "3px"
90
+ }
91
+ }),
92
+ /* @__PURE__ */ jsxs("div", {
93
+ style: {
94
+ marginTop: "8px",
95
+ display: "flex",
96
+ gap: "12px",
97
+ fontSize: "13px"
98
+ },
99
+ children: [/* @__PURE__ */ jsxs("label", {
100
+ style: {
101
+ display: "flex",
102
+ alignItems: "center",
103
+ gap: "4px",
104
+ cursor: "pointer"
105
+ },
106
+ children: [/* @__PURE__ */ jsx("input", {
107
+ type: "radio",
108
+ value: "inline",
109
+ checked: _ === "inline",
110
+ onChange: () => v("inline")
111
+ }), "Inline"]
112
+ }), /* @__PURE__ */ jsxs("label", {
113
+ style: {
114
+ display: "flex",
115
+ alignItems: "center",
116
+ gap: "4px",
117
+ cursor: "pointer"
118
+ },
119
+ children: [/* @__PURE__ */ jsx("input", {
120
+ type: "radio",
121
+ value: "block",
122
+ checked: _ === "block",
123
+ onChange: () => v("block")
124
+ }), "Block"]
125
+ })]
126
+ }),
127
+ /* @__PURE__ */ jsxs("div", {
128
+ style: {
129
+ marginTop: "8px",
130
+ display: "flex",
131
+ gap: "8px"
132
+ },
133
+ children: [/* @__PURE__ */ jsx("button", {
134
+ onClick: E,
135
+ disabled: !h.trim(),
136
+ style: {
137
+ padding: "4px 12px",
138
+ background: h.trim() ? "#0066cc" : "#ccc",
139
+ color: "white",
140
+ border: "none",
141
+ borderRadius: "3px",
142
+ cursor: h.trim() ? "pointer" : "not-allowed"
143
+ },
144
+ children: "Create"
145
+ }), /* @__PURE__ */ jsx("button", {
146
+ onClick: () => {
147
+ m(!1), g(""), v("inline");
148
+ },
149
+ style: {
150
+ padding: "4px 12px",
151
+ background: "white",
152
+ border: "1px solid #ddd",
153
+ borderRadius: "3px",
154
+ cursor: "pointer"
155
+ },
156
+ children: "Cancel"
157
+ })]
158
+ })
159
+ ]
160
+ }),
161
+ c && r.length > 0 && /* @__PURE__ */ jsx("div", { style: {
162
+ borderTop: "1px solid #eee",
163
+ margin: "4px 0"
164
+ } }),
165
+ f.length > 0 && (() => {
166
+ let e = /* @__PURE__ */ new Map();
167
+ f.forEach((t) => {
168
+ let n = t.group || `individual-${t.id}`, r = e.get(n) || [];
169
+ r.push(t), e.set(n, r);
170
+ });
171
+ let t = Array.from(e.values()).map((e) => ({
172
+ ...e[0],
173
+ count: e.length
174
+ }));
175
+ return /* @__PURE__ */ jsxs("div", {
176
+ style: { borderBottom: "1px solid #f0f0f0" },
177
+ children: [/* @__PURE__ */ jsxs("button", {
178
+ type: "button",
179
+ onClick: () => b(!y),
180
+ style: {
181
+ width: "100%",
182
+ display: "flex",
183
+ alignItems: "center",
184
+ justifyContent: "space-between",
185
+ padding: "8px 16px",
186
+ background: "transparent",
187
+ border: "none",
188
+ cursor: "pointer",
189
+ fontWeight: 500,
190
+ fontSize: "13px",
191
+ color: "#374151",
192
+ textAlign: "left"
193
+ },
194
+ children: [/* @__PURE__ */ jsxs("span", { children: [
195
+ "Existing Fields (",
196
+ t.length,
197
+ ")"
198
+ ] }), /* @__PURE__ */ jsx("span", {
199
+ "aria-hidden": !0,
200
+ style: {
201
+ display: "inline-block",
202
+ width: "8px",
203
+ height: "8px",
204
+ borderRight: "2px solid #666",
205
+ borderBottom: "2px solid #666",
206
+ transform: y ? "rotate(45deg)" : "rotate(-45deg)",
207
+ transition: "transform 0.2s ease"
208
+ }
209
+ })]
210
+ }), y && /* @__PURE__ */ jsx("div", {
211
+ style: {
212
+ maxHeight: "300px",
213
+ overflowY: "auto"
214
+ },
215
+ children: t.map((e) => /* @__PURE__ */ jsxs("div", {
216
+ className: "field-menu-item",
217
+ onClick: () => ne?.(e),
218
+ style: {
219
+ padding: "8px 16px",
220
+ cursor: "pointer",
221
+ display: "flex",
222
+ alignItems: "flex-start",
223
+ justifyContent: "space-between",
224
+ gap: "8px"
225
+ },
226
+ children: [/* @__PURE__ */ jsxs("div", {
227
+ style: {
228
+ flex: 1,
229
+ minWidth: 0
230
+ },
231
+ children: [/* @__PURE__ */ jsx("div", {
232
+ style: {
233
+ fontWeight: 500,
234
+ fontSize: "13px"
235
+ },
236
+ children: e.alias || e.id
237
+ }), /* @__PURE__ */ jsx("div", {
238
+ style: {
239
+ fontSize: "11px",
240
+ color: "#9ca3af",
241
+ marginTop: "2px"
242
+ },
243
+ children: e.group ? `group (${e.count} fields)` : `ID: ${e.id}`
244
+ })]
245
+ }), /* @__PURE__ */ jsx("span", {
246
+ style: {
247
+ fontSize: "11px",
248
+ color: "#6b7280",
249
+ padding: "2px 6px",
250
+ background: "#f3f4f6",
251
+ borderRadius: "3px",
252
+ textTransform: "capitalize",
253
+ flexShrink: 0
254
+ },
255
+ children: e.mode || "inline"
256
+ })]
257
+ }, e.group || e.id))
258
+ })]
259
+ });
260
+ })(),
261
+ w.length === 0 ? /* @__PURE__ */ jsx("div", {
262
+ style: {
263
+ padding: "16px",
264
+ fontSize: "13px",
265
+ color: "#6b7280",
266
+ textAlign: "center"
267
+ },
268
+ children: "No matching fields"
269
+ }) : /* @__PURE__ */ jsxs("div", {
270
+ style: { borderBottom: "1px solid #f0f0f0" },
271
+ children: [/* @__PURE__ */ jsxs("button", {
272
+ type: "button",
273
+ onClick: () => S(!x),
274
+ style: {
275
+ width: "100%",
276
+ display: "flex",
277
+ alignItems: "center",
278
+ justifyContent: "space-between",
279
+ padding: "8px 16px",
280
+ background: "transparent",
281
+ border: "none",
282
+ cursor: "pointer",
283
+ fontWeight: 500,
284
+ fontSize: "13px",
285
+ color: "#374151",
286
+ textAlign: "left"
287
+ },
288
+ children: [/* @__PURE__ */ jsxs("span", { children: [
289
+ "Available Fields (",
290
+ w.length,
291
+ ")"
292
+ ] }), /* @__PURE__ */ jsx("span", {
293
+ "aria-hidden": !0,
294
+ style: {
295
+ display: "inline-block",
296
+ width: "8px",
297
+ height: "8px",
298
+ borderRight: "2px solid #666",
299
+ borderBottom: "2px solid #666",
300
+ transform: x ? "rotate(45deg)" : "rotate(-45deg)",
301
+ transition: "transform 0.2s ease"
302
+ }
303
+ })]
304
+ }), x && /* @__PURE__ */ jsx("div", {
305
+ style: {
306
+ maxHeight: "300px",
307
+ overflowY: "auto"
308
+ },
309
+ children: w.map((e) => /* @__PURE__ */ jsxs("div", {
310
+ className: "field-menu-item",
311
+ onClick: () => l(e),
312
+ style: {
313
+ padding: "8px 16px",
314
+ cursor: "pointer",
315
+ display: "flex",
316
+ alignItems: "flex-start",
317
+ justifyContent: "space-between",
318
+ gap: "8px"
319
+ },
320
+ children: [/* @__PURE__ */ jsxs("div", {
321
+ style: {
322
+ flex: 1,
323
+ minWidth: 0
324
+ },
325
+ children: [/* @__PURE__ */ jsx("div", {
326
+ style: {
327
+ fontWeight: 500,
328
+ fontSize: "13px"
329
+ },
330
+ children: e.label || e.id
331
+ }), /* @__PURE__ */ jsxs("div", {
332
+ style: {
333
+ fontSize: "11px",
334
+ color: "#9ca3af",
335
+ marginTop: "2px"
336
+ },
337
+ children: ["ID: ", e.id]
338
+ })]
339
+ }), /* @__PURE__ */ jsx("span", {
340
+ style: {
341
+ fontSize: "11px",
342
+ color: "#6b7280",
343
+ padding: "2px 6px",
344
+ background: "#f3f4f6",
345
+ borderRadius: "3px",
346
+ textTransform: "capitalize",
347
+ flexShrink: 0
348
+ },
349
+ children: e.mode || "inline"
350
+ })]
351
+ }, e.id))
352
+ })]
353
+ }),
354
+ /* @__PURE__ */ jsx("div", {
355
+ style: {
356
+ borderTop: "1px solid #eee",
357
+ marginTop: "4px"
358
+ },
359
+ children: /* @__PURE__ */ jsx("button", {
360
+ onClick: u,
361
+ style: {
362
+ width: "100%",
363
+ padding: "6px 16px",
364
+ background: "#f3f4f6",
365
+ border: "none",
366
+ borderRadius: "0 0 4px 4px",
367
+ cursor: "pointer"
368
+ },
369
+ children: "Close"
370
+ })
371
+ })
372
+ ]
373
+ });
1105
374
  };
375
+ var shortenGroupId = (e) => {
376
+ let t = e.split("-");
377
+ return t.length > 2 ? t[t.length - 1].substring(0, 6) : e.substring(0, 6);
378
+ }, FieldItem = ({ field: e, onSelect: t, onDelete: n, isSelected: r, isGrouped: i = !1 }) => /* @__PURE__ */ jsxs("div", {
379
+ onClick: () => t(e),
380
+ style: {
381
+ position: "relative",
382
+ padding: "10px 12px",
383
+ background: r ? "#eff6ff" : "#f9fafb",
384
+ border: r ? "1px solid #3b82f6" : "1px solid #e5e7eb",
385
+ borderRadius: "6px",
386
+ cursor: "pointer",
387
+ transition: "all 0.2s",
388
+ fontSize: i ? "13px" : "14px"
389
+ },
390
+ onMouseEnter: (e) => {
391
+ r || (e.currentTarget.style.background = "#f3f4f6");
392
+ },
393
+ onMouseLeave: (e) => {
394
+ r || (e.currentTarget.style.background = "#f9fafb");
395
+ },
396
+ title: e.alias,
397
+ children: [/* @__PURE__ */ jsx("button", {
398
+ onClick: (t) => {
399
+ t.stopPropagation(), n(e.id);
400
+ },
401
+ style: {
402
+ position: "absolute",
403
+ top: "6px",
404
+ right: "6px",
405
+ padding: "4px",
406
+ background: "transparent",
407
+ border: "none",
408
+ cursor: "pointer",
409
+ color: "#9ca3af",
410
+ transition: "color 0.2s",
411
+ display: "flex",
412
+ alignItems: "center",
413
+ justifyContent: "center"
414
+ },
415
+ onMouseEnter: (e) => {
416
+ e.currentTarget.style.color = "#ef4444";
417
+ },
418
+ onMouseLeave: (e) => {
419
+ e.currentTarget.style.color = "#9ca3af";
420
+ },
421
+ title: "Delete field",
422
+ children: /* @__PURE__ */ jsx("svg", {
423
+ width: "14",
424
+ height: "14",
425
+ viewBox: "0 0 16 16",
426
+ fill: "none",
427
+ xmlns: "http://www.w3.org/2000/svg",
428
+ children: /* @__PURE__ */ jsx("path", {
429
+ d: "M6 2V1.5C6 1.22386 6.22386 1 6.5 1H9.5C9.77614 1 10 1.22386 10 1.5V2M2 4H14M12.6667 4L12.1991 11.0129C12.129 12.065 12.0939 12.5911 11.8667 12.99C11.6666 13.3412 11.3648 13.6235 11.0011 13.7998C10.588 14 10.0607 14 9.00623 14H6.99377C5.93927 14 5.41202 14 4.99889 13.7998C4.63517 13.6235 4.33339 13.3412 4.13332 12.99C3.90607 12.5911 3.871 12.065 3.80086 11.0129L3.33333 4",
430
+ stroke: "currentColor",
431
+ strokeWidth: "1.5",
432
+ strokeLinecap: "round",
433
+ strokeLinejoin: "round"
434
+ })
435
+ })
436
+ }), /* @__PURE__ */ jsxs("div", {
437
+ style: { paddingRight: "24px" },
438
+ children: [/* @__PURE__ */ jsx("div", {
439
+ style: {
440
+ fontWeight: "500",
441
+ fontSize: i ? "12px" : "14px",
442
+ color: i ? "#6b7280" : "#111827"
443
+ },
444
+ children: e.alias || e.id
445
+ }), /* @__PURE__ */ jsxs("div", {
446
+ style: {
447
+ display: "flex",
448
+ alignItems: "center",
449
+ gap: "6px",
450
+ fontSize: "11px",
451
+ color: "#9ca3af",
452
+ marginTop: "2px"
453
+ },
454
+ children: [/* @__PURE__ */ jsxs("span", { children: ["ID: ", e.id] }), e.mode && /* @__PURE__ */ jsx("span", {
455
+ style: {
456
+ fontSize: "9px",
457
+ padding: "2px 5px",
458
+ borderRadius: "3px",
459
+ background: e.mode === "block" ? "#dbeafe" : "#f3f4f6",
460
+ color: e.mode === "block" ? "#1e40af" : "#4b5563",
461
+ fontWeight: "500"
462
+ },
463
+ children: e.mode
464
+ })]
465
+ })]
466
+ })]
467
+ });
468
+ const FieldList = ({ fields: e, onSelect: t, onDelete: n, selectedFieldId: r }) => {
469
+ let [a, s] = useState(/* @__PURE__ */ new Set()), { groupedFields: u, ungroupedFields: d } = useMemo(() => {
470
+ let t = {}, n = [];
471
+ return e.forEach((e) => {
472
+ e.group ? (t[e.group] || (t[e.group] = []), t[e.group].push(e)) : n.push(e);
473
+ }), {
474
+ groupedFields: t,
475
+ ungroupedFields: n
476
+ };
477
+ }, [e]), f = (e) => {
478
+ s((t) => {
479
+ let n = new Set(t);
480
+ return n.has(e) ? n.delete(e) : n.add(e), n;
481
+ });
482
+ };
483
+ return /* @__PURE__ */ jsxs("div", {
484
+ className: "superdoc-field-list",
485
+ style: {
486
+ width: "250px",
487
+ background: "white",
488
+ border: "1px solid #e5e7eb",
489
+ borderRadius: "8px",
490
+ padding: "16px"
491
+ },
492
+ children: [/* @__PURE__ */ jsxs("h3", {
493
+ style: {
494
+ margin: "0 0 16px 0",
495
+ fontSize: "16px",
496
+ fontWeight: "600"
497
+ },
498
+ children: [
499
+ "Template Fields (",
500
+ e.length,
501
+ ")"
502
+ ]
503
+ }), e.length === 0 ? /* @__PURE__ */ jsxs("div", {
504
+ style: {
505
+ color: "#9ca3af",
506
+ fontSize: "14px",
507
+ textAlign: "center",
508
+ padding: "20px 0"
509
+ },
510
+ children: [
511
+ "No fields yet. Type ",
512
+ "{{",
513
+ " to add a field."
514
+ ]
515
+ }) : /* @__PURE__ */ jsxs("div", {
516
+ style: {
517
+ display: "flex",
518
+ flexDirection: "column",
519
+ gap: "8px"
520
+ },
521
+ children: [d.map((e) => /* @__PURE__ */ jsx(FieldItem, {
522
+ field: e,
523
+ onSelect: t,
524
+ onDelete: n,
525
+ isSelected: r === e.id
526
+ }, e.id)), Object.entries(u).map(([e, i]) => {
527
+ let o = a.has(e), s = i[0];
528
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
529
+ style: {
530
+ position: "relative",
531
+ padding: "12px",
532
+ background: "#f9fafb",
533
+ border: "1px solid #e5e7eb",
534
+ borderRadius: "6px",
535
+ cursor: "pointer",
536
+ transition: "all 0.2s"
537
+ },
538
+ onClick: () => f(e),
539
+ onMouseEnter: (e) => {
540
+ e.currentTarget.style.background = "#f3f4f6";
541
+ },
542
+ onMouseLeave: (e) => {
543
+ e.currentTarget.style.background = "#f9fafb";
544
+ },
545
+ children: /* @__PURE__ */ jsxs("div", {
546
+ style: {
547
+ display: "flex",
548
+ alignItems: "center",
549
+ gap: "8px"
550
+ },
551
+ children: [/* @__PURE__ */ jsx("span", {
552
+ style: {
553
+ fontSize: "12px",
554
+ color: "#6b7280"
555
+ },
556
+ children: o ? "▼" : "▶"
557
+ }), /* @__PURE__ */ jsxs("div", {
558
+ style: { flex: 1 },
559
+ children: [/* @__PURE__ */ jsx("div", {
560
+ style: {
561
+ fontWeight: "500",
562
+ fontSize: "14px"
563
+ },
564
+ children: s.alias
565
+ }), /* @__PURE__ */ jsxs("div", {
566
+ style: {
567
+ fontSize: "11px",
568
+ color: "#9ca3af",
569
+ marginTop: "2px"
570
+ },
571
+ children: [
572
+ "group: ",
573
+ shortenGroupId(e),
574
+ " (",
575
+ i.length,
576
+ " fields)"
577
+ ]
578
+ })]
579
+ })]
580
+ })
581
+ }), o && /* @__PURE__ */ jsx("div", {
582
+ style: {
583
+ marginLeft: "16px",
584
+ marginTop: "4px",
585
+ display: "flex",
586
+ flexDirection: "column",
587
+ gap: "4px"
588
+ },
589
+ children: i.map((e) => /* @__PURE__ */ jsx(FieldItem, {
590
+ field: e,
591
+ onSelect: t,
592
+ onDelete: n,
593
+ isSelected: r === e.id,
594
+ isGrouped: !0
595
+ }, e.id))
596
+ })] }, e);
597
+ })]
598
+ })]
599
+ });
600
+ };
601
+ var getTemplateFieldsFromEditor = (e) => {
602
+ let t = e.helpers?.structuredContentCommands;
603
+ return t?.getStructuredContentTags ? (t.getStructuredContentTags(e.state) || []).map((e) => {
604
+ let n = e?.node ?? e, r = n?.attrs ?? {}, i = (n?.type?.name || "").includes("Block") ? "block" : "inline";
605
+ return {
606
+ id: r.id,
607
+ alias: r.alias || r.label || "",
608
+ tag: r.tag,
609
+ mode: i,
610
+ group: t.getGroup?.(r.tag) ?? void 0
611
+ };
612
+ }) : [];
613
+ }, areTemplateFieldsEqual = (e, t) => {
614
+ if (e === t) return !0;
615
+ if (e.length !== t.length) return !1;
616
+ for (let n = 0; n < e.length; n += 1) {
617
+ let r = e[n], i = t[n];
618
+ if (!i || r.id !== i.id || r.alias !== i.alias || r.tag !== i.tag || r.position !== i.position || r.mode !== i.mode || r.group !== i.group) return !1;
619
+ }
620
+ return !0;
621
+ }, resolveToolbar = (e) => {
622
+ if (!e) return null;
623
+ if (e === !0) return {
624
+ selector: "#superdoc-toolbar",
625
+ config: {},
626
+ renderDefaultContainer: !0
627
+ };
628
+ if (typeof e == "string") return {
629
+ selector: e,
630
+ config: {},
631
+ renderDefaultContainer: !1
632
+ };
633
+ let { selector: t, ...n } = e;
634
+ return {
635
+ selector: t || "#superdoc-toolbar",
636
+ config: n,
637
+ renderDefaultContainer: t === void 0
638
+ };
639
+ }, MENU_VIEWPORT_PADDING = 10, MENU_APPROX_WIDTH = 250, MENU_APPROX_HEIGHT = 300, clampToViewport = (e) => {
640
+ let t = window.innerWidth - MENU_APPROX_WIDTH - MENU_VIEWPORT_PADDING, n = window.innerHeight - MENU_APPROX_HEIGHT - MENU_VIEWPORT_PADDING, r = Math.min(e.left, t), i = Math.min(e.top, n);
641
+ return new DOMRect(Math.max(r, MENU_VIEWPORT_PADDING), Math.max(i, MENU_VIEWPORT_PADDING), e.width, e.height);
642
+ }, SuperDocTemplateBuilder = forwardRef((e, c) => {
643
+ let { document: l, fields: p = {}, menu: m = {}, list: h = {}, toolbar: _, cspNonce: v, telemetry: y, licenseKey: b, onReady: x, onTrigger: S, onFieldInsert: C, onFieldUpdate: w, onFieldDelete: T, onFieldsChange: E, onFieldSelect: re, onFieldCreate: D, onExport: O, className: ie, style: ae, documentHeight: oe = "600px" } = e, [k, A] = useState(p.initial || []), [j, M] = useState(null), [N, P] = useState(!1), [se, F] = useState(), [ce, le] = useState(""), [ue, de] = useState(() => p.available || []), I = useRef(null), L = useRef(null), R = useRef(null), z = useRef(p);
644
+ z.current = p;
645
+ let B = useRef(null), V = useRef(N);
646
+ useEffect(() => {
647
+ V.current = N;
648
+ }, [N]);
649
+ let H = m.trigger || "{{", U = z.current.available || [], W = useMemo(() => resolveToolbar(_), [_]), G = useMemo(() => ({
650
+ enabled: y?.enabled ?? !0,
651
+ metadata: {
652
+ source: "template-builder",
653
+ ...y?.metadata
654
+ }
655
+ }), [y?.enabled, JSON.stringify(y?.metadata)]), K = useCallback((e) => {
656
+ let t = e.trim().toLowerCase();
657
+ return t ? U.filter((e) => e.label.toLowerCase().includes(t)) : U;
658
+ }, [U]), q = useCallback((e) => {
659
+ le(e), de(K(e));
660
+ }, [K]), J = useCallback(() => {
661
+ q("");
662
+ }, [q]), Y = useCallback((e, t) => {
663
+ if (!L.current?.activeEditor) return !1;
664
+ let n = L.current.activeEditor, r = k, i = e === "inline" ? n.commands.insertStructuredContentInline?.({
665
+ attrs: {
666
+ alias: t.alias,
667
+ tag: t.metadata ? JSON.stringify(t.metadata) : void 0
668
+ },
669
+ text: t.defaultValue || t.alias
670
+ }) : n.commands.insertStructuredContentBlock?.({
671
+ attrs: {
672
+ alias: t.alias,
673
+ tag: t.metadata ? JSON.stringify(t.metadata) : void 0
674
+ },
675
+ text: t.defaultValue || t.alias
676
+ });
677
+ if (i) {
678
+ let e = getTemplateFieldsFromEditor(n);
679
+ A(e), E?.(e);
680
+ let t = e.find((e) => !r.some((t) => t.id === e.id));
681
+ t && C?.(t);
682
+ }
683
+ return i ?? !1;
684
+ }, [
685
+ C,
686
+ E,
687
+ k
688
+ ]), X = useCallback((e, t) => {
689
+ if (!L.current?.activeEditor) return !1;
690
+ let n = L.current.activeEditor.commands.updateStructuredContentById?.(e, { attrs: t });
691
+ return n && A((n) => {
692
+ let r = n.map((n) => n.id === e ? {
693
+ ...n,
694
+ ...t
695
+ } : n);
696
+ E?.(r);
697
+ let i = r.find((t) => t.id === e);
698
+ return i && w?.(i), r;
699
+ }), n ?? !1;
700
+ }, [w, E]), Z = useCallback((e) => {
701
+ let t = L.current?.activeEditor;
702
+ if (!t) {
703
+ let t = !1;
704
+ return A((n) => {
705
+ if (!n.some((t) => t.id === e)) return n;
706
+ let r = n.filter((t) => t.id !== e);
707
+ return t = !0, E?.(r), T?.(e), r;
708
+ }), t && M((t) => t === e ? null : t), t;
709
+ }
710
+ let n = k.find((t) => t.id === e)?.group, r = !1;
711
+ try {
712
+ r = t.commands.deleteStructuredContentById?.(e) ?? !1;
713
+ } catch (t) {
714
+ console.warn("[TemplateBuilder] Failed to delete structured content:", e, t), r = !1;
715
+ }
716
+ let i = getTemplateFieldsFromEditor(t), a = i.some((t) => t.id === e);
717
+ if (!r && a && (i = i.filter((t) => t.id !== e)), n) {
718
+ let e = i.filter((e) => e.group === n);
719
+ if (e.length === 1) {
720
+ let n = e[0];
721
+ t.commands.updateStructuredContentById?.(n.id, { attrs: { tag: void 0 } }), i = getTemplateFieldsFromEditor(t);
722
+ }
723
+ }
724
+ let o = !1;
725
+ return A((t) => {
726
+ if (areTemplateFieldsEqual(t, i)) return t;
727
+ let n = t.some((t) => t.id === e), r = i.some((t) => t.id === e);
728
+ return n && !r && (o = !0), E?.(i), o && T?.(e), i;
729
+ }), o && M((t) => t === e ? null : t), r || o;
730
+ }, [
731
+ T,
732
+ E,
733
+ k
734
+ ]), Q = useCallback((e) => {
735
+ if (!L.current?.activeEditor) return;
736
+ L.current.activeEditor.commands.selectStructuredContentById?.(e), M(e);
737
+ let t = k.find((t) => t.id === e);
738
+ t && re?.(t);
739
+ }, [k, re]), $ = useCallback((e) => {
740
+ if (!e) return;
741
+ let t = getTemplateFieldsFromEditor(e);
742
+ A((e) => areTemplateFieldsEqual(e, t) ? e : (E?.(t), t));
743
+ }, [E]);
744
+ useEffect(() => {
745
+ if (!I.current) return;
746
+ let e = !1, t = null;
747
+ return (async () => {
748
+ let { SuperDoc: n } = await import("superdoc");
749
+ if (e) return;
750
+ let r = {
751
+ comments: !1,
752
+ ...W && { toolbar: {
753
+ selector: W.selector,
754
+ toolbarGroups: W.config.toolbarGroups || ["center"],
755
+ excludeItems: W.config.excludeItems || [],
756
+ ...W.config
757
+ } }
758
+ }, i = () => {
759
+ if (!e) {
760
+ if (t?.activeEditor) {
761
+ let e = t.activeEditor;
762
+ e.on("update", ({ editor: e }) => {
763
+ let { state: t } = e, { from: n } = t.selection;
764
+ if (n >= H.length) {
765
+ let r = n - H.length;
766
+ if (t.doc.textBetween(r, n) === H) {
767
+ let t = e.view.coordsAtPos(n), i = clampToViewport(new DOMRect(t.left, t.top, 0, 0)), a = () => {
768
+ let e = L.current?.activeEditor;
769
+ if (!e) return;
770
+ let t = e.state.selection.from, n = e.state.tr.delete(r, t);
771
+ e.view.dispatch(n);
772
+ };
773
+ R.current = a, B.current = n, F(i), P(!0), J(), S?.({
774
+ position: {
775
+ from: r,
776
+ to: n
777
+ },
778
+ bounds: i,
779
+ cleanup: a
780
+ });
781
+ return;
782
+ }
783
+ }
784
+ if (!V.current) return;
785
+ if (B.current == null) {
786
+ P(!1), J();
787
+ return;
788
+ }
789
+ if (n < B.current) {
790
+ P(!1), B.current = null, J();
791
+ return;
792
+ }
793
+ q(t.doc.textBetween(B.current, n));
794
+ let r = e.view.coordsAtPos(n);
795
+ F(clampToViewport(new DOMRect(r.left, r.top, 0, 0)));
796
+ }), e.on("update", () => {
797
+ $(e);
798
+ }), $(e);
799
+ }
800
+ x?.();
801
+ }
802
+ };
803
+ t = new n({
804
+ selector: I.current,
805
+ document: l?.source,
806
+ documentMode: l?.mode || "editing",
807
+ modules: r,
808
+ toolbar: W?.selector,
809
+ cspNonce: v,
810
+ telemetry: G,
811
+ ...b && { licenseKey: b },
812
+ onReady: i
813
+ }), L.current = t;
814
+ })(), () => {
815
+ e = !0, R.current = null, B.current = null, t && typeof t.destroy == "function" && t.destroy(), L.current = null;
816
+ };
817
+ }, [
818
+ l?.source,
819
+ l?.mode,
820
+ H,
821
+ $,
822
+ x,
823
+ S,
824
+ W,
825
+ v,
826
+ G,
827
+ b
828
+ ]);
829
+ let fe = useCallback(async (e) => {
830
+ R.current &&= (R.current(), null), B.current = null, J();
831
+ let t = e.mode || "inline";
832
+ if (e.id.startsWith("custom_") && D) {
833
+ let n = await D(e);
834
+ if (n) {
835
+ Y(n.mode || t, {
836
+ alias: n.label,
837
+ metadata: n.metadata,
838
+ defaultValue: n.defaultValue
839
+ }), P(!1);
840
+ return;
841
+ }
842
+ }
843
+ Y(t, {
844
+ alias: e.label,
845
+ metadata: e.metadata,
846
+ defaultValue: e.defaultValue
847
+ }), P(!1);
848
+ }, [
849
+ Y,
850
+ D,
851
+ J
852
+ ]), pe = useCallback((e) => {
853
+ R.current &&= (R.current(), null), B.current = null, J();
854
+ let t = L.current?.activeEditor;
855
+ if (!t) return;
856
+ let n = t.helpers?.structuredContentCommands;
857
+ if (!n) return;
858
+ let r = e.group || `group-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`, i = n.createTagObject?.({ group: r });
859
+ if ((e.mode || "inline") === "inline" ? t.commands.insertStructuredContentInline?.({
860
+ attrs: {
861
+ alias: e.alias,
862
+ tag: i
863
+ },
864
+ text: e.alias
865
+ }) : t.commands.insertStructuredContentBlock?.({
866
+ attrs: {
867
+ alias: e.alias,
868
+ tag: i
869
+ },
870
+ text: e.alias
871
+ })) {
872
+ e.group || X(e.id, { tag: i }), P(!1);
873
+ let n = getTemplateFieldsFromEditor(t);
874
+ A(n), E?.(n);
875
+ }
876
+ }, [
877
+ X,
878
+ J,
879
+ E
880
+ ]), me = useCallback(() => {
881
+ P(!1), B.current = null, J(), R.current &&= (R.current(), null);
882
+ }, [J]), he = useCallback(() => {
883
+ if (!L.current?.activeEditor || k.length === 0) return;
884
+ let e = k.findIndex((e) => e.id === j);
885
+ Q(k[e >= 0 ? (e + 1) % k.length : 0].id);
886
+ }, [
887
+ k,
888
+ j,
889
+ Q
890
+ ]), ge = useCallback(() => {
891
+ if (!L.current?.activeEditor || k.length === 0) return;
892
+ let e = k.findIndex((e) => e.id === j);
893
+ Q(k[e > 0 ? e - 1 : k.length - 1].id);
894
+ }, [
895
+ k,
896
+ j,
897
+ Q
898
+ ]), _e = useCallback(async (e) => {
899
+ let { fileName: t = "document", triggerDownload: n = !0 } = e || {}, r = await L.current?.export({
900
+ exportType: ["docx"],
901
+ exportedName: t,
902
+ triggerDownload: n
903
+ }), i = L.current?.activeEditor;
904
+ if (i) {
905
+ let e = getTemplateFieldsFromEditor(i);
906
+ O?.({
907
+ fields: e,
908
+ blob: n ? void 0 : r,
909
+ fileName: t
910
+ });
911
+ }
912
+ return r;
913
+ }, [O]);
914
+ useImperativeHandle(c, () => ({
915
+ insertField: (e) => Y("inline", e),
916
+ insertBlockField: (e) => Y("block", e),
917
+ updateField: X,
918
+ deleteField: Z,
919
+ selectField: Q,
920
+ nextField: he,
921
+ previousField: ge,
922
+ getFields: () => k,
923
+ exportTemplate: _e,
924
+ getSuperDoc: () => L.current
925
+ }));
926
+ let ve = m.component || FieldMenu, ye = h.component || FieldList;
927
+ return /* @__PURE__ */ jsxs("div", {
928
+ className: `superdoc-template-builder ${ie || ""}`,
929
+ style: ae,
930
+ children: [/* @__PURE__ */ jsxs("div", {
931
+ style: {
932
+ display: "flex",
933
+ gap: "20px"
934
+ },
935
+ children: [
936
+ h.position === "left" && /* @__PURE__ */ jsx("div", {
937
+ className: "superdoc-template-builder-sidebar",
938
+ children: /* @__PURE__ */ jsx(ye, {
939
+ fields: k,
940
+ onSelect: (e) => Q(e.id),
941
+ onDelete: Z,
942
+ onUpdate: (e) => X(e.id, e),
943
+ selectedFieldId: j || void 0
944
+ })
945
+ }),
946
+ /* @__PURE__ */ jsxs("div", {
947
+ className: "superdoc-template-builder-document",
948
+ style: { flex: 1 },
949
+ children: [W?.renderDefaultContainer && /* @__PURE__ */ jsx("div", {
950
+ id: "superdoc-toolbar",
951
+ className: "superdoc-template-builder-toolbar",
952
+ "data-testid": "template-builder-toolbar"
953
+ }), /* @__PURE__ */ jsx("div", {
954
+ ref: I,
955
+ className: "superdoc-template-builder-editor",
956
+ style: { height: oe },
957
+ "data-testid": "template-builder-editor"
958
+ })]
959
+ }),
960
+ h.position === "right" && /* @__PURE__ */ jsx("div", {
961
+ className: "superdoc-template-builder-sidebar",
962
+ children: /* @__PURE__ */ jsx(ye, {
963
+ fields: k,
964
+ onSelect: (e) => Q(e.id),
965
+ onDelete: Z,
966
+ onUpdate: (e) => X(e.id, e),
967
+ selectedFieldId: j || void 0
968
+ })
969
+ })
970
+ ]
971
+ }), /* @__PURE__ */ jsx(ve, {
972
+ isVisible: N,
973
+ position: se,
974
+ availableFields: p.available || [],
975
+ filteredFields: ue,
976
+ filterQuery: ce,
977
+ allowCreate: p.allowCreate || !1,
978
+ onSelect: fe,
979
+ onClose: me,
980
+ onCreateField: D,
981
+ existingFields: k,
982
+ onSelectExisting: pe
983
+ })]
984
+ });
985
+ });
986
+ SuperDocTemplateBuilder.displayName = "SuperDocTemplateBuilder";
987
+ var src_default = SuperDocTemplateBuilder;
988
+ export { FieldList, FieldMenu, src_default as default };