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

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