@superdoc-dev/esign 1.3.1 → 1.4.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,301 +1,29 @@
1
- import pe, { forwardRef as me, useState as I, useRef as L, useEffect as te, useCallback as M, useImperativeHandle as ge } from "react";
2
- var re = { exports: {} }, W = {};
3
- /**
4
- * @license React
5
- * react-jsx-runtime.production.js
6
- *
7
- * Copyright (c) Meta Platforms, Inc. and affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var ie;
13
- function ve() {
14
- if (ie) return W;
15
- ie = 1;
16
- var g = Symbol.for("react.transitional.element"), v = Symbol.for("react.fragment");
17
- function m(a, n, d) {
18
- var x = null;
19
- if (d !== void 0 && (x = "" + d), n.key !== void 0 && (x = "" + n.key), "key" in n) {
20
- d = {};
21
- for (var S in n)
22
- S !== "key" && (d[S] = n[S]);
23
- } else d = n;
24
- return n = d.ref, {
25
- $$typeof: g,
26
- type: a,
27
- key: x,
28
- ref: n !== void 0 ? n : null,
29
- props: d
30
- };
31
- }
32
- return W.Fragment = v, W.jsx = m, W.jsxs = m, W;
33
- }
34
- var V = {};
35
- /**
36
- * @license React
37
- * react-jsx-runtime.development.js
38
- *
39
- * Copyright (c) Meta Platforms, Inc. and affiliates.
40
- *
41
- * This source code is licensed under the MIT license found in the
42
- * LICENSE file in the root directory of this source tree.
43
- */
44
- var ce;
45
- function be() {
46
- return ce || (ce = 1, process.env.NODE_ENV !== "production" && (function() {
47
- function g(e) {
48
- if (e == null) return null;
49
- if (typeof e == "function")
50
- return e.$$typeof === oe ? null : e.displayName || e.name || null;
51
- if (typeof e == "string") return e;
52
- switch (e) {
53
- case _:
54
- return "Fragment";
55
- case b:
56
- return "Profiler";
57
- case H:
58
- return "StrictMode";
59
- case T:
60
- return "Suspense";
61
- case Z:
62
- return "SuspenseList";
63
- case K:
64
- return "Activity";
65
- }
66
- if (typeof e == "object")
67
- switch (typeof e.tag == "number" && console.error(
68
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
- ), e.$$typeof) {
70
- case ne:
71
- return "Portal";
72
- case A:
73
- return e.displayName || "Context";
74
- case G:
75
- return (e._context.displayName || "Context") + ".Consumer";
76
- case X:
77
- var r = e.render;
78
- return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case Q:
80
- return r = e.displayName || null, r !== null ? r : g(e.type) || "Memo";
81
- case P:
82
- r = e._payload, e = e._init;
83
- try {
84
- return g(e(r));
85
- } catch {
86
- }
87
- }
88
- return null;
89
- }
90
- function v(e) {
91
- return "" + e;
92
- }
93
- function m(e) {
94
- try {
95
- v(e);
96
- var r = !1;
97
- } catch {
98
- r = !0;
99
- }
100
- if (r) {
101
- r = console;
102
- var c = r.error, l = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
- return c.call(
104
- r,
105
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
- l
107
- ), v(e);
108
- }
109
- }
110
- function a(e) {
111
- if (e === _) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === P)
113
- return "<...>";
114
- try {
115
- var r = g(e);
116
- return r ? "<" + r + ">" : "<...>";
117
- } catch {
118
- return "<...>";
119
- }
120
- }
121
- function n() {
122
- var e = w.A;
123
- return e === null ? null : e.getOwner();
124
- }
125
- function d() {
126
- return Error("react-stack-top-frame");
127
- }
128
- function x(e) {
129
- if (y.call(e, "key")) {
130
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
131
- if (r && r.isReactWarning) return !1;
132
- }
133
- return e.key !== void 0;
134
- }
135
- function S(e, r) {
136
- function c() {
137
- k || (k = !0, console.error(
138
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
139
- r
140
- ));
141
- }
142
- c.isReactWarning = !0, Object.defineProperty(e, "key", {
143
- get: c,
144
- configurable: !0
145
- });
146
- }
147
- function z() {
148
- var e = g(this.type);
149
- return N[e] || (N[e] = !0, console.error(
150
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
151
- )), e = this.props.ref, e !== void 0 ? e : null;
152
- }
153
- function B(e, r, c, l, D, q) {
154
- var u = c.ref;
155
- return e = {
156
- $$typeof: J,
157
- type: e,
158
- key: r,
159
- props: c,
160
- _owner: l
161
- }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
162
- enumerable: !1,
163
- get: z
164
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
165
- configurable: !1,
166
- enumerable: !1,
167
- writable: !0,
168
- value: 0
169
- }), Object.defineProperty(e, "_debugInfo", {
170
- configurable: !1,
171
- enumerable: !1,
172
- writable: !0,
173
- value: null
174
- }), Object.defineProperty(e, "_debugStack", {
175
- configurable: !1,
176
- enumerable: !1,
177
- writable: !0,
178
- value: D
179
- }), Object.defineProperty(e, "_debugTask", {
180
- configurable: !1,
181
- enumerable: !1,
182
- writable: !0,
183
- value: q
184
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
185
- }
186
- function Y(e, r, c, l, D, q) {
187
- var u = r.children;
188
- if (u !== void 0)
189
- if (l)
190
- if (ae(u)) {
191
- for (l = 0; l < u.length; l++)
192
- $(u[l]);
193
- Object.freeze && Object.freeze(u);
194
- } else
195
- console.error(
196
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
197
- );
198
- else $(u);
199
- if (y.call(r, "key")) {
200
- u = g(e);
201
- var C = Object.keys(r).filter(function(se) {
202
- return se !== "key";
203
- });
204
- l = 0 < C.length ? "{key: someKey, " + C.join(": ..., ") + ": ...}" : "{key: someKey}", j[u + l] || (C = 0 < C.length ? "{" + C.join(": ..., ") + ": ...}" : "{}", console.error(
205
- `A props object containing a "key" prop is being spread into JSX:
206
- let props = %s;
207
- <%s {...props} />
208
- React keys must be passed directly to JSX without using spread:
209
- let props = %s;
210
- <%s key={someKey} {...props} />`,
211
- l,
212
- u,
213
- C,
214
- u
215
- ), j[u + l] = !0);
216
- }
217
- if (u = null, c !== void 0 && (m(c), u = "" + c), x(r) && (m(r.key), u = "" + r.key), "key" in r) {
218
- c = {};
219
- for (var F in r)
220
- F !== "key" && (c[F] = r[F]);
221
- } else c = r;
222
- return u && S(
223
- c,
224
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
225
- ), B(
226
- e,
227
- u,
228
- c,
229
- n(),
230
- D,
231
- q
232
- );
233
- }
234
- function $(e) {
235
- h(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? h(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
236
- }
237
- function h(e) {
238
- return typeof e == "object" && e !== null && e.$$typeof === J;
239
- }
240
- var O = pe, J = Symbol.for("react.transitional.element"), ne = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), H = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), G = Symbol.for("react.consumer"), A = Symbol.for("react.context"), X = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), Z = Symbol.for("react.suspense_list"), Q = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), K = Symbol.for("react.activity"), oe = Symbol.for("react.client.reference"), w = O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, y = Object.prototype.hasOwnProperty, ae = Array.isArray, E = console.createTask ? console.createTask : function() {
241
- return null;
242
- };
243
- O = {
244
- react_stack_bottom_frame: function(e) {
245
- return e();
246
- }
247
- };
248
- var k, N = {}, ee = O.react_stack_bottom_frame.bind(
249
- O,
250
- d
251
- )(), U = E(a(d)), j = {};
252
- V.Fragment = _, V.jsx = function(e, r, c) {
253
- var l = 1e4 > w.recentlyCreatedOwnerStacks++;
254
- return Y(
255
- e,
256
- r,
257
- c,
258
- !1,
259
- l ? Error("react-stack-top-frame") : ee,
260
- l ? E(a(e)) : U
261
- );
262
- }, V.jsxs = function(e, r, c) {
263
- var l = 1e4 > w.recentlyCreatedOwnerStacks++;
264
- return Y(
265
- e,
266
- r,
267
- c,
268
- !0,
269
- l ? Error("react-stack-top-frame") : ee,
270
- l ? E(a(e)) : U
271
- );
272
- };
273
- })()), V;
274
- }
275
- var le;
276
- function xe() {
277
- return le || (le = 1, process.env.NODE_ENV === "production" ? re.exports = ve() : re.exports = be()), re.exports;
278
- }
279
- var p = xe();
280
- const he = ({
281
- value: g,
282
- onChange: v,
283
- isDisabled: m,
284
- label: a
285
- }) => /* @__PURE__ */ p.jsxs(
1
+ import { jsxs as b, jsx as d } from "react/jsx-runtime";
2
+ import { forwardRef as ae, useState as y, useRef as D, useEffect as k, useCallback as M, useImperativeHandle as ce } from "react";
3
+ const le = (u) => {
4
+ const l = globalThis.document.createElement("canvas"), r = l.getContext("2d"), n = 30;
5
+ r.font = `italic ${n}px cursive`;
6
+ const i = r.measureText(u).width, m = n * 1.3, p = 4, T = 6;
7
+ return l.width = Math.ceil(i + p * 2) + 20, l.height = Math.ceil(m + T * 2), r.font = `italic ${n}px cursive`, r.fillStyle = "black", r.textAlign = "center", r.textBaseline = "middle", r.fillText(u, l.width / 2, l.height / 2), l.toDataURL("image/png");
8
+ }, de = ({
9
+ value: u,
10
+ onChange: l,
11
+ isDisabled: r,
12
+ label: n
13
+ }) => /* @__PURE__ */ b(
286
14
  "div",
287
15
  {
288
16
  className: "superdoc-esign-signature-input",
289
17
  style: { display: "flex", flexDirection: "column", gap: "8px" },
290
18
  children: [
291
- a && /* @__PURE__ */ p.jsx("label", { children: a }),
292
- /* @__PURE__ */ p.jsx(
19
+ n && /* @__PURE__ */ d("label", { children: n }),
20
+ /* @__PURE__ */ d(
293
21
  "input",
294
22
  {
295
23
  type: "text",
296
- value: String(g || ""),
297
- onChange: (n) => v(n.target.value),
298
- disabled: m,
24
+ value: String(u || ""),
25
+ onChange: (s) => l(s.target.value),
26
+ disabled: r,
299
27
  placeholder: "Type your full name",
300
28
  style: {
301
29
  fontFamily: "cursive",
@@ -305,412 +33,375 @@ const he = ({
305
33
  )
306
34
  ]
307
35
  }
308
- ), ye = ({
309
- value: g,
310
- onChange: v,
311
- isDisabled: m,
312
- label: a
313
- }) => /* @__PURE__ */ p.jsxs(
314
- "label",
315
- {
316
- className: "superdoc-esign-checkbox-input",
317
- style: { display: "flex", gap: "8px" },
318
- children: [
319
- /* @__PURE__ */ p.jsx(
320
- "input",
321
- {
322
- type: "checkbox",
323
- checked: !!g,
324
- onChange: (n) => v(n.target.checked),
325
- disabled: m
326
- }
327
- ),
328
- /* @__PURE__ */ p.jsx("span", { children: a })
329
- ]
330
- }
331
- ), Ee = (g) => ({
332
- onClick: m,
333
- fileName: a,
334
- isDisabled: n
36
+ ), ue = ({
37
+ value: u,
38
+ onChange: l,
39
+ isDisabled: r,
40
+ label: n
41
+ }) => /* @__PURE__ */ b("label", { className: "superdoc-esign-checkbox-input", style: { display: "flex", gap: "8px" }, children: [
42
+ /* @__PURE__ */ d(
43
+ "input",
44
+ {
45
+ type: "checkbox",
46
+ checked: !!u,
47
+ onChange: (s) => l(s.target.checked),
48
+ disabled: r
49
+ }
50
+ ),
51
+ /* @__PURE__ */ d("span", { children: n })
52
+ ] }), pe = (u) => ({
53
+ onClick: r,
54
+ fileName: n,
55
+ isDisabled: s,
56
+ isDownloading: i
335
57
  }) => {
336
- const d = g?.label || "Download";
337
- return /* @__PURE__ */ p.jsxs(
58
+ const m = u?.label || "Download", p = s || i;
59
+ return /* @__PURE__ */ b(
338
60
  "button",
339
61
  {
340
- onClick: m,
341
- disabled: n,
342
- className: "superdoc-esign-btn superdoc-esign-btn--download",
62
+ onClick: r,
63
+ disabled: p,
64
+ className: `superdoc-esign-btn superdoc-esign-btn--download${i ? " superdoc-esign-btn--loading" : ""}`,
343
65
  style: {
344
66
  padding: "8px 16px",
345
67
  borderRadius: "6px",
346
68
  border: "1px solid #d0d5dd",
347
69
  background: "#ffffff",
348
70
  color: "#333",
349
- cursor: n ? "not-allowed" : "pointer",
350
- opacity: n ? 0.5 : 1,
71
+ cursor: p ? "not-allowed" : "pointer",
72
+ opacity: p ? 0.7 : 1,
351
73
  fontSize: "16px",
352
- fontWeight: "bold"
74
+ fontWeight: "bold",
75
+ display: "inline-flex",
76
+ alignItems: "center",
77
+ gap: "8px",
78
+ transition: "opacity 0.2s ease"
353
79
  },
354
80
  children: [
355
- d,
356
- " ",
357
- a && `(${a})`
81
+ i && /* @__PURE__ */ d("span", { className: "superdoc-esign-spinner" }),
82
+ i ? "Downloading..." : m,
83
+ !i && n && ` (${n})`
358
84
  ]
359
85
  }
360
86
  );
361
- }, _e = (g) => ({
362
- onClick: m,
363
- isValid: a,
364
- isDisabled: n,
365
- isSubmitting: d
87
+ }, ge = (u) => ({
88
+ onClick: r,
89
+ isValid: n,
90
+ isDisabled: s,
91
+ isSubmitting: i
366
92
  }) => {
367
- const x = () => g?.label || "Submit";
368
- return /* @__PURE__ */ p.jsx(
93
+ const m = u?.label || "Submit", p = !n || s || i;
94
+ return /* @__PURE__ */ b(
369
95
  "button",
370
96
  {
371
- onClick: m,
372
- disabled: !a || n || d,
373
- className: "superdoc-esign-btn superdoc-esign-btn--submit",
97
+ onClick: r,
98
+ disabled: p,
99
+ className: `superdoc-esign-btn superdoc-esign-btn--submit${i ? " superdoc-esign-btn--loading" : ""}`,
374
100
  style: {
375
101
  padding: "12px 24px",
376
102
  borderRadius: "6px",
377
103
  border: "none",
378
104
  background: "#007bff",
379
105
  color: "#fff",
380
- cursor: !a || n ? "not-allowed" : "pointer",
381
- opacity: !a || n ? 0.5 : 1,
106
+ cursor: p ? "not-allowed" : "pointer",
107
+ opacity: p && !i ? 0.5 : 1,
382
108
  fontSize: "16px",
383
- fontWeight: "bold"
109
+ fontWeight: "bold",
110
+ display: "inline-flex",
111
+ alignItems: "center",
112
+ gap: "8px",
113
+ transition: "opacity 0.2s ease"
384
114
  },
385
- children: x()
115
+ children: [
116
+ i && /* @__PURE__ */ d("span", { className: "superdoc-esign-spinner superdoc-esign-spinner--light" }),
117
+ i ? "Submitting..." : m
118
+ ]
386
119
  }
387
120
  );
388
- }, Re = me((g, v) => {
389
- const {
390
- eventId: m,
391
- document: a,
392
- fields: n = {},
393
- download: d,
394
- submit: x,
395
- onSubmit: S,
396
- onDownload: z,
397
- onStateChange: B,
398
- onFieldChange: Y,
399
- onFieldsDiscovered: $,
400
- isDisabled: h = !1,
401
- className: O,
402
- style: J,
403
- documentHeight: ne = "600px"
404
- } = g, [_, H] = I(
405
- !a.validation?.scroll?.required
406
- ), [b, G] = I(
407
- /* @__PURE__ */ new Map()
408
- ), [A, X] = I(!1), [T, Z] = I(!1), [Q, P] = I([]), [K, oe] = I(!1), w = L(null), y = L(null), ae = L(Date.now()), E = L(n), k = L([]);
409
- E.current = n, te(() => {
410
- k.current = Q;
411
- }, [Q]);
412
- const N = M((t) => {
413
- if (!y.current?.activeEditor) return;
414
- const o = y.current.activeEditor, s = E.current.signer?.find(
415
- (i) => i.id === t.id
416
- );
417
- let f;
418
- s?.type === "signature" && t.value ? f = {
419
- json: {
420
- type: "image",
421
- attrs: { src: typeof t.value == "string" && t.value.startsWith("data:image/") ? t.value : ee(String(t.value)), alt: "Signature" }
422
- }
423
- } : f = { text: String(t.value ?? "") }, t.id && o.commands.updateStructuredContentById(t.id, f);
424
- }, []);
425
- function ee(t) {
426
- const o = globalThis.document.createElement("canvas"), s = o.getContext("2d"), f = 30;
427
- s.font = `italic ${f}px cursive`;
428
- const R = s.measureText(t).width, ue = f * 1.3, de = 4, fe = 6;
429
- return o.width = Math.ceil(R + de * 2) + 20, o.height = Math.ceil(ue + fe * 2), s.font = `italic ${f}px cursive`, s.fillStyle = "black", s.textAlign = "center", s.textBaseline = "middle", s.fillText(t, o.width / 2, o.height / 2), o.toDataURL("image/png");
430
- }
431
- const U = M(
432
- (t) => {
433
- if (!t) return;
434
- const o = t.helpers.structuredContentCommands.getStructuredContentTags(
435
- t.state
436
- ), s = /* @__PURE__ */ new Map();
437
- E.current.document?.forEach((i) => {
438
- i.id && s.set(i.id, i.value);
439
- }), E.current.signer?.forEach((i) => {
440
- i.value !== void 0 && s.set(i.id, i.value);
441
- });
442
- const f = o.map(({ node: i }) => ({
443
- id: i.attrs.id,
444
- label: i.attrs.label,
445
- value: s.get(i.attrs.id) ?? i.textContent ?? ""
446
- })).filter((i) => i.id);
447
- f.length > 0 && ($?.(f), [
448
- ...E.current.document || [],
449
- ...E.current.signer || []
450
- ].filter((R) => R.value !== void 0).forEach(
451
- (R) => N({
452
- id: R.id,
453
- value: R.value
454
- })
455
- ));
456
- },
457
- [$, N]
458
- ), j = (t) => {
459
- const o = {
460
- ...t,
461
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
462
- }, s = globalThis?.__SUPERDOC_AUDIT_MOCK__;
463
- s && s(o);
464
- const f = [...k.current, o];
465
- return k.current = f, P(f), f;
466
- };
467
- te(() => w.current ? ((async () => {
468
- const { SuperDoc: o } = await import("superdoc"), s = new o({
469
- selector: w.current,
470
- document: a.source,
471
- documentMode: "viewing",
472
- onReady: () => {
473
- s.activeEditor && U(s.activeEditor), j({ type: "ready" }), oe(!0);
474
- }
475
- });
476
- y.current = s;
477
- })(), () => {
478
- y.current && (typeof y.current.destroy == "function" && y.current.destroy(), y.current = null);
479
- }) : void 0, [a.source, a.mode, U]), te(() => {
480
- if (!a.validation?.scroll?.required || !K) return;
481
- const t = w.current;
482
- if (!t) return;
483
- const o = () => {
484
- const { scrollTop: s, scrollHeight: f, clientHeight: i } = t, R = s / (f - i);
485
- (R >= 0.95 || f <= i) && (H(!0), j({
486
- type: "scroll",
487
- data: { percent: Math.round(R * 100) }
488
- }));
489
- };
490
- return t.addEventListener("scroll", o), o(), () => t.removeEventListener("scroll", o);
491
- }, [a.validation?.scroll?.required, K]);
492
- const e = M(
493
- (t, o) => {
494
- G((s) => {
495
- const f = s.get(t), i = new Map(s);
496
- return i.set(t, o), N({
497
- id: t,
498
- value: o
499
- }), j({
500
- type: "field_change",
501
- data: { fieldId: t, value: o, previousValue: f }
502
- }), Y?.({
503
- id: t,
504
- value: o,
505
- previousValue: f
506
- }), i;
507
- });
508
- },
509
- [Y, N]
510
- ), r = M(() => a.validation?.scroll?.required && !_ ? !1 : (n.signer || []).every((t) => {
511
- if (!t.validation?.required) return !0;
512
- const o = b.get(t.id);
513
- return o && (typeof o != "string" || o.trim());
514
- }), [
515
- _,
516
- n.signer,
517
- b,
518
- a.validation?.scroll?.required
519
- ]);
520
- te(() => {
521
- const t = r();
522
- X(t), B?.({
523
- scrolled: _,
524
- fields: b,
525
- isValid: t,
526
- isSubmitting: T
527
- });
528
- }, [_, b, T, r, B]);
529
- const c = M(async () => {
530
- if (h) return;
531
- const t = {
532
- eventId: m,
533
- documentSource: a.source,
534
- fields: {
535
- document: n.document || [],
536
- signer: (n.signer || []).map((o) => ({
537
- id: o.id,
538
- value: b.get(o.id) ?? null
539
- }))
121
+ }, me = ae(
122
+ (u, l) => {
123
+ const {
124
+ eventId: r,
125
+ document: n,
126
+ fields: s = {},
127
+ download: i,
128
+ submit: m,
129
+ onSubmit: p,
130
+ onDownload: T,
131
+ onStateChange: A,
132
+ onFieldChange: q,
133
+ onFieldsDiscovered: V,
134
+ isDisabled: f = !1,
135
+ className: X,
136
+ style: Y,
137
+ documentHeight: G = "600px"
138
+ } = u, [x, B] = y(!n.validation?.scroll?.required), [g, _] = y(/* @__PURE__ */ new Map()), [S, U] = y(!1), [h, $] = y(!1), [I, H] = y(!1), [z, O] = y([]), [W, J] = y(!1), E = D(null), F = D(null), Q = D(Date.now()), w = D(s), N = D([]), j = D(V);
139
+ w.current = s, j.current = V, k(() => {
140
+ N.current = z;
141
+ }, [z]);
142
+ const C = M((e) => {
143
+ if (!F.current?.activeEditor) return;
144
+ const t = F.current.activeEditor, a = w.current.signer?.find((o) => o.id === e.id);
145
+ let c;
146
+ a?.type === "signature" && e.value ? c = {
147
+ json: {
148
+ type: "image",
149
+ attrs: { src: typeof e.value == "string" && e.value.startsWith("data:image/") ? e.value : le(String(e.value)), alt: "Signature" }
150
+ }
151
+ } : c = { text: String(e.value ?? "") }, e.id && t.commands.updateStructuredContentById?.(e.id, c);
152
+ }, []), L = M(
153
+ (e) => {
154
+ if (!e) return;
155
+ const t = e.helpers.structuredContentCommands.getStructuredContentTags(
156
+ e.state
157
+ ), a = /* @__PURE__ */ new Map();
158
+ w.current.document?.forEach((o) => {
159
+ o.id && a.set(o.id, o.value);
160
+ }), w.current.signer?.forEach((o) => {
161
+ o.value !== void 0 && a.set(o.id, o.value);
162
+ });
163
+ const c = t.map(({ node: o }) => ({
164
+ id: o.attrs.id,
165
+ label: o.attrs.label,
166
+ value: a.get(o.attrs.id) ?? o.textContent ?? ""
167
+ })).filter((o) => o.id);
168
+ c.length > 0 && (j.current?.(c), [
169
+ ...w.current.document || [],
170
+ ...w.current.signer || []
171
+ ].filter((v) => v.value !== void 0).forEach(
172
+ (v) => C({
173
+ id: v.id,
174
+ value: v.value
175
+ })
176
+ ));
540
177
  },
541
- fileName: d?.fileName || "document.pdf"
542
- };
543
- await z?.(t);
544
- }, [
545
- h,
546
- m,
547
- a.source,
548
- n,
549
- b,
550
- d,
551
- z
552
- ]), l = M(async () => {
553
- if (!A || h || T) return;
554
- Z(!0), j({ type: "submit" });
555
- const t = j({ type: "submit" }), o = {
556
- eventId: m,
557
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
558
- duration: Math.floor((Date.now() - ae.current) / 1e3),
559
- auditTrail: t,
560
- documentFields: n.document || [],
561
- signerFields: (n.signer || []).map((s) => ({
562
- id: s.id,
563
- value: b.get(s.id) ?? null
564
- })),
565
- isFullyCompleted: A
178
+ [C]
179
+ ), R = (e) => {
180
+ const t = {
181
+ ...e,
182
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
183
+ }, a = globalThis?.__SUPERDOC_AUDIT_MOCK__;
184
+ a && a(t);
185
+ const c = [...N.current, t];
186
+ return N.current = c, O(c), c;
566
187
  };
567
- try {
568
- await S(o);
569
- } finally {
570
- Z(!1);
571
- }
572
- }, [
573
- A,
574
- h,
575
- T,
576
- m,
577
- n,
578
- b,
579
- S
580
- ]), D = (t) => {
581
- const o = t.component || q(t.type);
582
- return /* @__PURE__ */ p.jsx(
583
- o,
584
- {
585
- value: b.get(t.id) ?? null,
586
- onChange: (s) => e(t.id, s),
587
- isDisabled: h,
588
- label: t.label
188
+ k(() => {
189
+ if (!E.current) return;
190
+ let e = !1, t = null;
191
+ return (async () => {
192
+ const { SuperDoc: c } = await import("superdoc");
193
+ e || (t = new c({
194
+ selector: E.current,
195
+ document: n.source,
196
+ documentMode: "viewing",
197
+ modules: {
198
+ comments: !1
199
+ },
200
+ // @ts-expect-error - layoutMode is not supported in SuperDoc v1.1.0 yet
201
+ layoutMode: n.layoutMode,
202
+ layoutMargins: n.layoutMargins,
203
+ onReady: () => {
204
+ e || (t?.activeEditor && L(t.activeEditor), R({ type: "ready" }), J(!0));
205
+ }
206
+ }), F.current = t);
207
+ })(), () => {
208
+ e = !0, t && typeof t.destroy == "function" && t.destroy(), F.current = null;
209
+ };
210
+ }, [
211
+ n.source,
212
+ n.mode,
213
+ n.layoutMode,
214
+ n.layoutMargins?.top,
215
+ n.layoutMargins?.bottom,
216
+ n.layoutMargins?.left,
217
+ n.layoutMargins?.right,
218
+ L
219
+ ]), k(() => {
220
+ if (!n.validation?.scroll?.required || !W) return;
221
+ const e = E.current;
222
+ if (!e) return;
223
+ const t = () => {
224
+ const { scrollTop: a, scrollHeight: c, clientHeight: o } = e, v = a / (c - o);
225
+ (v >= 0.95 || c <= o) && (B(!0), R({
226
+ type: "scroll",
227
+ data: { percent: Math.round(v * 100) }
228
+ }));
229
+ };
230
+ return e.addEventListener("scroll", t), t(), () => e.removeEventListener("scroll", t);
231
+ }, [n.validation?.scroll?.required, W]);
232
+ const Z = M(
233
+ (e, t) => {
234
+ _((a) => {
235
+ const c = a.get(e), o = new Map(a);
236
+ return o.set(e, t), C({
237
+ id: e,
238
+ value: t
239
+ }), R({
240
+ type: "field_change",
241
+ data: { fieldId: e, value: t, previousValue: c }
242
+ }), q?.({
243
+ id: e,
244
+ value: t,
245
+ previousValue: c
246
+ }), o;
247
+ });
589
248
  },
590
- t.id
591
- );
592
- }, q = (t) => {
593
- switch (t) {
594
- case "signature":
595
- case "text":
596
- return he;
597
- case "checkbox":
598
- return ye;
599
- }
600
- }, u = () => {
601
- const t = d?.component || Ee(d);
602
- return t ? /* @__PURE__ */ p.jsx(
603
- t,
604
- {
605
- onClick: c,
606
- fileName: d?.fileName,
607
- isDisabled: h
249
+ [q, C]
250
+ ), P = M(() => n.validation?.scroll?.required && !x ? !1 : (s.signer || []).every((e) => {
251
+ if (!e.validation?.required) return !0;
252
+ const t = g.get(e.id);
253
+ return t && (typeof t != "string" || t.trim());
254
+ }), [x, s.signer, g, n.validation?.scroll?.required]);
255
+ k(() => {
256
+ const e = P();
257
+ U(e), A?.({
258
+ scrolled: x,
259
+ fields: g,
260
+ isValid: e,
261
+ isSubmitting: h
262
+ });
263
+ }, [x, g, h, P, A]);
264
+ const ee = M(async () => {
265
+ if (f || I) return;
266
+ H(!0);
267
+ const e = {
268
+ eventId: r,
269
+ documentSource: n.source,
270
+ fields: {
271
+ document: s.document || [],
272
+ signer: (s.signer || []).map((t) => ({
273
+ id: t.id,
274
+ value: g.get(t.id) ?? null
275
+ }))
276
+ },
277
+ fileName: i?.fileName || "document.pdf"
278
+ };
279
+ try {
280
+ await T?.(e);
281
+ } finally {
282
+ H(!1);
608
283
  }
609
- ) : null;
610
- }, C = () => {
611
- if (a.mode === "download")
612
- return null;
613
- const t = x?.component || _e(x);
614
- return /* @__PURE__ */ p.jsx(
615
- "div",
616
- {
617
- className: "superdoc-esign-actions superdoc-esign-form-actions",
618
- style: { display: "flex", gap: "10px" },
619
- children: /* @__PURE__ */ p.jsx(
620
- t,
621
- {
622
- onClick: l,
623
- isValid: A,
624
- isDisabled: h,
625
- isSubmitting: T
626
- }
627
- )
284
+ }, [
285
+ f,
286
+ I,
287
+ r,
288
+ n.source,
289
+ s,
290
+ g,
291
+ i,
292
+ T
293
+ ]), te = M(async () => {
294
+ if (!S || f || h) return;
295
+ $(!0);
296
+ const e = R({ type: "submit" }), t = {
297
+ eventId: r,
298
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
299
+ duration: Math.floor((Date.now() - Q.current) / 1e3),
300
+ auditTrail: e,
301
+ documentFields: s.document || [],
302
+ signerFields: (s.signer || []).map((a) => ({
303
+ id: a.id,
304
+ value: g.get(a.id) ?? null
305
+ })),
306
+ isFullyCompleted: S
307
+ };
308
+ try {
309
+ await p(t);
310
+ } finally {
311
+ $(!1);
628
312
  }
629
- );
630
- }, F = u(), se = C();
631
- return ge(v, () => ({
632
- getState: () => ({
633
- scrolled: _,
634
- fields: b,
635
- isValid: A,
636
- isSubmitting: T
637
- }),
638
- getAuditTrail: () => k.current,
639
- reset: () => {
640
- H(!a.validation?.scroll?.required), G(/* @__PURE__ */ new Map()), X(!1), k.current = [], P([]);
641
- }
642
- })), /* @__PURE__ */ p.jsxs(
643
- "div",
644
- {
645
- className: `superdoc-esign-container ${O || ""}`,
646
- style: J,
647
- children: [
648
- /* @__PURE__ */ p.jsxs(
649
- "div",
650
- {
651
- className: "superdoc-esign-document",
652
- "data-testid": "superdoc-esign-document",
653
- style: { display: "flex", flexDirection: "column" },
654
- children: [
655
- F && /* @__PURE__ */ p.jsx(
656
- "div",
657
- {
658
- className: "superdoc-esign-document-toolbar",
659
- style: {
660
- display: "flex",
661
- justifyContent: "flex-end",
662
- alignItems: "center",
663
- padding: "8px 12px"
664
- },
665
- children: /* @__PURE__ */ p.jsx(
666
- "div",
667
- {
668
- className: "superdoc-esign-document-controls",
669
- style: { display: "flex", gap: "8px" },
670
- children: F
671
- }
672
- )
673
- }
674
- ),
675
- /* @__PURE__ */ p.jsx(
676
- "div",
677
- {
678
- ref: w,
679
- className: "superdoc-esign-document-viewer",
680
- "data-testid": "superdoc-scroll-container",
681
- style: { height: ne, overflow: "auto" }
682
- }
683
- )
684
- ]
685
- }
686
- ),
687
- /* @__PURE__ */ p.jsxs(
313
+ }, [S, f, h, r, s, g, p]), ne = (e) => {
314
+ const t = e.component || oe(e.type);
315
+ return /* @__PURE__ */ d(
316
+ t,
317
+ {
318
+ value: g.get(e.id) ?? null,
319
+ onChange: (a) => Z(e.id, a),
320
+ isDisabled: f,
321
+ label: e.label
322
+ },
323
+ e.id
324
+ );
325
+ }, oe = (e) => {
326
+ switch (e) {
327
+ case "signature":
328
+ case "text":
329
+ return de;
330
+ case "checkbox":
331
+ return ue;
332
+ }
333
+ }, se = () => {
334
+ const e = i?.component || pe(i);
335
+ return e ? /* @__PURE__ */ d(
336
+ e,
337
+ {
338
+ onClick: ee,
339
+ fileName: i?.fileName,
340
+ isDisabled: f,
341
+ isDownloading: I
342
+ }
343
+ ) : null;
344
+ }, re = () => {
345
+ if (n.mode === "download")
346
+ return null;
347
+ const e = m?.component || ge(m);
348
+ return /* @__PURE__ */ d("div", { className: "superdoc-esign-actions superdoc-esign-form-actions", children: /* @__PURE__ */ d(
349
+ e,
350
+ {
351
+ onClick: te,
352
+ isValid: S,
353
+ isDisabled: f,
354
+ isSubmitting: h
355
+ }
356
+ ) });
357
+ }, K = se(), ie = re();
358
+ return ce(
359
+ l,
360
+ () => ({
361
+ getState: () => ({
362
+ scrolled: x,
363
+ fields: g,
364
+ isValid: S,
365
+ isSubmitting: h
366
+ }),
367
+ getAuditTrail: () => N.current,
368
+ reset: () => {
369
+ B(!n.validation?.scroll?.required), _(/* @__PURE__ */ new Map()), U(!1), N.current = [], O([]);
370
+ },
371
+ updateFieldInDocument: C
372
+ }),
373
+ [
374
+ x,
375
+ g,
376
+ S,
377
+ h,
378
+ n.validation?.scroll?.required,
379
+ C
380
+ ]
381
+ ), /* @__PURE__ */ b("div", { className: `superdoc-esign-container ${X || ""}`, style: Y, children: [
382
+ /* @__PURE__ */ b("div", { className: "superdoc-esign-document", "data-testid": "superdoc-esign-document", children: [
383
+ K && /* @__PURE__ */ d("div", { className: "superdoc-esign-document-toolbar", children: /* @__PURE__ */ d("div", { className: "superdoc-esign-document-controls", children: K }) }),
384
+ /* @__PURE__ */ d(
688
385
  "div",
689
386
  {
690
- className: "superdoc-esign-controls",
691
- style: { marginTop: "20px" },
692
- "data-testid": "superdoc-esign-controls",
693
- children: [
694
- n.signer && n.signer.length > 0 && /* @__PURE__ */ p.jsx(
695
- "div",
696
- {
697
- className: "superdoc-esign-fields",
698
- style: { marginBottom: "20px" },
699
- "data-testid": "superdoc-esign-fields",
700
- children: n.signer.map(D)
701
- }
702
- ),
703
- se
704
- ]
387
+ ref: E,
388
+ className: "superdoc-esign-document-viewer",
389
+ "data-testid": "superdoc-scroll-container",
390
+ style: { height: G, overflow: "auto" }
705
391
  }
706
392
  )
707
- ]
708
- }
709
- );
710
- });
711
- Re.displayName = "SuperDocESign";
393
+ ] }),
394
+ /* @__PURE__ */ b("div", { className: "superdoc-esign-controls", "data-testid": "superdoc-esign-controls", children: [
395
+ s.signer && s.signer.length > 0 && /* @__PURE__ */ d("div", { className: "superdoc-esign-fields", "data-testid": "superdoc-esign-fields", children: s.signer.map(ne) }),
396
+ ie
397
+ ] })
398
+ ] });
399
+ }
400
+ );
401
+ me.displayName = "SuperDocESign";
712
402
  export {
713
- ye as CheckboxInput,
714
- he as SignatureInput,
715
- Re as default
403
+ ue as CheckboxInput,
404
+ de as SignatureInput,
405
+ me as default,
406
+ le as textToImageDataUrl
716
407
  };