@superdoc-dev/esign 1.4.0-next.3 → 1.4.0-next.4
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/__tests__/signature.test.d.ts +2 -0
- package/dist/__tests__/signature.test.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +163 -163
- package/dist/utils/signature.d.ts +2 -0
- package/dist/utils/signature.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/signature.test.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { textToImageDataUrl } from './utils/signature';
|
|
1
2
|
import { SignatureInput, CheckboxInput } from './defaults';
|
|
2
3
|
import type * as Types from './types';
|
|
3
4
|
export * from './types';
|
|
5
|
+
export { textToImageDataUrl };
|
|
4
6
|
export { SignatureInput, CheckboxInput };
|
|
5
7
|
declare const SuperDocESign: import('react').ForwardRefExoticComponent<Types.SuperDocESignProps & import('react').RefAttributes<Types.SuperDocESignHandle>>;
|
|
6
8
|
export default SuperDocESign;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AACtC,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,gIAuclB,CAAC;AAIF,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ce=Object.create;var P=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var ge=(i,c,o,t)=>{if(c&&typeof c=="object"||typeof c=="function")for(let s of ue(c))!pe.call(i,s)&&s!==o&&P(i,s,{get:()=>c[s],enumerable:!(t=le(c,s))||t.enumerable});return i};var me=(i,c,o)=>(o=i!=null?ce(de(i)):{},ge(c||!i||!i.__esModule?P(o,"default",{value:i,enumerable:!0}):o,i));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),r=require("react"),W=i=>{const c=globalThis.document.createElement("canvas"),o=c.getContext("2d"),t=30;o.font=`italic ${t}px cursive`;const u=o.measureText(i).width,f=t*1.3,g=4,j=6;return c.width=Math.ceil(u+g*2)+20,c.height=Math.ceil(f+j*2),o.font=`italic ${t}px cursive`,o.fillStyle="black",o.textAlign="center",o.textBaseline="middle",o.fillText(i,c.width/2,c.height/2),c.toDataURL("image/png")},L=({value:i,onChange:c,isDisabled:o,label:t})=>l.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t&&l.jsx("label",{children:t}),l.jsx("input",{type:"text",value:String(i||""),onChange:s=>c(s.target.value),disabled:o,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),K=({value:i,onChange:c,isDisabled:o,label:t})=>l.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[l.jsx("input",{type:"checkbox",checked:!!i,onChange:s=>c(s.target.checked),disabled:o}),l.jsx("span",{children:t})]}),fe=i=>({onClick:o,fileName:t,isDisabled:s,isDownloading:u})=>{const f=i?.label||"Download",g=s||u;return l.jsxs("button",{onClick:o,disabled:g,className:`superdoc-esign-btn superdoc-esign-btn--download${u?" superdoc-esign-btn--loading":""}`,style:{padding:"8px 16px",borderRadius:"6px",border:"1px solid #d0d5dd",background:"#ffffff",color:"#333",cursor:g?"not-allowed":"pointer",opacity:g?.7:1,fontSize:"16px",fontWeight:"bold",display:"inline-flex",alignItems:"center",gap:"8px",transition:"opacity 0.2s ease"},children:[u&&l.jsx("span",{className:"superdoc-esign-spinner"}),u?"Downloading...":f,!u&&t&&` (${t})`]})},he=i=>({onClick:o,isValid:t,isDisabled:s,isSubmitting:u})=>{const f=i?.label||"Submit",g=!t||s||u;return l.jsxs("button",{onClick:o,disabled:g,className:`superdoc-esign-btn superdoc-esign-btn--submit${u?" superdoc-esign-btn--loading":""}`,style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:g?"not-allowed":"pointer",opacity:g&&!u?.5:1,fontSize:"16px",fontWeight:"bold",display:"inline-flex",alignItems:"center",gap:"8px",transition:"opacity 0.2s ease"},children:[u&&l.jsx("span",{className:"superdoc-esign-spinner superdoc-esign-spinner--light"}),u?"Submitting...":f]})},X=r.forwardRef((i,c)=>{const{eventId:o,document:t,fields:s={},download:u,submit:f,onSubmit:g,onDownload:j,onStateChange:E,onFieldChange:N,onFieldsDiscovered:T,isDisabled:h=!1,className:Y,style:G,documentHeight:J="600px"}=i,[y,F]=r.useState(!t.validation?.scroll?.required),[m,I]=r.useState(new Map),[b,q]=r.useState(!1),[x,A]=r.useState(!1),[k,_]=r.useState(!1),[V,B]=r.useState([]),[U,Q]=r.useState(!1),M=r.useRef(null),R=r.useRef(null),Z=r.useRef(Date.now()),S=r.useRef(s),w=r.useRef([]),$=r.useRef(T);S.current=s,$.current=T,r.useEffect(()=>{w.current=V},[V]);const C=r.useCallback(e=>{if(!R.current?.activeEditor)return;const n=R.current.activeEditor,d=S.current.signer?.find(a=>a.id===e.id);let p;d?.type==="signature"&&e.value?p={json:{type:"image",attrs:{src:typeof e.value=="string"&&e.value.startsWith("data:image/")?e.value:W(String(e.value)),alt:"Signature"}}}:p={text:String(e.value??"")},e.id&&n.commands.updateStructuredContentById(e.id,p)},[]),H=r.useCallback(e=>{if(!e)return;const n=e.helpers.structuredContentCommands.getStructuredContentTags(e.state),d=new Map;S.current.document?.forEach(a=>{a.id&&d.set(a.id,a.value)}),S.current.signer?.forEach(a=>{a.value!==void 0&&d.set(a.id,a.value)});const p=n.map(({node:a})=>({id:a.attrs.id,label:a.attrs.label,value:d.get(a.attrs.id)??a.textContent??""})).filter(a=>a.id);p.length>0&&($.current?.(p),[...S.current.document||[],...S.current.signer||[]].filter(v=>v.value!==void 0).forEach(v=>C({id:v.id,value:v.value})))},[C]),D=e=>{const n={...e,timestamp:new Date().toISOString()},d=globalThis?.__SUPERDOC_AUDIT_MOCK__;d&&d(n);const p=[...w.current,n];return w.current=p,B(p),p};r.useEffect(()=>{if(!M.current)return;let e=!1,n=null;return(async()=>{const{SuperDoc:p}=await import("superdoc");e||(n=new p({selector:M.current,document:t.source,documentMode:"viewing",modules:{comments:!1},layoutMode:t.layoutMode,layoutMargins:t.layoutMargins,onReady:()=>{e||(n?.activeEditor&&H(n.activeEditor),D({type:"ready"}),Q(!0))}}),R.current=n)})(),()=>{e=!0,n&&typeof n.destroy=="function"&&n.destroy(),R.current=null}},[t.source,t.mode,t.layoutMode,t.layoutMargins?.top,t.layoutMargins?.bottom,t.layoutMargins?.left,t.layoutMargins?.right,H]),r.useEffect(()=>{if(!t.validation?.scroll?.required||!U)return;const e=M.current;if(!e)return;const n=()=>{const{scrollTop:d,scrollHeight:p,clientHeight:a}=e,v=d/(p-a);(v>=.95||p<=a)&&(F(!0),D({type:"scroll",data:{percent:Math.round(v*100)}}))};return e.addEventListener("scroll",n),n(),()=>e.removeEventListener("scroll",n)},[t.validation?.scroll?.required,U]);const ee=r.useCallback((e,n)=>{I(d=>{const p=d.get(e),a=new Map(d);return a.set(e,n),C({id:e,value:n}),D({type:"field_change",data:{fieldId:e,value:n,previousValue:p}}),N?.({id:e,value:n,previousValue:p}),a})},[N,C]),O=r.useCallback(()=>t.validation?.scroll?.required&&!y?!1:(s.signer||[]).every(e=>{if(!e.validation?.required)return!0;const n=m.get(e.id);return n&&(typeof n!="string"||n.trim())}),[y,s.signer,m,t.validation?.scroll?.required]);r.useEffect(()=>{const e=O();q(e),E?.({scrolled:y,fields:m,isValid:e,isSubmitting:x})},[y,m,x,O,E]);const te=r.useCallback(async()=>{if(h||k)return;_(!0);const e={eventId:o,documentSource:t.source,fields:{document:s.document||[],signer:(s.signer||[]).map(n=>({id:n.id,value:m.get(n.id)??null}))},fileName:u?.fileName||"document.pdf"};try{await j?.(e)}finally{_(!1)}},[h,k,o,t.source,s,m,u,j]),ne=r.useCallback(async()=>{if(!b||h||x)return;A(!0),D({type:"submit"});const e=D({type:"submit"}),n={eventId:o,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-Z.current)/1e3),auditTrail:e,documentFields:s.document||[],signerFields:(s.signer||[]).map(d=>({id:d.id,value:m.get(d.id)??null})),isFullyCompleted:b};try{await g(n)}finally{A(!1)}},[b,h,x,o,s,m,g]),se=e=>{const n=e.component||oe(e.type);return l.jsx(n,{value:m.get(e.id)??null,onChange:d=>ee(e.id,d),isDisabled:h,label:e.label},e.id)},oe=e=>{switch(e){case"signature":case"text":return L;case"checkbox":return K}},re=()=>{const e=u?.component||fe(u);return e?l.jsx(e,{onClick:te,fileName:u?.fileName,isDisabled:h,isDownloading:k}):null},ae=()=>{if(t.mode==="download")return null;const e=f?.component||he(f);return l.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",children:l.jsx(e,{onClick:ne,isValid:b,isDisabled:h,isSubmitting:x})})},z=re(),ie=ae();return r.useImperativeHandle(c,()=>({getState:()=>({scrolled:y,fields:m,isValid:b,isSubmitting:x}),getAuditTrail:()=>w.current,reset:()=>{F(!t.validation?.scroll?.required),I(new Map),q(!1),w.current=[],B([])},updateFieldInDocument:C}),[y,m,b,x,t.validation?.scroll?.required,C]),l.jsxs("div",{className:`superdoc-esign-container ${Y||""}`,style:G,children:[l.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",children:[z&&l.jsx("div",{className:"superdoc-esign-document-toolbar",children:l.jsx("div",{className:"superdoc-esign-document-controls",children:z})}),l.jsx("div",{ref:M,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:J,overflow:"auto"}})]}),l.jsxs("div",{className:"superdoc-esign-controls","data-testid":"superdoc-esign-controls",children:[s.signer&&s.signer.length>0&&l.jsx("div",{className:"superdoc-esign-fields","data-testid":"superdoc-esign-fields",children:s.signer.map(se)}),ie]})]})});X.displayName="SuperDocESign";exports.CheckboxInput=K;exports.SignatureInput=L;exports.default=X;exports.textToImageDataUrl=W;
|
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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, E = 6;
|
|
7
|
+
return l.width = Math.ceil(i + p * 2) + 20, l.height = Math.ceil(m + E * 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,
|
|
7
12
|
label: n
|
|
8
|
-
}) => /* @__PURE__ */
|
|
13
|
+
}) => /* @__PURE__ */ b(
|
|
9
14
|
"div",
|
|
10
15
|
{
|
|
11
16
|
className: "superdoc-esign-signature-input",
|
|
12
17
|
style: { display: "flex", flexDirection: "column", gap: "8px" },
|
|
13
18
|
children: [
|
|
14
|
-
n && /* @__PURE__ */
|
|
15
|
-
/* @__PURE__ */
|
|
19
|
+
n && /* @__PURE__ */ d("label", { children: n }),
|
|
20
|
+
/* @__PURE__ */ d(
|
|
16
21
|
"input",
|
|
17
22
|
{
|
|
18
23
|
type: "text",
|
|
19
|
-
value: String(
|
|
20
|
-
onChange: (
|
|
21
|
-
disabled:
|
|
24
|
+
value: String(u || ""),
|
|
25
|
+
onChange: (o) => l(o.target.value),
|
|
26
|
+
disabled: r,
|
|
22
27
|
placeholder: "Type your full name",
|
|
23
28
|
style: {
|
|
24
29
|
fontFamily: "cursive",
|
|
@@ -28,43 +33,43 @@ const ge = ({
|
|
|
28
33
|
)
|
|
29
34
|
]
|
|
30
35
|
}
|
|
31
|
-
),
|
|
32
|
-
value:
|
|
33
|
-
onChange:
|
|
34
|
-
isDisabled:
|
|
36
|
+
), ue = ({
|
|
37
|
+
value: u,
|
|
38
|
+
onChange: l,
|
|
39
|
+
isDisabled: r,
|
|
35
40
|
label: n
|
|
36
|
-
}) => /* @__PURE__ */
|
|
37
|
-
/* @__PURE__ */
|
|
41
|
+
}) => /* @__PURE__ */ b("label", { className: "superdoc-esign-checkbox-input", style: { display: "flex", gap: "8px" }, children: [
|
|
42
|
+
/* @__PURE__ */ d(
|
|
38
43
|
"input",
|
|
39
44
|
{
|
|
40
45
|
type: "checkbox",
|
|
41
|
-
checked: !!
|
|
42
|
-
onChange: (
|
|
43
|
-
disabled:
|
|
46
|
+
checked: !!u,
|
|
47
|
+
onChange: (o) => l(o.target.checked),
|
|
48
|
+
disabled: r
|
|
44
49
|
}
|
|
45
50
|
),
|
|
46
|
-
/* @__PURE__ */
|
|
47
|
-
] }),
|
|
48
|
-
onClick:
|
|
51
|
+
/* @__PURE__ */ d("span", { children: n })
|
|
52
|
+
] }), pe = (u) => ({
|
|
53
|
+
onClick: r,
|
|
49
54
|
fileName: n,
|
|
50
|
-
isDisabled:
|
|
51
|
-
isDownloading:
|
|
55
|
+
isDisabled: o,
|
|
56
|
+
isDownloading: i
|
|
52
57
|
}) => {
|
|
53
|
-
const
|
|
54
|
-
return /* @__PURE__ */
|
|
58
|
+
const m = u?.label || "Download", p = o || i;
|
|
59
|
+
return /* @__PURE__ */ b(
|
|
55
60
|
"button",
|
|
56
61
|
{
|
|
57
|
-
onClick:
|
|
58
|
-
disabled:
|
|
59
|
-
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" : ""}`,
|
|
60
65
|
style: {
|
|
61
66
|
padding: "8px 16px",
|
|
62
67
|
borderRadius: "6px",
|
|
63
68
|
border: "1px solid #d0d5dd",
|
|
64
69
|
background: "#ffffff",
|
|
65
70
|
color: "#333",
|
|
66
|
-
cursor:
|
|
67
|
-
opacity:
|
|
71
|
+
cursor: p ? "not-allowed" : "pointer",
|
|
72
|
+
opacity: p ? 0.7 : 1,
|
|
68
73
|
fontSize: "16px",
|
|
69
74
|
fontWeight: "bold",
|
|
70
75
|
display: "inline-flex",
|
|
@@ -73,33 +78,33 @@ const ge = ({
|
|
|
73
78
|
transition: "opacity 0.2s ease"
|
|
74
79
|
},
|
|
75
80
|
children: [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
!
|
|
81
|
+
i && /* @__PURE__ */ d("span", { className: "superdoc-esign-spinner" }),
|
|
82
|
+
i ? "Downloading..." : m,
|
|
83
|
+
!i && n && ` (${n})`
|
|
79
84
|
]
|
|
80
85
|
}
|
|
81
86
|
);
|
|
82
|
-
},
|
|
83
|
-
onClick:
|
|
87
|
+
}, ge = (u) => ({
|
|
88
|
+
onClick: r,
|
|
84
89
|
isValid: n,
|
|
85
|
-
isDisabled:
|
|
86
|
-
isSubmitting:
|
|
90
|
+
isDisabled: o,
|
|
91
|
+
isSubmitting: i
|
|
87
92
|
}) => {
|
|
88
|
-
const
|
|
89
|
-
return /* @__PURE__ */
|
|
93
|
+
const m = u?.label || "Submit", p = !n || o || i;
|
|
94
|
+
return /* @__PURE__ */ b(
|
|
90
95
|
"button",
|
|
91
96
|
{
|
|
92
|
-
onClick:
|
|
93
|
-
disabled:
|
|
94
|
-
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" : ""}`,
|
|
95
100
|
style: {
|
|
96
101
|
padding: "12px 24px",
|
|
97
102
|
borderRadius: "6px",
|
|
98
103
|
border: "none",
|
|
99
104
|
background: "#007bff",
|
|
100
105
|
color: "#fff",
|
|
101
|
-
cursor:
|
|
102
|
-
opacity:
|
|
106
|
+
cursor: p ? "not-allowed" : "pointer",
|
|
107
|
+
opacity: p && !i ? 0.5 : 1,
|
|
103
108
|
fontSize: "16px",
|
|
104
109
|
fontWeight: "bold",
|
|
105
110
|
display: "inline-flex",
|
|
@@ -108,21 +113,21 @@ const ge = ({
|
|
|
108
113
|
transition: "opacity 0.2s ease"
|
|
109
114
|
},
|
|
110
115
|
children: [
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
i && /* @__PURE__ */ d("span", { className: "superdoc-esign-spinner superdoc-esign-spinner--light" }),
|
|
117
|
+
i ? "Submitting..." : m
|
|
113
118
|
]
|
|
114
119
|
}
|
|
115
120
|
);
|
|
116
|
-
},
|
|
117
|
-
(
|
|
121
|
+
}, me = ae(
|
|
122
|
+
(u, l) => {
|
|
118
123
|
const {
|
|
119
|
-
eventId:
|
|
124
|
+
eventId: r,
|
|
120
125
|
document: n,
|
|
121
|
-
fields:
|
|
122
|
-
download:
|
|
123
|
-
submit:
|
|
124
|
-
onSubmit:
|
|
125
|
-
onDownload:
|
|
126
|
+
fields: o = {},
|
|
127
|
+
download: i,
|
|
128
|
+
submit: m,
|
|
129
|
+
onSubmit: p,
|
|
130
|
+
onDownload: E,
|
|
126
131
|
onStateChange: A,
|
|
127
132
|
onFieldChange: q,
|
|
128
133
|
onFieldsDiscovered: V,
|
|
@@ -130,50 +135,43 @@ const ge = ({
|
|
|
130
135
|
className: X,
|
|
131
136
|
style: Y,
|
|
132
137
|
documentHeight: G = "600px"
|
|
133
|
-
} =
|
|
134
|
-
w.current =
|
|
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), F = D(null), R = D(null), Q = D(Date.now()), w = D(o), N = D([]), j = D(V);
|
|
139
|
+
w.current = o, j.current = V, k(() => {
|
|
135
140
|
N.current = z;
|
|
136
141
|
}, [z]);
|
|
137
142
|
const C = M((e) => {
|
|
138
|
-
if (!
|
|
139
|
-
const t =
|
|
140
|
-
let
|
|
141
|
-
|
|
143
|
+
if (!R.current?.activeEditor) return;
|
|
144
|
+
const t = R.current.activeEditor, a = w.current.signer?.find((s) => s.id === e.id);
|
|
145
|
+
let c;
|
|
146
|
+
a?.type === "signature" && e.value ? c = {
|
|
142
147
|
json: {
|
|
143
148
|
type: "image",
|
|
144
|
-
attrs: { src: typeof e.value == "string" && e.value.startsWith("data:image/") ? e.value :
|
|
149
|
+
attrs: { src: typeof e.value == "string" && e.value.startsWith("data:image/") ? e.value : le(String(e.value)), alt: "Signature" }
|
|
145
150
|
}
|
|
146
|
-
} :
|
|
147
|
-
}, [])
|
|
148
|
-
function Z(e) {
|
|
149
|
-
const t = globalThis.document.createElement("canvas"), o = t.getContext("2d"), r = 30;
|
|
150
|
-
o.font = `italic ${r}px cursive`;
|
|
151
|
-
const g = o.measureText(e).width, ce = r * 1.3, le = 4, de = 6;
|
|
152
|
-
return t.width = Math.ceil(g + le * 2) + 20, t.height = Math.ceil(ce + de * 2), o.font = `italic ${r}px cursive`, o.fillStyle = "black", o.textAlign = "center", o.textBaseline = "middle", o.fillText(e, t.width / 2, t.height / 2), t.toDataURL("image/png");
|
|
153
|
-
}
|
|
154
|
-
const L = M(
|
|
151
|
+
} : c = { text: String(e.value ?? "") }, e.id && t.commands.updateStructuredContentById(e.id, c);
|
|
152
|
+
}, []), L = M(
|
|
155
153
|
(e) => {
|
|
156
154
|
if (!e) return;
|
|
157
155
|
const t = e.helpers.structuredContentCommands.getStructuredContentTags(
|
|
158
156
|
e.state
|
|
159
|
-
),
|
|
157
|
+
), a = /* @__PURE__ */ new Map();
|
|
160
158
|
w.current.document?.forEach((s) => {
|
|
161
|
-
s.id &&
|
|
159
|
+
s.id && a.set(s.id, s.value);
|
|
162
160
|
}), w.current.signer?.forEach((s) => {
|
|
163
|
-
s.value !== void 0 &&
|
|
161
|
+
s.value !== void 0 && a.set(s.id, s.value);
|
|
164
162
|
});
|
|
165
|
-
const
|
|
163
|
+
const c = t.map(({ node: s }) => ({
|
|
166
164
|
id: s.attrs.id,
|
|
167
165
|
label: s.attrs.label,
|
|
168
|
-
value:
|
|
166
|
+
value: a.get(s.attrs.id) ?? s.textContent ?? ""
|
|
169
167
|
})).filter((s) => s.id);
|
|
170
|
-
|
|
168
|
+
c.length > 0 && (j.current?.(c), [
|
|
171
169
|
...w.current.document || [],
|
|
172
170
|
...w.current.signer || []
|
|
173
|
-
].filter((
|
|
174
|
-
(
|
|
175
|
-
id:
|
|
176
|
-
value:
|
|
171
|
+
].filter((v) => v.value !== void 0).forEach(
|
|
172
|
+
(v) => C({
|
|
173
|
+
id: v.id,
|
|
174
|
+
value: v.value
|
|
177
175
|
})
|
|
178
176
|
));
|
|
179
177
|
},
|
|
@@ -182,31 +180,32 @@ const ge = ({
|
|
|
182
180
|
const t = {
|
|
183
181
|
...e,
|
|
184
182
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
return N.current =
|
|
183
|
+
}, a = globalThis?.__SUPERDOC_AUDIT_MOCK__;
|
|
184
|
+
a && a(t);
|
|
185
|
+
const c = [...N.current, t];
|
|
186
|
+
return N.current = c, O(c), c;
|
|
189
187
|
};
|
|
190
|
-
|
|
191
|
-
if (!
|
|
188
|
+
k(() => {
|
|
189
|
+
if (!F.current) return;
|
|
192
190
|
let e = !1, t = null;
|
|
193
191
|
return (async () => {
|
|
194
|
-
const { SuperDoc:
|
|
195
|
-
e || (t = new
|
|
196
|
-
selector:
|
|
192
|
+
const { SuperDoc: c } = await import("superdoc");
|
|
193
|
+
e || (t = new c({
|
|
194
|
+
selector: F.current,
|
|
197
195
|
document: n.source,
|
|
198
196
|
documentMode: "viewing",
|
|
199
197
|
modules: {
|
|
200
198
|
comments: !1
|
|
201
199
|
},
|
|
200
|
+
// @ts-expect-error - layoutMode is not supported in SuperDoc v1.1.0 yet
|
|
202
201
|
layoutMode: n.layoutMode,
|
|
203
202
|
layoutMargins: n.layoutMargins,
|
|
204
203
|
onReady: () => {
|
|
205
204
|
e || (t?.activeEditor && L(t.activeEditor), T({ type: "ready" }), J(!0));
|
|
206
205
|
}
|
|
207
|
-
}),
|
|
206
|
+
}), R.current = t);
|
|
208
207
|
})(), () => {
|
|
209
|
-
e = !0, t && typeof t.destroy == "function" && t.destroy(),
|
|
208
|
+
e = !0, t && typeof t.destroy == "function" && t.destroy(), R.current = null;
|
|
210
209
|
};
|
|
211
210
|
}, [
|
|
212
211
|
n.source,
|
|
@@ -217,107 +216,107 @@ const ge = ({
|
|
|
217
216
|
n.layoutMargins?.left,
|
|
218
217
|
n.layoutMargins?.right,
|
|
219
218
|
L
|
|
220
|
-
]),
|
|
219
|
+
]), k(() => {
|
|
221
220
|
if (!n.validation?.scroll?.required || !W) return;
|
|
222
|
-
const e =
|
|
221
|
+
const e = F.current;
|
|
223
222
|
if (!e) return;
|
|
224
223
|
const t = () => {
|
|
225
|
-
const { scrollTop:
|
|
226
|
-
(
|
|
224
|
+
const { scrollTop: a, scrollHeight: c, clientHeight: s } = e, v = a / (c - s);
|
|
225
|
+
(v >= 0.95 || c <= s) && (B(!0), T({
|
|
227
226
|
type: "scroll",
|
|
228
|
-
data: { percent: Math.round(
|
|
227
|
+
data: { percent: Math.round(v * 100) }
|
|
229
228
|
}));
|
|
230
229
|
};
|
|
231
230
|
return e.addEventListener("scroll", t), t(), () => e.removeEventListener("scroll", t);
|
|
232
231
|
}, [n.validation?.scroll?.required, W]);
|
|
233
|
-
const
|
|
232
|
+
const Z = M(
|
|
234
233
|
(e, t) => {
|
|
235
|
-
_((
|
|
236
|
-
const
|
|
234
|
+
_((a) => {
|
|
235
|
+
const c = a.get(e), s = new Map(a);
|
|
237
236
|
return s.set(e, t), C({
|
|
238
237
|
id: e,
|
|
239
238
|
value: t
|
|
240
239
|
}), T({
|
|
241
240
|
type: "field_change",
|
|
242
|
-
data: { fieldId: e, value: t, previousValue:
|
|
241
|
+
data: { fieldId: e, value: t, previousValue: c }
|
|
243
242
|
}), q?.({
|
|
244
243
|
id: e,
|
|
245
244
|
value: t,
|
|
246
|
-
previousValue:
|
|
245
|
+
previousValue: c
|
|
247
246
|
}), s;
|
|
248
247
|
});
|
|
249
248
|
},
|
|
250
249
|
[q, C]
|
|
251
|
-
), P = M(() => n.validation?.scroll?.required && !x ? !1 : (
|
|
250
|
+
), P = M(() => n.validation?.scroll?.required && !x ? !1 : (o.signer || []).every((e) => {
|
|
252
251
|
if (!e.validation?.required) return !0;
|
|
253
|
-
const t =
|
|
252
|
+
const t = g.get(e.id);
|
|
254
253
|
return t && (typeof t != "string" || t.trim());
|
|
255
|
-
}), [x,
|
|
256
|
-
|
|
254
|
+
}), [x, o.signer, g, n.validation?.scroll?.required]);
|
|
255
|
+
k(() => {
|
|
257
256
|
const e = P();
|
|
258
257
|
U(e), A?.({
|
|
259
258
|
scrolled: x,
|
|
260
|
-
fields:
|
|
259
|
+
fields: g,
|
|
261
260
|
isValid: e,
|
|
262
261
|
isSubmitting: h
|
|
263
262
|
});
|
|
264
|
-
}, [x,
|
|
265
|
-
const
|
|
266
|
-
if (f ||
|
|
263
|
+
}, [x, g, h, P, A]);
|
|
264
|
+
const ee = M(async () => {
|
|
265
|
+
if (f || I) return;
|
|
267
266
|
H(!0);
|
|
268
267
|
const e = {
|
|
269
|
-
eventId:
|
|
268
|
+
eventId: r,
|
|
270
269
|
documentSource: n.source,
|
|
271
270
|
fields: {
|
|
272
|
-
document:
|
|
273
|
-
signer: (
|
|
271
|
+
document: o.document || [],
|
|
272
|
+
signer: (o.signer || []).map((t) => ({
|
|
274
273
|
id: t.id,
|
|
275
|
-
value:
|
|
274
|
+
value: g.get(t.id) ?? null
|
|
276
275
|
}))
|
|
277
276
|
},
|
|
278
|
-
fileName:
|
|
277
|
+
fileName: i?.fileName || "document.pdf"
|
|
279
278
|
};
|
|
280
279
|
try {
|
|
281
|
-
await
|
|
280
|
+
await E?.(e);
|
|
282
281
|
} finally {
|
|
283
282
|
H(!1);
|
|
284
283
|
}
|
|
285
284
|
}, [
|
|
286
285
|
f,
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
I,
|
|
287
|
+
r,
|
|
289
288
|
n.source,
|
|
289
|
+
o,
|
|
290
|
+
g,
|
|
290
291
|
i,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
I
|
|
294
|
-
]), ne = M(async () => {
|
|
292
|
+
E
|
|
293
|
+
]), te = M(async () => {
|
|
295
294
|
if (!S || f || h) return;
|
|
296
295
|
$(!0), T({ type: "submit" });
|
|
297
296
|
const e = T({ type: "submit" }), t = {
|
|
298
|
-
eventId:
|
|
297
|
+
eventId: r,
|
|
299
298
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
300
299
|
duration: Math.floor((Date.now() - Q.current) / 1e3),
|
|
301
300
|
auditTrail: e,
|
|
302
|
-
documentFields:
|
|
303
|
-
signerFields: (
|
|
304
|
-
id:
|
|
305
|
-
value:
|
|
301
|
+
documentFields: o.document || [],
|
|
302
|
+
signerFields: (o.signer || []).map((a) => ({
|
|
303
|
+
id: a.id,
|
|
304
|
+
value: g.get(a.id) ?? null
|
|
306
305
|
})),
|
|
307
306
|
isFullyCompleted: S
|
|
308
307
|
};
|
|
309
308
|
try {
|
|
310
|
-
await
|
|
309
|
+
await p(t);
|
|
311
310
|
} finally {
|
|
312
311
|
$(!1);
|
|
313
312
|
}
|
|
314
|
-
}, [S, f, h,
|
|
313
|
+
}, [S, f, h, r, o, g, p]), ne = (e) => {
|
|
315
314
|
const t = e.component || se(e.type);
|
|
316
|
-
return /* @__PURE__ */
|
|
315
|
+
return /* @__PURE__ */ d(
|
|
317
316
|
t,
|
|
318
317
|
{
|
|
319
|
-
value:
|
|
320
|
-
onChange: (
|
|
318
|
+
value: g.get(e.id) ?? null,
|
|
319
|
+
onChange: (a) => Z(e.id, a),
|
|
321
320
|
isDisabled: f,
|
|
322
321
|
label: e.label
|
|
323
322
|
},
|
|
@@ -327,41 +326,41 @@ const ge = ({
|
|
|
327
326
|
switch (e) {
|
|
328
327
|
case "signature":
|
|
329
328
|
case "text":
|
|
330
|
-
return
|
|
329
|
+
return de;
|
|
331
330
|
case "checkbox":
|
|
332
|
-
return
|
|
331
|
+
return ue;
|
|
333
332
|
}
|
|
334
|
-
},
|
|
335
|
-
const e =
|
|
336
|
-
return e ? /* @__PURE__ */
|
|
333
|
+
}, oe = () => {
|
|
334
|
+
const e = i?.component || pe(i);
|
|
335
|
+
return e ? /* @__PURE__ */ d(
|
|
337
336
|
e,
|
|
338
337
|
{
|
|
339
|
-
onClick:
|
|
340
|
-
fileName:
|
|
338
|
+
onClick: ee,
|
|
339
|
+
fileName: i?.fileName,
|
|
341
340
|
isDisabled: f,
|
|
342
|
-
isDownloading:
|
|
341
|
+
isDownloading: I
|
|
343
342
|
}
|
|
344
343
|
) : null;
|
|
345
|
-
},
|
|
344
|
+
}, re = () => {
|
|
346
345
|
if (n.mode === "download")
|
|
347
346
|
return null;
|
|
348
|
-
const e =
|
|
349
|
-
return /* @__PURE__ */
|
|
347
|
+
const e = m?.component || ge(m);
|
|
348
|
+
return /* @__PURE__ */ d("div", { className: "superdoc-esign-actions superdoc-esign-form-actions", children: /* @__PURE__ */ d(
|
|
350
349
|
e,
|
|
351
350
|
{
|
|
352
|
-
onClick:
|
|
351
|
+
onClick: te,
|
|
353
352
|
isValid: S,
|
|
354
353
|
isDisabled: f,
|
|
355
354
|
isSubmitting: h
|
|
356
355
|
}
|
|
357
356
|
) });
|
|
358
|
-
}, K =
|
|
359
|
-
return
|
|
360
|
-
|
|
357
|
+
}, K = oe(), ie = re();
|
|
358
|
+
return ce(
|
|
359
|
+
l,
|
|
361
360
|
() => ({
|
|
362
361
|
getState: () => ({
|
|
363
362
|
scrolled: x,
|
|
364
|
-
fields:
|
|
363
|
+
fields: g,
|
|
365
364
|
isValid: S,
|
|
366
365
|
isSubmitting: h
|
|
367
366
|
}),
|
|
@@ -373,35 +372,36 @@ const ge = ({
|
|
|
373
372
|
}),
|
|
374
373
|
[
|
|
375
374
|
x,
|
|
376
|
-
|
|
375
|
+
g,
|
|
377
376
|
S,
|
|
378
377
|
h,
|
|
379
378
|
n.validation?.scroll?.required,
|
|
380
379
|
C
|
|
381
380
|
]
|
|
382
|
-
), /* @__PURE__ */
|
|
383
|
-
/* @__PURE__ */
|
|
384
|
-
K && /* @__PURE__ */
|
|
385
|
-
/* @__PURE__ */
|
|
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(
|
|
386
385
|
"div",
|
|
387
386
|
{
|
|
388
|
-
ref:
|
|
387
|
+
ref: F,
|
|
389
388
|
className: "superdoc-esign-document-viewer",
|
|
390
389
|
"data-testid": "superdoc-scroll-container",
|
|
391
390
|
style: { height: G, overflow: "auto" }
|
|
392
391
|
}
|
|
393
392
|
)
|
|
394
393
|
] }),
|
|
395
|
-
/* @__PURE__ */
|
|
396
|
-
|
|
397
|
-
|
|
394
|
+
/* @__PURE__ */ b("div", { className: "superdoc-esign-controls", "data-testid": "superdoc-esign-controls", children: [
|
|
395
|
+
o.signer && o.signer.length > 0 && /* @__PURE__ */ d("div", { className: "superdoc-esign-fields", "data-testid": "superdoc-esign-fields", children: o.signer.map(ne) }),
|
|
396
|
+
ie
|
|
398
397
|
] })
|
|
399
398
|
] });
|
|
400
399
|
}
|
|
401
400
|
);
|
|
402
|
-
|
|
401
|
+
me.displayName = "SuperDocESign";
|
|
403
402
|
export {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
403
|
+
ue as CheckboxInput,
|
|
404
|
+
de as SignatureInput,
|
|
405
|
+
me as default,
|
|
406
|
+
le as textToImageDataUrl
|
|
407
407
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/utils/signature.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,MAyBjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc-dev/esign",
|
|
3
|
-
"version": "1.4.0-next.
|
|
3
|
+
"version": "1.4.0-next.4",
|
|
4
4
|
"description": "React eSignature component for SuperDoc",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
58
58
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
59
|
-
"superdoc": "^
|
|
59
|
+
"superdoc": "^1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@commitlint/cli": "^20.1.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"react": "^19.2.0",
|
|
82
82
|
"react-dom": "^19.2.0",
|
|
83
83
|
"semantic-release": "^24.2.9",
|
|
84
|
-
"superdoc": "
|
|
84
|
+
"superdoc": "1.1.0",
|
|
85
85
|
"typescript": "^5.9.2",
|
|
86
86
|
"typescript-eslint": "^8.44.1",
|
|
87
87
|
"vite": "^7.1.7",
|