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