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