@superdoc-dev/template-builder 0.2.0-next.4 → 0.2.0-next.6

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