@superdoc-dev/template-builder 0.2.0-next.5 → 0.2.0-next.7

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