@superdoc-dev/template-builder 0.1.0 → 0.2.0-next.2

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