@superdoc-dev/template-builder 1.2.0-next.1 → 1.2.0
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/README.md +148 -88
- package/dist/defaults/InfoTooltip.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +489 -313
- package/dist/tests/FieldList.test.d.ts +1 -0
- package/dist/tests/FieldMenu.test.d.ts +1 -0
- package/dist/tests/InfoTooltip.test.d.ts +1 -0
- package/dist/tests/utils.test.d.ts +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/utils.d.ts +17 -0
- package/package.json +4 -2
- package/src/styles/field-types.css +26 -0
- /package/dist/{test → tests}/setup.d.ts +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,111 @@
|
|
|
1
1
|
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const areTemplateFieldsEqual = (e, t) => {
|
|
4
|
+
if (e === t) return !0;
|
|
5
|
+
if (e.length !== t.length) return !1;
|
|
6
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
7
|
+
let r = e[n], i = t[n];
|
|
8
|
+
if (!i || r.id !== i.id || r.alias !== i.alias || r.tag !== i.tag || r.position !== i.position || r.mode !== i.mode || r.group !== i.group || r.fieldType !== i.fieldType) return !1;
|
|
9
|
+
}
|
|
10
|
+
return !0;
|
|
11
|
+
}, resolveToolbar = (e) => {
|
|
12
|
+
if (!e) return null;
|
|
13
|
+
if (e === !0) return {
|
|
14
|
+
selector: "#superdoc-toolbar",
|
|
15
|
+
config: {},
|
|
16
|
+
renderDefaultContainer: !0
|
|
17
|
+
};
|
|
18
|
+
if (typeof e == "string") return {
|
|
19
|
+
selector: e,
|
|
20
|
+
config: {},
|
|
21
|
+
renderDefaultContainer: !1
|
|
22
|
+
};
|
|
23
|
+
let { selector: t, ...n } = e;
|
|
24
|
+
return {
|
|
25
|
+
selector: t || "#superdoc-toolbar",
|
|
26
|
+
config: n,
|
|
27
|
+
renderDefaultContainer: t === void 0
|
|
28
|
+
};
|
|
29
|
+
}, getPresentationEditor = (e) => {
|
|
30
|
+
let t = e?.superdocStore?.documents;
|
|
31
|
+
return !Array.isArray(t) || t.length === 0 ? null : t[0].getPresentationEditor?.() ?? null;
|
|
32
|
+
};
|
|
33
|
+
var FIELD_TYPE_STYLES = { signer: {
|
|
34
|
+
background: "#fef3c7",
|
|
35
|
+
color: "#b45309"
|
|
36
|
+
} }, DEFAULT_FIELD_TYPE_STYLE = {
|
|
37
|
+
background: "#f3f4f6",
|
|
38
|
+
color: "#6b7280"
|
|
39
|
+
};
|
|
40
|
+
const getFieldTypeStyle = (e) => FIELD_TYPE_STYLES[e] ?? DEFAULT_FIELD_TYPE_STYLE, clampToViewport = (e) => {
|
|
41
|
+
let t = window.innerWidth - 250 - 10, n = window.innerHeight - 300 - 10, r = Math.min(e.left, t), i = Math.min(e.top, n);
|
|
42
|
+
return new DOMRect(Math.max(r, 10), Math.max(i, 10), e.width, e.height);
|
|
43
|
+
}, InfoTooltip = ({ text: e }) => {
|
|
44
|
+
let [t, n] = useState(!1);
|
|
45
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
46
|
+
style: {
|
|
47
|
+
position: "relative",
|
|
48
|
+
display: "inline-flex"
|
|
49
|
+
},
|
|
50
|
+
onMouseEnter: () => n(!0),
|
|
51
|
+
onMouseLeave: () => n(!1),
|
|
52
|
+
onClick: (e) => e.stopPropagation(),
|
|
53
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
54
|
+
width: "14",
|
|
55
|
+
height: "14",
|
|
56
|
+
viewBox: "0 0 16 16",
|
|
57
|
+
fill: "none",
|
|
58
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
59
|
+
style: {
|
|
60
|
+
cursor: "help",
|
|
61
|
+
flexShrink: 0
|
|
62
|
+
},
|
|
63
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
64
|
+
cx: "8",
|
|
65
|
+
cy: "8",
|
|
66
|
+
r: "7",
|
|
67
|
+
stroke: "#9ca3af",
|
|
68
|
+
strokeWidth: "1.5"
|
|
69
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
70
|
+
x: "8",
|
|
71
|
+
y: "11.5",
|
|
72
|
+
textAnchor: "middle",
|
|
73
|
+
fontSize: "10",
|
|
74
|
+
fontWeight: "600",
|
|
75
|
+
fontFamily: "system-ui, sans-serif",
|
|
76
|
+
fill: "#6b7280",
|
|
77
|
+
children: "?"
|
|
78
|
+
})]
|
|
79
|
+
}), t && /* @__PURE__ */ jsx("span", {
|
|
80
|
+
style: {
|
|
81
|
+
position: "absolute",
|
|
82
|
+
bottom: "100%",
|
|
83
|
+
left: "50%",
|
|
84
|
+
transform: "translateX(-50%)",
|
|
85
|
+
marginBottom: "6px",
|
|
86
|
+
padding: "6px 10px",
|
|
87
|
+
background: "#1f2937",
|
|
88
|
+
color: "#fff",
|
|
89
|
+
fontSize: "11px",
|
|
90
|
+
lineHeight: "1.4",
|
|
91
|
+
borderRadius: "4px",
|
|
92
|
+
whiteSpace: "normal",
|
|
93
|
+
width: "200px",
|
|
94
|
+
textAlign: "center",
|
|
95
|
+
zIndex: 1001,
|
|
96
|
+
pointerEvents: "none",
|
|
97
|
+
fontWeight: 400
|
|
98
|
+
},
|
|
99
|
+
children: e
|
|
100
|
+
})]
|
|
101
|
+
});
|
|
102
|
+
}, FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFields: a, filterQuery: s, allowCreate: c, onSelect: l, onClose: u, onCreateField: d, existingFields: p = [], onSelectExisting: ne }) => {
|
|
103
|
+
let [h, g] = useState(!1), [_, v] = useState(""), [y, b] = useState("inline"), [x, S] = useState("owner"), [C, w] = useState(!0), [T, E] = useState(!0);
|
|
5
104
|
useEffect(() => {
|
|
6
|
-
e || (
|
|
105
|
+
e || (g(!1), v(""), b("inline"), S("owner"));
|
|
7
106
|
}, [e]);
|
|
8
|
-
let
|
|
9
|
-
position: "
|
|
107
|
+
let D = useMemo(() => ({
|
|
108
|
+
position: "fixed",
|
|
10
109
|
left: t?.left,
|
|
11
110
|
top: t?.top,
|
|
12
111
|
zIndex: 1e3,
|
|
@@ -15,30 +114,33 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
15
114
|
borderRadius: "4px",
|
|
16
115
|
boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
|
|
17
116
|
padding: "8px 0",
|
|
18
|
-
width: "280px"
|
|
19
|
-
|
|
117
|
+
width: "280px",
|
|
118
|
+
maxHeight: `calc(100vh - ${(t?.top ?? 0) + 10}px)`,
|
|
119
|
+
overflowY: "auto"
|
|
120
|
+
}), [t]), O = a ?? r, k = !!s;
|
|
20
121
|
if (useEffect(() => {
|
|
21
|
-
|
|
22
|
-
}, [
|
|
23
|
-
let
|
|
24
|
-
let e =
|
|
122
|
+
k && E(!0);
|
|
123
|
+
}, [k]), !e) return null;
|
|
124
|
+
let A = async () => {
|
|
125
|
+
let e = _.trim();
|
|
25
126
|
if (!e) return;
|
|
26
127
|
let t = {
|
|
27
128
|
id: `custom_${Date.now()}`,
|
|
28
129
|
label: e,
|
|
29
|
-
mode:
|
|
130
|
+
mode: y,
|
|
131
|
+
fieldType: x
|
|
30
132
|
};
|
|
31
133
|
try {
|
|
32
134
|
l(d && await d(t) || t);
|
|
33
135
|
} finally {
|
|
34
|
-
|
|
136
|
+
g(!1), v(""), b("inline"), S("owner");
|
|
35
137
|
}
|
|
36
138
|
};
|
|
37
139
|
return /* @__PURE__ */ jsxs("div", {
|
|
38
140
|
className: "superdoc-field-menu",
|
|
39
|
-
style:
|
|
141
|
+
style: D,
|
|
40
142
|
children: [
|
|
41
|
-
|
|
143
|
+
k && /* @__PURE__ */ jsx("div", {
|
|
42
144
|
style: {
|
|
43
145
|
padding: "8px 16px",
|
|
44
146
|
borderBottom: "1px solid #f0f0f0",
|
|
@@ -59,9 +161,9 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
59
161
|
})]
|
|
60
162
|
})
|
|
61
163
|
}),
|
|
62
|
-
c && !
|
|
164
|
+
c && !h && /* @__PURE__ */ jsx("div", {
|
|
63
165
|
className: "field-menu-item",
|
|
64
|
-
onClick: () =>
|
|
166
|
+
onClick: () => g(!0),
|
|
65
167
|
style: {
|
|
66
168
|
padding: "8px 16px",
|
|
67
169
|
cursor: "pointer",
|
|
@@ -70,16 +172,16 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
70
172
|
},
|
|
71
173
|
children: "+ Create New Field"
|
|
72
174
|
}),
|
|
73
|
-
c &&
|
|
175
|
+
c && h && /* @__PURE__ */ jsxs("div", {
|
|
74
176
|
style: { padding: "8px 16px" },
|
|
75
177
|
children: [
|
|
76
178
|
/* @__PURE__ */ jsx("input", {
|
|
77
179
|
type: "text",
|
|
78
|
-
value:
|
|
180
|
+
value: _,
|
|
79
181
|
placeholder: "Field name...",
|
|
80
|
-
onChange: (e) =>
|
|
182
|
+
onChange: (e) => v(e.target.value),
|
|
81
183
|
onKeyDown: (e) => {
|
|
82
|
-
e.key === "Enter" &&
|
|
184
|
+
e.key === "Enter" && A(), e.key === "Escape" && (g(!1), v(""), b("inline"));
|
|
83
185
|
},
|
|
84
186
|
autoFocus: !0,
|
|
85
187
|
style: {
|
|
@@ -105,9 +207,10 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
105
207
|
},
|
|
106
208
|
children: [/* @__PURE__ */ jsx("input", {
|
|
107
209
|
type: "radio",
|
|
210
|
+
name: "fieldMode",
|
|
108
211
|
value: "inline",
|
|
109
|
-
checked:
|
|
110
|
-
onChange: () =>
|
|
212
|
+
checked: y === "inline",
|
|
213
|
+
onChange: () => b("inline")
|
|
111
214
|
}), "Inline"]
|
|
112
215
|
}), /* @__PURE__ */ jsxs("label", {
|
|
113
216
|
style: {
|
|
@@ -118,12 +221,50 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
118
221
|
},
|
|
119
222
|
children: [/* @__PURE__ */ jsx("input", {
|
|
120
223
|
type: "radio",
|
|
224
|
+
name: "fieldMode",
|
|
121
225
|
value: "block",
|
|
122
|
-
checked:
|
|
123
|
-
onChange: () =>
|
|
226
|
+
checked: y === "block",
|
|
227
|
+
onChange: () => b("block")
|
|
124
228
|
}), "Block"]
|
|
125
229
|
})]
|
|
126
230
|
}),
|
|
231
|
+
/* @__PURE__ */ jsxs("div", {
|
|
232
|
+
style: {
|
|
233
|
+
marginTop: "8px",
|
|
234
|
+
display: "flex",
|
|
235
|
+
gap: "12px",
|
|
236
|
+
fontSize: "13px"
|
|
237
|
+
},
|
|
238
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
239
|
+
style: {
|
|
240
|
+
display: "flex",
|
|
241
|
+
alignItems: "center",
|
|
242
|
+
gap: "4px",
|
|
243
|
+
cursor: "pointer"
|
|
244
|
+
},
|
|
245
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
246
|
+
type: "radio",
|
|
247
|
+
name: "fieldType",
|
|
248
|
+
value: "owner",
|
|
249
|
+
checked: x === "owner",
|
|
250
|
+
onChange: () => S("owner")
|
|
251
|
+
}), "Owner"]
|
|
252
|
+
}), /* @__PURE__ */ jsxs("label", {
|
|
253
|
+
style: {
|
|
254
|
+
display: "flex",
|
|
255
|
+
alignItems: "center",
|
|
256
|
+
gap: "4px",
|
|
257
|
+
cursor: "pointer"
|
|
258
|
+
},
|
|
259
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
260
|
+
type: "radio",
|
|
261
|
+
name: "fieldType",
|
|
262
|
+
value: "signer",
|
|
263
|
+
checked: x === "signer",
|
|
264
|
+
onChange: () => S("signer")
|
|
265
|
+
}), "Signer"]
|
|
266
|
+
})]
|
|
267
|
+
}),
|
|
127
268
|
/* @__PURE__ */ jsxs("div", {
|
|
128
269
|
style: {
|
|
129
270
|
marginTop: "8px",
|
|
@@ -131,20 +272,20 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
131
272
|
gap: "8px"
|
|
132
273
|
},
|
|
133
274
|
children: [/* @__PURE__ */ jsx("button", {
|
|
134
|
-
onClick:
|
|
135
|
-
disabled: !
|
|
275
|
+
onClick: A,
|
|
276
|
+
disabled: !_.trim(),
|
|
136
277
|
style: {
|
|
137
278
|
padding: "4px 12px",
|
|
138
|
-
background:
|
|
279
|
+
background: _.trim() ? "#0066cc" : "#ccc",
|
|
139
280
|
color: "white",
|
|
140
281
|
border: "none",
|
|
141
282
|
borderRadius: "3px",
|
|
142
|
-
cursor:
|
|
283
|
+
cursor: _.trim() ? "pointer" : "not-allowed"
|
|
143
284
|
},
|
|
144
285
|
children: "Create"
|
|
145
286
|
}), /* @__PURE__ */ jsx("button", {
|
|
146
287
|
onClick: () => {
|
|
147
|
-
|
|
288
|
+
g(!1), v(""), b("inline"), S("owner");
|
|
148
289
|
},
|
|
149
290
|
style: {
|
|
150
291
|
padding: "4px 12px",
|
|
@@ -162,9 +303,9 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
162
303
|
borderTop: "1px solid #eee",
|
|
163
304
|
margin: "4px 0"
|
|
164
305
|
} }),
|
|
165
|
-
|
|
306
|
+
p.length > 0 && (() => {
|
|
166
307
|
let e = /* @__PURE__ */ new Map();
|
|
167
|
-
|
|
308
|
+
p.forEach((t) => {
|
|
168
309
|
let n = t.group || `individual-${t.id}`, r = e.get(n) || [];
|
|
169
310
|
r.push(t), e.set(n, r);
|
|
170
311
|
});
|
|
@@ -176,7 +317,7 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
176
317
|
style: { borderBottom: "1px solid #f0f0f0" },
|
|
177
318
|
children: [/* @__PURE__ */ jsxs("button", {
|
|
178
319
|
type: "button",
|
|
179
|
-
onClick: () =>
|
|
320
|
+
onClick: () => w(!C),
|
|
180
321
|
style: {
|
|
181
322
|
width: "100%",
|
|
182
323
|
display: "flex",
|
|
@@ -191,11 +332,19 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
191
332
|
color: "#374151",
|
|
192
333
|
textAlign: "left"
|
|
193
334
|
},
|
|
194
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
335
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
336
|
+
style: {
|
|
337
|
+
display: "flex",
|
|
338
|
+
alignItems: "center",
|
|
339
|
+
gap: "4px"
|
|
340
|
+
},
|
|
341
|
+
children: [
|
|
342
|
+
"Existing Fields (",
|
|
343
|
+
t.length,
|
|
344
|
+
")",
|
|
345
|
+
/* @__PURE__ */ jsx(InfoTooltip, { text: "Insert a linked copy of a field already in the document. Linked fields share the same group and stay in sync." })
|
|
346
|
+
]
|
|
347
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
199
348
|
"aria-hidden": !0,
|
|
200
349
|
style: {
|
|
201
350
|
display: "inline-block",
|
|
@@ -203,45 +352,56 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
203
352
|
height: "8px",
|
|
204
353
|
borderRight: "2px solid #666",
|
|
205
354
|
borderBottom: "2px solid #666",
|
|
206
|
-
transform:
|
|
355
|
+
transform: C ? "rotate(45deg)" : "rotate(-45deg)",
|
|
207
356
|
transition: "transform 0.2s ease"
|
|
208
357
|
}
|
|
209
358
|
})]
|
|
210
|
-
}),
|
|
359
|
+
}), C && /* @__PURE__ */ jsx("div", { children: t.map((e) => /* @__PURE__ */ jsxs("div", {
|
|
360
|
+
className: "field-menu-item",
|
|
361
|
+
onClick: () => ne?.(e),
|
|
211
362
|
style: {
|
|
212
|
-
|
|
213
|
-
|
|
363
|
+
padding: "8px 16px",
|
|
364
|
+
cursor: "pointer",
|
|
365
|
+
display: "flex",
|
|
366
|
+
alignItems: "flex-start",
|
|
367
|
+
justifyContent: "space-between",
|
|
368
|
+
gap: "8px"
|
|
214
369
|
},
|
|
215
|
-
children:
|
|
216
|
-
|
|
217
|
-
|
|
370
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
371
|
+
style: {
|
|
372
|
+
flex: 1,
|
|
373
|
+
minWidth: 0
|
|
374
|
+
},
|
|
375
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
376
|
+
style: {
|
|
377
|
+
fontWeight: 500,
|
|
378
|
+
fontSize: "13px"
|
|
379
|
+
},
|
|
380
|
+
children: e.alias || e.id
|
|
381
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
382
|
+
style: {
|
|
383
|
+
fontSize: "11px",
|
|
384
|
+
color: "#9ca3af",
|
|
385
|
+
marginTop: "2px"
|
|
386
|
+
},
|
|
387
|
+
children: e.group ? `group (${e.count} fields)` : `ID: ${e.id}`
|
|
388
|
+
})]
|
|
389
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
218
390
|
style: {
|
|
219
|
-
padding: "8px 16px",
|
|
220
|
-
cursor: "pointer",
|
|
221
391
|
display: "flex",
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
gap: "8px"
|
|
392
|
+
gap: "4px",
|
|
393
|
+
flexShrink: 0
|
|
225
394
|
},
|
|
226
|
-
children: [/* @__PURE__ */
|
|
395
|
+
children: [e.fieldType && /* @__PURE__ */ jsx("span", {
|
|
227
396
|
style: {
|
|
228
|
-
|
|
229
|
-
|
|
397
|
+
fontSize: "11px",
|
|
398
|
+
padding: "2px 6px",
|
|
399
|
+
borderRadius: "3px",
|
|
400
|
+
textTransform: "capitalize",
|
|
401
|
+
...getFieldTypeStyle(e.fieldType),
|
|
402
|
+
fontWeight: 500
|
|
230
403
|
},
|
|
231
|
-
children:
|
|
232
|
-
style: {
|
|
233
|
-
fontWeight: 500,
|
|
234
|
-
fontSize: "13px"
|
|
235
|
-
},
|
|
236
|
-
children: e.alias || e.id
|
|
237
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
238
|
-
style: {
|
|
239
|
-
fontSize: "11px",
|
|
240
|
-
color: "#9ca3af",
|
|
241
|
-
marginTop: "2px"
|
|
242
|
-
},
|
|
243
|
-
children: e.group ? `group (${e.count} fields)` : `ID: ${e.id}`
|
|
244
|
-
})]
|
|
404
|
+
children: e.fieldType
|
|
245
405
|
}), /* @__PURE__ */ jsx("span", {
|
|
246
406
|
style: {
|
|
247
407
|
fontSize: "11px",
|
|
@@ -249,16 +409,15 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
249
409
|
padding: "2px 6px",
|
|
250
410
|
background: "#f3f4f6",
|
|
251
411
|
borderRadius: "3px",
|
|
252
|
-
textTransform: "capitalize"
|
|
253
|
-
flexShrink: 0
|
|
412
|
+
textTransform: "capitalize"
|
|
254
413
|
},
|
|
255
414
|
children: e.mode || "inline"
|
|
256
415
|
})]
|
|
257
|
-
}
|
|
258
|
-
})]
|
|
416
|
+
})]
|
|
417
|
+
}, e.group || e.id)) })]
|
|
259
418
|
});
|
|
260
419
|
})(),
|
|
261
|
-
|
|
420
|
+
O.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
262
421
|
style: {
|
|
263
422
|
padding: "16px",
|
|
264
423
|
fontSize: "13px",
|
|
@@ -270,7 +429,7 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
270
429
|
style: { borderBottom: "1px solid #f0f0f0" },
|
|
271
430
|
children: [/* @__PURE__ */ jsxs("button", {
|
|
272
431
|
type: "button",
|
|
273
|
-
onClick: () =>
|
|
432
|
+
onClick: () => E(!T),
|
|
274
433
|
style: {
|
|
275
434
|
width: "100%",
|
|
276
435
|
display: "flex",
|
|
@@ -285,11 +444,19 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
285
444
|
color: "#374151",
|
|
286
445
|
textAlign: "left"
|
|
287
446
|
},
|
|
288
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
447
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
448
|
+
style: {
|
|
449
|
+
display: "flex",
|
|
450
|
+
alignItems: "center",
|
|
451
|
+
gap: "4px"
|
|
452
|
+
},
|
|
453
|
+
children: [
|
|
454
|
+
"Available Fields (",
|
|
455
|
+
O.length,
|
|
456
|
+
")",
|
|
457
|
+
/* @__PURE__ */ jsx(InfoTooltip, { text: "Insert a new, independent field instance into the document." })
|
|
458
|
+
]
|
|
459
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
293
460
|
"aria-hidden": !0,
|
|
294
461
|
style: {
|
|
295
462
|
display: "inline-block",
|
|
@@ -297,45 +464,56 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
297
464
|
height: "8px",
|
|
298
465
|
borderRight: "2px solid #666",
|
|
299
466
|
borderBottom: "2px solid #666",
|
|
300
|
-
transform:
|
|
467
|
+
transform: T ? "rotate(45deg)" : "rotate(-45deg)",
|
|
301
468
|
transition: "transform 0.2s ease"
|
|
302
469
|
}
|
|
303
470
|
})]
|
|
304
|
-
}),
|
|
471
|
+
}), T && /* @__PURE__ */ jsx("div", { children: O.map((e) => /* @__PURE__ */ jsxs("div", {
|
|
472
|
+
className: "field-menu-item",
|
|
473
|
+
onClick: () => l(e),
|
|
305
474
|
style: {
|
|
306
|
-
|
|
307
|
-
|
|
475
|
+
padding: "8px 16px",
|
|
476
|
+
cursor: "pointer",
|
|
477
|
+
display: "flex",
|
|
478
|
+
alignItems: "flex-start",
|
|
479
|
+
justifyContent: "space-between",
|
|
480
|
+
gap: "8px"
|
|
308
481
|
},
|
|
309
|
-
children:
|
|
310
|
-
|
|
311
|
-
|
|
482
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
483
|
+
style: {
|
|
484
|
+
flex: 1,
|
|
485
|
+
minWidth: 0
|
|
486
|
+
},
|
|
487
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
488
|
+
style: {
|
|
489
|
+
fontWeight: 500,
|
|
490
|
+
fontSize: "13px"
|
|
491
|
+
},
|
|
492
|
+
children: e.label || e.id
|
|
493
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
494
|
+
style: {
|
|
495
|
+
fontSize: "11px",
|
|
496
|
+
color: "#9ca3af",
|
|
497
|
+
marginTop: "2px"
|
|
498
|
+
},
|
|
499
|
+
children: ["ID: ", e.id]
|
|
500
|
+
})]
|
|
501
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
312
502
|
style: {
|
|
313
|
-
padding: "8px 16px",
|
|
314
|
-
cursor: "pointer",
|
|
315
503
|
display: "flex",
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
gap: "8px"
|
|
504
|
+
gap: "4px",
|
|
505
|
+
flexShrink: 0
|
|
319
506
|
},
|
|
320
|
-
children: [/* @__PURE__ */
|
|
507
|
+
children: [e.fieldType && /* @__PURE__ */ jsx("span", {
|
|
321
508
|
style: {
|
|
322
|
-
|
|
323
|
-
|
|
509
|
+
fontSize: "11px",
|
|
510
|
+
padding: "2px 6px",
|
|
511
|
+
borderRadius: "3px",
|
|
512
|
+
textTransform: "capitalize",
|
|
513
|
+
...getFieldTypeStyle(e.fieldType),
|
|
514
|
+
fontWeight: 500
|
|
324
515
|
},
|
|
325
|
-
children:
|
|
326
|
-
style: {
|
|
327
|
-
fontWeight: 500,
|
|
328
|
-
fontSize: "13px"
|
|
329
|
-
},
|
|
330
|
-
children: e.label || e.id
|
|
331
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
332
|
-
style: {
|
|
333
|
-
fontSize: "11px",
|
|
334
|
-
color: "#9ca3af",
|
|
335
|
-
marginTop: "2px"
|
|
336
|
-
},
|
|
337
|
-
children: ["ID: ", e.id]
|
|
338
|
-
})]
|
|
516
|
+
children: e.fieldType
|
|
339
517
|
}), /* @__PURE__ */ jsx("span", {
|
|
340
518
|
style: {
|
|
341
519
|
fontSize: "11px",
|
|
@@ -343,13 +521,12 @@ const FieldMenu = ({ isVisible: e, position: t, availableFields: r, filteredFiel
|
|
|
343
521
|
padding: "2px 6px",
|
|
344
522
|
background: "#f3f4f6",
|
|
345
523
|
borderRadius: "3px",
|
|
346
|
-
textTransform: "capitalize"
|
|
347
|
-
flexShrink: 0
|
|
524
|
+
textTransform: "capitalize"
|
|
348
525
|
},
|
|
349
526
|
children: e.mode || "inline"
|
|
350
527
|
})]
|
|
351
|
-
}
|
|
352
|
-
})]
|
|
528
|
+
})]
|
|
529
|
+
}, e.id)) })]
|
|
353
530
|
}),
|
|
354
531
|
/* @__PURE__ */ jsx("div", {
|
|
355
532
|
style: {
|
|
@@ -451,22 +628,35 @@ var shortenGroupId = (e) => {
|
|
|
451
628
|
color: "#9ca3af",
|
|
452
629
|
marginTop: "2px"
|
|
453
630
|
},
|
|
454
|
-
children: [
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
631
|
+
children: [
|
|
632
|
+
/* @__PURE__ */ jsxs("span", { children: ["ID: ", e.id] }),
|
|
633
|
+
e.mode && /* @__PURE__ */ jsx("span", {
|
|
634
|
+
style: {
|
|
635
|
+
fontSize: "9px",
|
|
636
|
+
padding: "2px 5px",
|
|
637
|
+
borderRadius: "3px",
|
|
638
|
+
background: e.mode === "block" ? "#dbeafe" : "#f3f4f6",
|
|
639
|
+
color: e.mode === "block" ? "#1e40af" : "#4b5563",
|
|
640
|
+
fontWeight: "500"
|
|
641
|
+
},
|
|
642
|
+
children: e.mode
|
|
643
|
+
}),
|
|
644
|
+
e.fieldType && /* @__PURE__ */ jsx("span", {
|
|
645
|
+
style: {
|
|
646
|
+
fontSize: "9px",
|
|
647
|
+
padding: "2px 5px",
|
|
648
|
+
borderRadius: "3px",
|
|
649
|
+
...getFieldTypeStyle(e.fieldType),
|
|
650
|
+
fontWeight: "500"
|
|
651
|
+
},
|
|
652
|
+
children: e.fieldType
|
|
653
|
+
})
|
|
654
|
+
]
|
|
465
655
|
})]
|
|
466
656
|
})]
|
|
467
657
|
});
|
|
468
658
|
const FieldList = ({ fields: e, onSelect: t, onDelete: n, selectedFieldId: r }) => {
|
|
469
|
-
let [a, s] = useState(/* @__PURE__ */ new Set()), { groupedFields:
|
|
659
|
+
let [a, s] = useState(/* @__PURE__ */ new Set()), { groupedFields: c, ungroupedFields: l } = useMemo(() => {
|
|
470
660
|
let t = {}, n = [];
|
|
471
661
|
return e.forEach((e) => {
|
|
472
662
|
e.group ? (t[e.group] || (t[e.group] = []), t[e.group].push(e)) : n.push(e);
|
|
@@ -474,7 +664,7 @@ const FieldList = ({ fields: e, onSelect: t, onDelete: n, selectedFieldId: r })
|
|
|
474
664
|
groupedFields: t,
|
|
475
665
|
ungroupedFields: n
|
|
476
666
|
};
|
|
477
|
-
}, [e]),
|
|
667
|
+
}, [e]), u = (e) => {
|
|
478
668
|
s((t) => {
|
|
479
669
|
let n = new Set(t);
|
|
480
670
|
return n.has(e) ? n.delete(e) : n.add(e), n;
|
|
@@ -518,12 +708,12 @@ const FieldList = ({ fields: e, onSelect: t, onDelete: n, selectedFieldId: r })
|
|
|
518
708
|
flexDirection: "column",
|
|
519
709
|
gap: "8px"
|
|
520
710
|
},
|
|
521
|
-
children: [
|
|
711
|
+
children: [l.map((e) => /* @__PURE__ */ jsx(FieldItem, {
|
|
522
712
|
field: e,
|
|
523
713
|
onSelect: t,
|
|
524
714
|
onDelete: n,
|
|
525
715
|
isSelected: r === e.id
|
|
526
|
-
}, e.id)), Object.entries(
|
|
716
|
+
}, e.id)), Object.entries(c).map(([e, i]) => {
|
|
527
717
|
let o = a.has(e), s = i[0];
|
|
528
718
|
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
|
|
529
719
|
style: {
|
|
@@ -535,7 +725,7 @@ const FieldList = ({ fields: e, onSelect: t, onDelete: n, selectedFieldId: r })
|
|
|
535
725
|
cursor: "pointer",
|
|
536
726
|
transition: "all 0.2s"
|
|
537
727
|
},
|
|
538
|
-
onClick: () =>
|
|
728
|
+
onClick: () => u(e),
|
|
539
729
|
onMouseEnter: (e) => {
|
|
540
730
|
e.currentTarget.style.background = "#f3f4f6";
|
|
541
731
|
},
|
|
@@ -601,113 +791,94 @@ const FieldList = ({ fields: e, onSelect: t, onDelete: n, selectedFieldId: r })
|
|
|
601
791
|
var getTemplateFieldsFromEditor = (e) => {
|
|
602
792
|
let t = e.helpers?.structuredContentCommands;
|
|
603
793
|
return t?.getStructuredContentTags ? (t.getStructuredContentTags(e.state) || []).map((e) => {
|
|
604
|
-
let n = e?.node ?? e, r = n?.attrs ?? {}, i = (n?.type?.name || "").includes("Block") ? "block" : "inline"
|
|
794
|
+
let n = e?.node ?? e, r = n?.attrs ?? {}, i = (n?.type?.name || "").includes("Block") ? "block" : "inline", a = (() => {
|
|
795
|
+
try {
|
|
796
|
+
return typeof r.tag == "string" && r.tag.startsWith("{") ? JSON.parse(r.tag) : null;
|
|
797
|
+
} catch {
|
|
798
|
+
return null;
|
|
799
|
+
}
|
|
800
|
+
})();
|
|
605
801
|
return {
|
|
606
802
|
id: r.id,
|
|
607
803
|
alias: r.alias || r.label || "",
|
|
608
804
|
tag: r.tag,
|
|
609
805
|
mode: i,
|
|
610
|
-
group: t.getGroup?.(r.tag) ?? void 0
|
|
806
|
+
group: t.getGroup?.(r.tag) ?? void 0,
|
|
807
|
+
fieldType: a?.fieldType ?? "owner"
|
|
611
808
|
};
|
|
612
809
|
}) : [];
|
|
613
|
-
},
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
let r = e[n], i = t[n];
|
|
618
|
-
if (!i || r.id !== i.id || r.alias !== i.alias || r.tag !== i.tag || r.position !== i.position || r.mode !== i.mode || r.group !== i.group) return !1;
|
|
619
|
-
}
|
|
620
|
-
return !0;
|
|
621
|
-
}, resolveToolbar = (e) => {
|
|
622
|
-
if (!e) return null;
|
|
623
|
-
if (e === !0) return {
|
|
624
|
-
selector: "#superdoc-toolbar",
|
|
625
|
-
config: {},
|
|
626
|
-
renderDefaultContainer: !0
|
|
627
|
-
};
|
|
628
|
-
if (typeof e == "string") return {
|
|
629
|
-
selector: e,
|
|
630
|
-
config: {},
|
|
631
|
-
renderDefaultContainer: !1
|
|
632
|
-
};
|
|
633
|
-
let { selector: t, ...n } = e;
|
|
634
|
-
return {
|
|
635
|
-
selector: t || "#superdoc-toolbar",
|
|
636
|
-
config: n,
|
|
637
|
-
renderDefaultContainer: t === void 0
|
|
638
|
-
};
|
|
639
|
-
}, MENU_VIEWPORT_PADDING = 10, MENU_APPROX_WIDTH = 250, MENU_APPROX_HEIGHT = 300, clampToViewport = (e) => {
|
|
640
|
-
let t = window.innerWidth - MENU_APPROX_WIDTH - MENU_VIEWPORT_PADDING, n = window.innerHeight - MENU_APPROX_HEIGHT - MENU_VIEWPORT_PADDING, r = Math.min(e.left, t), i = Math.min(e.top, n);
|
|
641
|
-
return new DOMRect(Math.max(r, MENU_VIEWPORT_PADDING), Math.max(i, MENU_VIEWPORT_PADDING), e.width, e.height);
|
|
642
|
-
}, SuperDocTemplateBuilder = forwardRef((e, c) => {
|
|
643
|
-
let { document: l, fields: p = {}, menu: m = {}, list: h = {}, toolbar: _, cspNonce: v, telemetry: y, licenseKey: b, onReady: x, onTrigger: S, onFieldInsert: C, onFieldUpdate: w, onFieldDelete: T, onFieldsChange: E, onFieldSelect: re, onFieldCreate: D, onExport: O, className: ie, style: ae, documentHeight: oe = "600px" } = e, [k, A] = useState(p.initial || []), [j, M] = useState(null), [N, P] = useState(!1), [se, F] = useState(), [ce, le] = useState(""), [ue, de] = useState(() => p.available || []), I = useRef(null), L = useRef(null), R = useRef(null), z = useRef(p);
|
|
644
|
-
z.current = p;
|
|
645
|
-
let B = useRef(null), V = useRef(N);
|
|
810
|
+
}, SuperDocTemplateBuilder = forwardRef((e, u) => {
|
|
811
|
+
let { document: d, fields: f = {}, menu: m = {}, list: h = {}, toolbar: g, cspNonce: y, telemetry: b, licenseKey: x, onReady: S, onTrigger: C, onFieldInsert: w, onFieldUpdate: T, onFieldDelete: E, onFieldsChange: D, onFieldSelect: O, onFieldCreate: k, onExport: A, className: re, style: ie, documentHeight: ae = "600px" } = e, [j, M] = useState(f.initial || []), [N, P] = useState(null), [F, I] = useState(!1), [oe, L] = useState(), [se, ce] = useState(""), [le, ue] = useState(() => f.available || []), R = useRef(null), z = useRef(null), B = useRef(null), de = useRef(f);
|
|
812
|
+
de.current = f;
|
|
813
|
+
let V = useRef(null), H = useRef(F);
|
|
646
814
|
useEffect(() => {
|
|
647
|
-
|
|
648
|
-
}, [
|
|
649
|
-
let
|
|
650
|
-
enabled:
|
|
815
|
+
H.current = F;
|
|
816
|
+
}, [F]);
|
|
817
|
+
let U = m.trigger || "{{", W = de.current.available || [], G = useMemo(() => resolveToolbar(g), [g]), K = useMemo(() => ({
|
|
818
|
+
enabled: b?.enabled ?? !0,
|
|
651
819
|
metadata: {
|
|
652
820
|
source: "template-builder",
|
|
653
|
-
...
|
|
821
|
+
...b?.metadata
|
|
654
822
|
}
|
|
655
|
-
}), [
|
|
823
|
+
}), [b?.enabled, JSON.stringify(b?.metadata)]), fe = useCallback((e) => {
|
|
656
824
|
let t = e.trim().toLowerCase();
|
|
657
|
-
return t ?
|
|
658
|
-
}, [
|
|
659
|
-
|
|
660
|
-
}, [
|
|
825
|
+
return t ? W.filter((e) => e.label.toLowerCase().includes(t)) : W;
|
|
826
|
+
}, [W]), q = useCallback((e) => {
|
|
827
|
+
ce(e), ue(fe(e));
|
|
828
|
+
}, [fe]), J = useCallback(() => {
|
|
661
829
|
q("");
|
|
662
830
|
}, [q]), Y = useCallback((e, t) => {
|
|
663
|
-
if (!
|
|
664
|
-
let n =
|
|
831
|
+
if (!z.current?.activeEditor) return !1;
|
|
832
|
+
let n = z.current.activeEditor, r = j, i = t.metadata || t.fieldType ? JSON.stringify({
|
|
833
|
+
...t.metadata,
|
|
834
|
+
...t.fieldType ? { fieldType: t.fieldType } : {}
|
|
835
|
+
}) : void 0, a = e === "inline" ? n.commands.insertStructuredContentInline?.({
|
|
665
836
|
attrs: {
|
|
666
837
|
alias: t.alias,
|
|
667
|
-
tag:
|
|
838
|
+
tag: i
|
|
668
839
|
},
|
|
669
840
|
text: t.defaultValue || t.alias
|
|
670
841
|
}) : n.commands.insertStructuredContentBlock?.({
|
|
671
842
|
attrs: {
|
|
672
843
|
alias: t.alias,
|
|
673
|
-
tag:
|
|
844
|
+
tag: i
|
|
674
845
|
},
|
|
675
846
|
text: t.defaultValue || t.alias
|
|
676
847
|
});
|
|
677
|
-
if (
|
|
848
|
+
if (a) {
|
|
678
849
|
let e = getTemplateFieldsFromEditor(n);
|
|
679
|
-
|
|
850
|
+
M(e), D?.(e);
|
|
680
851
|
let t = e.find((e) => !r.some((t) => t.id === e.id));
|
|
681
|
-
t &&
|
|
852
|
+
t && w?.(t);
|
|
682
853
|
}
|
|
683
|
-
return
|
|
854
|
+
return a ?? !1;
|
|
684
855
|
}, [
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
856
|
+
w,
|
|
857
|
+
D,
|
|
858
|
+
j
|
|
688
859
|
]), X = useCallback((e, t) => {
|
|
689
|
-
if (!
|
|
690
|
-
let n =
|
|
691
|
-
return n &&
|
|
860
|
+
if (!z.current?.activeEditor) return !1;
|
|
861
|
+
let n = z.current.activeEditor.commands.updateStructuredContentById?.(e, { attrs: t });
|
|
862
|
+
return n && M((n) => {
|
|
692
863
|
let r = n.map((n) => n.id === e ? {
|
|
693
864
|
...n,
|
|
694
865
|
...t
|
|
695
866
|
} : n);
|
|
696
|
-
|
|
867
|
+
D?.(r);
|
|
697
868
|
let i = r.find((t) => t.id === e);
|
|
698
|
-
return i &&
|
|
869
|
+
return i && T?.(i), r;
|
|
699
870
|
}), n ?? !1;
|
|
700
|
-
}, [
|
|
701
|
-
let t =
|
|
871
|
+
}, [T, D]), Z = useCallback((e) => {
|
|
872
|
+
let t = z.current?.activeEditor;
|
|
702
873
|
if (!t) {
|
|
703
874
|
let t = !1;
|
|
704
|
-
return
|
|
875
|
+
return M((n) => {
|
|
705
876
|
if (!n.some((t) => t.id === e)) return n;
|
|
706
877
|
let r = n.filter((t) => t.id !== e);
|
|
707
|
-
return t = !0,
|
|
708
|
-
}), t &&
|
|
878
|
+
return t = !0, D?.(r), E?.(e), r;
|
|
879
|
+
}), t && P((t) => t === e ? null : t), t;
|
|
709
880
|
}
|
|
710
|
-
let n =
|
|
881
|
+
let n = j.find((t) => t.id === e)?.group, r = !1;
|
|
711
882
|
try {
|
|
712
883
|
r = t.commands.deleteStructuredContentById?.(e) ?? !1;
|
|
713
884
|
} catch (t) {
|
|
@@ -722,140 +893,145 @@ var getTemplateFieldsFromEditor = (e) => {
|
|
|
722
893
|
}
|
|
723
894
|
}
|
|
724
895
|
let o = !1;
|
|
725
|
-
return
|
|
896
|
+
return M((t) => {
|
|
726
897
|
if (areTemplateFieldsEqual(t, i)) return t;
|
|
727
898
|
let n = t.some((t) => t.id === e), r = i.some((t) => t.id === e);
|
|
728
|
-
return n && !r && (o = !0),
|
|
729
|
-
}), o &&
|
|
899
|
+
return n && !r && (o = !0), D?.(i), o && E?.(e), i;
|
|
900
|
+
}), o && P((t) => t === e ? null : t), r || o;
|
|
730
901
|
}, [
|
|
731
|
-
T,
|
|
732
902
|
E,
|
|
733
|
-
|
|
903
|
+
D,
|
|
904
|
+
j
|
|
734
905
|
]), Q = useCallback((e) => {
|
|
735
|
-
if (!
|
|
736
|
-
|
|
737
|
-
let t =
|
|
738
|
-
t &&
|
|
739
|
-
}, [
|
|
906
|
+
if (!z.current?.activeEditor) return;
|
|
907
|
+
z.current.activeEditor.commands.selectStructuredContentById?.(e), P(e);
|
|
908
|
+
let t = j.find((t) => t.id === e);
|
|
909
|
+
t && O?.(t);
|
|
910
|
+
}, [j, O]), $ = useCallback((e) => {
|
|
740
911
|
if (!e) return;
|
|
741
912
|
let t = getTemplateFieldsFromEditor(e);
|
|
742
|
-
|
|
743
|
-
}, [
|
|
913
|
+
M((e) => areTemplateFieldsEqual(e, t) ? e : (D?.(t), t));
|
|
914
|
+
}, [D]);
|
|
744
915
|
useEffect(() => {
|
|
745
|
-
if (!
|
|
916
|
+
if (!R.current) return;
|
|
746
917
|
let e = !1, t = null;
|
|
747
918
|
return (async () => {
|
|
748
919
|
let { SuperDoc: n } = await import("superdoc");
|
|
749
920
|
if (e) return;
|
|
750
921
|
let r = {
|
|
751
922
|
comments: !1,
|
|
752
|
-
...
|
|
753
|
-
selector:
|
|
754
|
-
toolbarGroups:
|
|
755
|
-
excludeItems:
|
|
756
|
-
...
|
|
923
|
+
...G && { toolbar: {
|
|
924
|
+
selector: G.selector,
|
|
925
|
+
toolbarGroups: G.config.toolbarGroups || ["center"],
|
|
926
|
+
excludeItems: G.config.excludeItems || [],
|
|
927
|
+
...G.config
|
|
757
928
|
} }
|
|
758
929
|
}, i = () => {
|
|
759
930
|
if (!e) {
|
|
760
931
|
if (t?.activeEditor) {
|
|
761
|
-
let e = t.activeEditor;
|
|
932
|
+
let e = t.activeEditor, n = getPresentationEditor(t);
|
|
762
933
|
e.on("update", ({ editor: e }) => {
|
|
763
|
-
let { state: t } = e, { from:
|
|
764
|
-
if (
|
|
765
|
-
let
|
|
766
|
-
if (t.doc.textBetween(
|
|
767
|
-
let t = e.view.coordsAtPos(
|
|
768
|
-
let e =
|
|
934
|
+
let { state: t } = e, { from: r } = t.selection;
|
|
935
|
+
if (r >= U.length) {
|
|
936
|
+
let i = r - U.length;
|
|
937
|
+
if (t.doc.textBetween(i, r) === U) {
|
|
938
|
+
let t = n?.coordsAtPos(r) ?? e.view.coordsAtPos(r), a = clampToViewport(new DOMRect(t.left, t.bottom ?? t.top, 0, 0)), o = () => {
|
|
939
|
+
let e = z.current?.activeEditor;
|
|
769
940
|
if (!e) return;
|
|
770
|
-
let t = e.state.selection.from, n = e.state.tr.delete(
|
|
941
|
+
let t = e.state.selection.from, n = e.state.tr.delete(i, t);
|
|
771
942
|
e.view.dispatch(n);
|
|
772
943
|
};
|
|
773
|
-
|
|
944
|
+
B.current = o, V.current = r, L(a), I(!0), J(), C?.({
|
|
774
945
|
position: {
|
|
775
|
-
from:
|
|
776
|
-
to:
|
|
946
|
+
from: i,
|
|
947
|
+
to: r
|
|
777
948
|
},
|
|
778
|
-
bounds:
|
|
779
|
-
cleanup:
|
|
949
|
+
bounds: a,
|
|
950
|
+
cleanup: o
|
|
780
951
|
});
|
|
781
952
|
return;
|
|
782
953
|
}
|
|
783
954
|
}
|
|
784
|
-
if (!
|
|
785
|
-
if (
|
|
786
|
-
|
|
955
|
+
if (!H.current) return;
|
|
956
|
+
if (V.current == null) {
|
|
957
|
+
I(!1), J();
|
|
787
958
|
return;
|
|
788
959
|
}
|
|
789
|
-
if (
|
|
790
|
-
|
|
960
|
+
if (r < V.current) {
|
|
961
|
+
I(!1), V.current = null, J();
|
|
791
962
|
return;
|
|
792
963
|
}
|
|
793
|
-
q(t.doc.textBetween(
|
|
794
|
-
let
|
|
795
|
-
|
|
964
|
+
q(t.doc.textBetween(V.current, r));
|
|
965
|
+
let i = n?.coordsAtPos(r) ?? e.view.coordsAtPos(r);
|
|
966
|
+
L(clampToViewport(new DOMRect(i.left, i.bottom ?? i.top, 0, 0)));
|
|
796
967
|
}), e.on("update", () => {
|
|
797
968
|
$(e);
|
|
798
969
|
}), $(e);
|
|
799
970
|
}
|
|
800
|
-
|
|
971
|
+
S?.();
|
|
801
972
|
}
|
|
802
973
|
};
|
|
803
974
|
t = new n({
|
|
804
|
-
selector:
|
|
805
|
-
document:
|
|
806
|
-
documentMode:
|
|
975
|
+
selector: R.current,
|
|
976
|
+
document: d?.source,
|
|
977
|
+
documentMode: d?.mode || "editing",
|
|
807
978
|
modules: r,
|
|
808
|
-
toolbar:
|
|
809
|
-
cspNonce:
|
|
810
|
-
telemetry:
|
|
811
|
-
...
|
|
979
|
+
toolbar: G?.selector,
|
|
980
|
+
cspNonce: y,
|
|
981
|
+
telemetry: K,
|
|
982
|
+
...x && { licenseKey: x },
|
|
812
983
|
onReady: i
|
|
813
|
-
}),
|
|
984
|
+
}), z.current = t;
|
|
814
985
|
})(), () => {
|
|
815
|
-
e = !0,
|
|
986
|
+
e = !0, B.current = null, V.current = null, t && typeof t.destroy == "function" && t.destroy(), z.current = null;
|
|
816
987
|
};
|
|
817
988
|
}, [
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
989
|
+
d?.source,
|
|
990
|
+
d?.mode,
|
|
991
|
+
U,
|
|
821
992
|
$,
|
|
822
|
-
x,
|
|
823
993
|
S,
|
|
824
|
-
|
|
825
|
-
v,
|
|
994
|
+
C,
|
|
826
995
|
G,
|
|
827
|
-
|
|
996
|
+
y,
|
|
997
|
+
K,
|
|
998
|
+
x
|
|
828
999
|
]);
|
|
829
|
-
let
|
|
830
|
-
|
|
1000
|
+
let pe = useCallback(async (e) => {
|
|
1001
|
+
B.current &&= (B.current(), null), V.current = null, J();
|
|
831
1002
|
let t = e.mode || "inline";
|
|
832
|
-
if (e.id.startsWith("custom_") &&
|
|
833
|
-
let n = await
|
|
1003
|
+
if (e.id.startsWith("custom_") && k) {
|
|
1004
|
+
let n = await k(e);
|
|
834
1005
|
if (n) {
|
|
835
1006
|
Y(n.mode || t, {
|
|
836
1007
|
alias: n.label,
|
|
837
1008
|
metadata: n.metadata,
|
|
838
|
-
defaultValue: n.defaultValue
|
|
839
|
-
|
|
1009
|
+
defaultValue: n.defaultValue,
|
|
1010
|
+
fieldType: n.fieldType
|
|
1011
|
+
}), I(!1);
|
|
840
1012
|
return;
|
|
841
1013
|
}
|
|
842
1014
|
}
|
|
843
1015
|
Y(t, {
|
|
844
1016
|
alias: e.label,
|
|
845
1017
|
metadata: e.metadata,
|
|
846
|
-
defaultValue: e.defaultValue
|
|
847
|
-
|
|
1018
|
+
defaultValue: e.defaultValue,
|
|
1019
|
+
fieldType: e.fieldType
|
|
1020
|
+
}), I(!1);
|
|
848
1021
|
}, [
|
|
849
1022
|
Y,
|
|
850
|
-
|
|
1023
|
+
k,
|
|
851
1024
|
J
|
|
852
|
-
]),
|
|
853
|
-
|
|
854
|
-
let t =
|
|
1025
|
+
]), me = useCallback((e) => {
|
|
1026
|
+
B.current &&= (B.current(), null), V.current = null, J();
|
|
1027
|
+
let t = z.current?.activeEditor;
|
|
855
1028
|
if (!t) return;
|
|
856
1029
|
let n = t.helpers?.structuredContentCommands;
|
|
857
1030
|
if (!n) return;
|
|
858
|
-
let r = e.group || `group-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`, i = n.createTagObject?.({
|
|
1031
|
+
let r = e.group || `group-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`, i = n.createTagObject?.({
|
|
1032
|
+
group: r,
|
|
1033
|
+
...e.fieldType ? { fieldType: e.fieldType } : {}
|
|
1034
|
+
});
|
|
859
1035
|
if ((e.mode || "inline") === "inline" ? t.commands.insertStructuredContentInline?.({
|
|
860
1036
|
attrs: {
|
|
861
1037
|
alias: e.alias,
|
|
@@ -869,64 +1045,64 @@ var getTemplateFieldsFromEditor = (e) => {
|
|
|
869
1045
|
},
|
|
870
1046
|
text: e.alias
|
|
871
1047
|
})) {
|
|
872
|
-
e.group || X(e.id, { tag: i }),
|
|
1048
|
+
e.group || X(e.id, { tag: i }), I(!1);
|
|
873
1049
|
let n = getTemplateFieldsFromEditor(t);
|
|
874
|
-
|
|
1050
|
+
M(n), D?.(n);
|
|
875
1051
|
}
|
|
876
1052
|
}, [
|
|
877
1053
|
X,
|
|
878
1054
|
J,
|
|
879
|
-
|
|
880
|
-
]),
|
|
881
|
-
|
|
882
|
-
}, [J]),
|
|
883
|
-
if (!
|
|
884
|
-
let e =
|
|
885
|
-
Q(
|
|
1055
|
+
D
|
|
1056
|
+
]), he = useCallback(() => {
|
|
1057
|
+
I(!1), V.current = null, J(), B.current &&= (B.current(), null);
|
|
1058
|
+
}, [J]), ge = useCallback(() => {
|
|
1059
|
+
if (!z.current?.activeEditor || j.length === 0) return;
|
|
1060
|
+
let e = j.findIndex((e) => e.id === N);
|
|
1061
|
+
Q(j[e >= 0 ? (e + 1) % j.length : 0].id);
|
|
886
1062
|
}, [
|
|
887
|
-
k,
|
|
888
1063
|
j,
|
|
1064
|
+
N,
|
|
889
1065
|
Q
|
|
890
|
-
]),
|
|
891
|
-
if (!
|
|
892
|
-
let e =
|
|
893
|
-
Q(
|
|
1066
|
+
]), _e = useCallback(() => {
|
|
1067
|
+
if (!z.current?.activeEditor || j.length === 0) return;
|
|
1068
|
+
let e = j.findIndex((e) => e.id === N);
|
|
1069
|
+
Q(j[e > 0 ? e - 1 : j.length - 1].id);
|
|
894
1070
|
}, [
|
|
895
|
-
k,
|
|
896
1071
|
j,
|
|
1072
|
+
N,
|
|
897
1073
|
Q
|
|
898
|
-
]),
|
|
899
|
-
let { fileName: t = "document", triggerDownload: n = !0 } = e || {}, r = await
|
|
1074
|
+
]), ve = useCallback(async (e) => {
|
|
1075
|
+
let { fileName: t = "document", triggerDownload: n = !0 } = e || {}, r = await z.current?.export({
|
|
900
1076
|
exportType: ["docx"],
|
|
901
1077
|
exportedName: t,
|
|
902
1078
|
triggerDownload: n
|
|
903
|
-
}), i =
|
|
1079
|
+
}), i = z.current?.activeEditor;
|
|
904
1080
|
if (i) {
|
|
905
1081
|
let e = getTemplateFieldsFromEditor(i);
|
|
906
|
-
|
|
1082
|
+
A?.({
|
|
907
1083
|
fields: e,
|
|
908
1084
|
blob: n ? void 0 : r,
|
|
909
1085
|
fileName: t
|
|
910
1086
|
});
|
|
911
1087
|
}
|
|
912
1088
|
return r;
|
|
913
|
-
}, [
|
|
914
|
-
useImperativeHandle(
|
|
1089
|
+
}, [A]);
|
|
1090
|
+
useImperativeHandle(u, () => ({
|
|
915
1091
|
insertField: (e) => Y("inline", e),
|
|
916
1092
|
insertBlockField: (e) => Y("block", e),
|
|
917
1093
|
updateField: X,
|
|
918
1094
|
deleteField: Z,
|
|
919
1095
|
selectField: Q,
|
|
920
|
-
nextField:
|
|
921
|
-
previousField:
|
|
922
|
-
getFields: () =>
|
|
923
|
-
exportTemplate:
|
|
924
|
-
getSuperDoc: () =>
|
|
1096
|
+
nextField: ge,
|
|
1097
|
+
previousField: _e,
|
|
1098
|
+
getFields: () => j,
|
|
1099
|
+
exportTemplate: ve,
|
|
1100
|
+
getSuperDoc: () => z.current
|
|
925
1101
|
}));
|
|
926
|
-
let
|
|
1102
|
+
let ye = m.component || FieldMenu, be = h.component || FieldList;
|
|
927
1103
|
return /* @__PURE__ */ jsxs("div", {
|
|
928
|
-
className: `superdoc-template-builder ${
|
|
929
|
-
style:
|
|
1104
|
+
className: `superdoc-template-builder ${re || ""}`,
|
|
1105
|
+
style: ie,
|
|
930
1106
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
931
1107
|
style: {
|
|
932
1108
|
display: "flex",
|
|
@@ -935,51 +1111,51 @@ var getTemplateFieldsFromEditor = (e) => {
|
|
|
935
1111
|
children: [
|
|
936
1112
|
h.position === "left" && /* @__PURE__ */ jsx("div", {
|
|
937
1113
|
className: "superdoc-template-builder-sidebar",
|
|
938
|
-
children: /* @__PURE__ */ jsx(
|
|
939
|
-
fields:
|
|
1114
|
+
children: /* @__PURE__ */ jsx(be, {
|
|
1115
|
+
fields: j,
|
|
940
1116
|
onSelect: (e) => Q(e.id),
|
|
941
1117
|
onDelete: Z,
|
|
942
1118
|
onUpdate: (e) => X(e.id, e),
|
|
943
|
-
selectedFieldId:
|
|
1119
|
+
selectedFieldId: N || void 0
|
|
944
1120
|
})
|
|
945
1121
|
}),
|
|
946
1122
|
/* @__PURE__ */ jsxs("div", {
|
|
947
1123
|
className: "superdoc-template-builder-document",
|
|
948
1124
|
style: { flex: 1 },
|
|
949
|
-
children: [
|
|
1125
|
+
children: [G?.renderDefaultContainer && /* @__PURE__ */ jsx("div", {
|
|
950
1126
|
id: "superdoc-toolbar",
|
|
951
1127
|
className: "superdoc-template-builder-toolbar",
|
|
952
1128
|
"data-testid": "template-builder-toolbar"
|
|
953
1129
|
}), /* @__PURE__ */ jsx("div", {
|
|
954
|
-
ref:
|
|
1130
|
+
ref: R,
|
|
955
1131
|
className: "superdoc-template-builder-editor",
|
|
956
|
-
style: { height:
|
|
1132
|
+
style: { height: ae },
|
|
957
1133
|
"data-testid": "template-builder-editor"
|
|
958
1134
|
})]
|
|
959
1135
|
}),
|
|
960
1136
|
h.position === "right" && /* @__PURE__ */ jsx("div", {
|
|
961
1137
|
className: "superdoc-template-builder-sidebar",
|
|
962
|
-
children: /* @__PURE__ */ jsx(
|
|
963
|
-
fields:
|
|
1138
|
+
children: /* @__PURE__ */ jsx(be, {
|
|
1139
|
+
fields: j,
|
|
964
1140
|
onSelect: (e) => Q(e.id),
|
|
965
1141
|
onDelete: Z,
|
|
966
1142
|
onUpdate: (e) => X(e.id, e),
|
|
967
|
-
selectedFieldId:
|
|
1143
|
+
selectedFieldId: N || void 0
|
|
968
1144
|
})
|
|
969
1145
|
})
|
|
970
1146
|
]
|
|
971
|
-
}), /* @__PURE__ */ jsx(
|
|
972
|
-
isVisible:
|
|
973
|
-
position:
|
|
974
|
-
availableFields:
|
|
975
|
-
filteredFields:
|
|
976
|
-
filterQuery:
|
|
977
|
-
allowCreate:
|
|
978
|
-
onSelect:
|
|
979
|
-
onClose:
|
|
980
|
-
onCreateField:
|
|
981
|
-
existingFields:
|
|
982
|
-
onSelectExisting:
|
|
1147
|
+
}), /* @__PURE__ */ jsx(ye, {
|
|
1148
|
+
isVisible: F,
|
|
1149
|
+
position: oe,
|
|
1150
|
+
availableFields: f.available || [],
|
|
1151
|
+
filteredFields: le,
|
|
1152
|
+
filterQuery: se,
|
|
1153
|
+
allowCreate: f.allowCreate || !1,
|
|
1154
|
+
onSelect: pe,
|
|
1155
|
+
onClose: he,
|
|
1156
|
+
onCreateField: k,
|
|
1157
|
+
existingFields: j,
|
|
1158
|
+
onSelectExisting: me
|
|
983
1159
|
})]
|
|
984
1160
|
});
|
|
985
1161
|
});
|