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