@superdoc-dev/esign 2.1.0-next.2 → 2.1.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,gIAqdjB,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 be=Object.create;var J=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var Se=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var Ce=(i,c,r,s)=>{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:!(s=ye(c,o))||s.enumerable});return i};var De=(i,c,r)=>(r=i!=null?be(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"),s=30;r.font=`italic ${s}px cursive`;const u=r.measureText(i).width,f=s*1.3,g=4,R=6;return c.width=Math.ceil(u+g*2)+20,c.height=Math.ceil(f+R*2),r.font=`italic ${s}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:s})=>l.jsxs("div",{className:"superdoc-esign-signature-input",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[s&&l.jsx("label",{children:s}),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:s})=>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:s})]}),je=i=>({onClick:r,fileName:s,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&&s&&` (${s})`]})},Re=i=>({onClick:r,isValid:s,isDisabled:o,isSubmitting:u})=>{const f=i?.label||"Submit",g=!s||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:s,fields:o={},download:u,submit:f,onSubmit:g,onDownload:R,onStateChange:F,onFieldChange:A,onFieldsDiscovered:q,isDisabled:h=!1,className:ne,style:se,documentHeight:oe="600px"}=i,[y,O]=a.useState(!s.validation?.scroll?.required),[m,_]=a.useState(new Map),[x,B]=a.useState(!1),[v,V]=a.useState(!1),[k,U]=a.useState(!1),[z,$]=a.useState([]),[H,re]=a.useState(!1),T=a.useRef(null),E=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=z},[z]);const b=a.useCallback(e=>{if(!E.current?.activeEditor)return;const t=E.current.activeEditor,d=S.current.signer?.find(n=>n.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:I,pos:fe}=D[0],X=I.childCount;if(X>1){let j=t.state.tr;for(let N=X-1;N>=1;N--){let Y=1;for(let M=0;M<N;M++)Y+=I.child(M).nodeSize;const he=I.child(N),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(n=>{n.id&&d.set(n.id,n.value)}),S.current.signer?.forEach(n=>{n.value!==void 0&&d.set(n.id,n.value)});const p=t.map(({node:n})=>({id:n.attrs.id,label:n.attrs.label,value:d.get(n.attrs.id)??n.textContent??""})).filter(n=>n.id);p.length>0&&(P.current?.(p),(S.current.document||[]).filter(n=>n.value!==void 0).forEach(n=>b({id:n.id,value:n.value,type:n.type})),(S.current.signer||[]).filter(n=>n.value!==void 0).forEach(n=>b({id:n.id,value:n.value})))},[b]),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(!T.current)return;let e=!1,t=null;return(async()=>{const{SuperDoc:p}=await import("superdoc");e||(t=new p({selector:T.current,document:s.source,documentMode:"viewing",modules:{comments:!1},viewOptions:{layout:s.viewOptions?.layout??(s.layoutMode==="responsive"?"web":"print")},onReady:()=>{e||(t?.activeEditor&&W(t.activeEditor),C({type:"ready"}),re(!0))}}),E.current=t)})(),()=>{e=!0,t&&typeof t.destroy=="function"&&t.destroy(),E.current=null}},[s.source,s.mode,s.layoutMode,s.viewOptions?.layout,W]),a.useEffect(()=>{if(!s.validation?.scroll?.required||!H)return;const e=T.current;if(!e)return;const t=()=>{const{scrollTop:d,scrollHeight:p,clientHeight:n}=e,D=d/(p-n);(D>=.95||p<=n)&&(O(!0),C({type:"scroll",data:{percent:Math.round(D*100)}}))};return e.addEventListener("scroll",t),t(),()=>e.removeEventListener("scroll",t)},[s.validation?.scroll?.required,H]);const ie=a.useCallback((e,t)=>{_(d=>{const p=d.get(e),n=new Map(d);return n.set(e,t),b({id:e,value:t}),C({type:"field_change",data:{fieldId:e,value:t,previousValue:p}}),A?.({id:e,value:t,previousValue:p}),n})},[A,b]),L=a.useCallback(()=>s.validation?.scroll?.required&&!y?!1:(o.signer||[]).every(e=>{if(!e.validation?.required)return!0;const t=m.get(e.id);return t&&(typeof t!="string"||t.trim())}),[y,o.signer,m,s.validation?.scroll?.required]);a.useEffect(()=>{const e=L();B(e),F?.({scrolled:y,fields:m,isValid:e,isSubmitting:v})},[y,m,v,L,F]);const ce=a.useCallback(async()=>{if(h||k)return;U(!0);const e={eventId:r,documentSource:s.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 R?.(e)}finally{U(!1)}},[h,k,r,s.source,o,m,u,R]),le=a.useCallback(async()=>{if(!x||h||v)return;V(!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{V(!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:k}):null},ge=()=>{if(s.mode==="download")return null;const e=f?.component||Re(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:y,fields:m,isValid:x,isSubmitting:v}),getAuditTrail:()=>w.current,reset:()=>{O(!s.validation?.scroll?.required),_(new Map),B(!1),w.current=[],$([])},updateFieldInDocument:b}),[y,m,x,v,s.validation?.scroll?.required,b]),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:T,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 ve, useState as y, useRef as C, useEffect as A, useCallback as D, useImperativeHandle as ye } 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 i = s.measureText(u).width, m = o * 1.3, p = 4, k = 6;
7
+ return l.width = Math.ceil(i + p * 2) + 20, l.height = Math.ceil(m + k * 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
+ }, we = ({
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,33 +33,33 @@ const le = (u) => {
33
33
  )
34
34
  ]
35
35
  }
36
- ), ue = ({
36
+ ), xe = ({
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,
51
+ /* @__PURE__ */ d("span", { children: o })
52
+ ] }), Se = (u) => ({
53
+ onClick: s,
54
+ fileName: o,
55
+ isDisabled: r,
56
56
  isDownloading: i
57
57
  }) => {
58
- const m = u?.label || "Download", p = s || i;
58
+ const m = u?.label || "Download", p = r || i;
59
59
  return /* @__PURE__ */ b(
60
60
  "button",
61
61
  {
62
- onClick: r,
62
+ onClick: s,
63
63
  disabled: p,
64
64
  className: `superdoc-esign-btn superdoc-esign-btn--download${i ? " superdoc-esign-btn--loading" : ""}`,
65
65
  style: {
@@ -80,21 +80,21 @@ const le = (u) => {
80
80
  children: [
81
81
  i && /* @__PURE__ */ d("span", { className: "superdoc-esign-spinner" }),
82
82
  i ? "Downloading..." : m,
83
- !i && n && ` (${n})`
83
+ !i && o && ` (${o})`
84
84
  ]
85
85
  }
86
86
  );
87
- }, ge = (u) => ({
88
- onClick: r,
89
- isValid: n,
90
- isDisabled: s,
87
+ }, Ce = (u) => ({
88
+ onClick: s,
89
+ isValid: o,
90
+ isDisabled: r,
91
91
  isSubmitting: i
92
92
  }) => {
93
- const m = u?.label || "Submit", p = !n || s || i;
93
+ const m = u?.label || "Submit", p = !o || r || i;
94
94
  return /* @__PURE__ */ b(
95
95
  "button",
96
96
  {
97
- onClick: r,
97
+ onClick: s,
98
98
  disabled: p,
99
99
  className: `superdoc-esign-btn superdoc-esign-btn--submit${i ? " superdoc-esign-btn--loading" : ""}`,
100
100
  style: {
@@ -118,290 +118,279 @@ const le = (u) => {
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 = ve((u, l) => {
122
+ const {
123
+ eventId: s,
124
+ document: o,
125
+ fields: r = {},
126
+ download: i,
127
+ submit: m,
128
+ onSubmit: p,
129
+ onDownload: k,
130
+ onStateChange: V,
131
+ onFieldChange: _,
132
+ onFieldsDiscovered: z,
133
+ isDisabled: f = !1,
134
+ className: te,
135
+ style: ne,
136
+ documentHeight: oe = "600px"
137
+ } = u, [w, U] = y(!o.validation?.scroll?.required), [g, $] = y(/* @__PURE__ */ new Map()), [x, H] = y(!1), [h, j] = y(!1), [q, P] = y(!1), [W, L] = y([]), [K, re] = y(!1), F = C(null), I = C(null), se = C(Date.now()), S = C(r), N = C([]), X = C(z);
138
+ S.current = r, X.current = z, A(() => {
139
+ N.current = W;
140
+ }, [W]);
141
+ const v = D((e) => {
142
+ if (!I.current?.activeEditor) return;
143
+ const t = I.current.activeEditor, a = S.current.signer?.find((n) => n.id === e.id);
144
+ if (e.type === "table" && Array.isArray(e.value)) {
145
+ const E = t.helpers?.structuredContentCommands?.getStructuredContentTablesById?.(e.id, t.state) || [];
146
+ if (E.length) {
147
+ const { node: B, pos: me } = E[0], Q = B.childCount;
148
+ if (Q > 1) {
149
+ let R = t.state.tr;
150
+ for (let M = Q - 1; M >= 1; M--) {
151
+ let Z = 1;
152
+ for (let O = 0; O < M; O++)
153
+ Z += B.child(O).nodeSize;
154
+ const fe = B.child(M), ee = me + Z, he = ee + fe.nodeSize;
155
+ R = R.delete(R.mapping.map(ee), R.mapping.map(he));
156
+ }
157
+ t.view?.dispatch(R);
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
- ));
177
- },
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;
187
- };
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;
164
+ }
165
+ return;
166
+ }
167
+ let c;
168
+ a?.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) => {
222
176
  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
- });
248
- },
249
- [q, C]
250
- ), P = M(() => n.validation?.scroll?.required && !x ? !1 : (s.signer || []).every((e) => {
251
- if (!e.validation?.required) return !0;
252
- const t = g.get(e.id);
253
- return t && (typeof t != "string" || t.trim());
254
- }), [x, s.signer, g, n.validation?.scroll?.required]);
255
- k(() => {
256
- const e = P();
257
- U(e), A?.({
258
- scrolled: x,
259
- fields: g,
260
- isValid: e,
261
- isSubmitting: h
177
+ const t = e.helpers.structuredContentCommands.getStructuredContentTags(e.state), a = /* @__PURE__ */ new Map();
178
+ S.current.document?.forEach((n) => {
179
+ n.id && a.set(n.id, n.value);
180
+ }), S.current.signer?.forEach((n) => {
181
+ n.value !== void 0 && a.set(n.id, n.value);
262
182
  });
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
- }))
183
+ const c = t.map(({ node: n }) => ({
184
+ id: n.attrs.id,
185
+ label: n.attrs.label,
186
+ value: a.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) => v({
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) => v({
196
+ id: n.id,
197
+ value: n.value
198
+ })
199
+ ));
200
+ },
201
+ [v]
202
+ ), T = (e) => {
203
+ const t = {
204
+ ...e,
205
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
206
+ }, a = globalThis?.__SUPERDOC_AUDIT_MOCK__;
207
+ a && a(t);
208
+ const c = [...N.current, t];
209
+ return N.current = c, L(c), c;
210
+ };
211
+ A(() => {
212
+ if (!F.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: F.current,
218
+ document: o.source,
219
+ documentMode: "viewing",
220
+ modules: {
221
+ comments: !1
276
222
  },
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
223
+ viewOptions: {
224
+ layout: o.viewOptions?.layout ?? (o.layoutMode === "responsive" ? "web" : "print")
322
225
  },
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
226
+ onReady: () => {
227
+ e || (t?.activeEditor && Y(t.activeEditor), T({ type: "ready" }), re(!0));
342
228
  }
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,
229
+ }), I.current = t);
230
+ })(), () => {
231
+ e = !0, t && typeof t.destroy == "function" && t.destroy(), I.current = null;
232
+ };
233
+ }, [o.source, o.mode, o.layoutMode, o.viewOptions?.layout, Y]), A(() => {
234
+ if (!o.validation?.scroll?.required || !K) return;
235
+ const e = F.current;
236
+ if (!e) return;
237
+ const t = () => {
238
+ const { scrollTop: a, scrollHeight: c, clientHeight: n } = e, E = a / (c - n);
239
+ (E >= 0.95 || c <= n) && (U(!0), T({
240
+ type: "scroll",
241
+ data: { percent: Math.round(E * 100) }
242
+ }));
243
+ };
244
+ return e.addEventListener("scroll", t), t(), () => e.removeEventListener("scroll", t);
245
+ }, [o.validation?.scroll?.required, K]);
246
+ const ie = D(
247
+ (e, t) => {
248
+ $((a) => {
249
+ const c = a.get(e), n = new Map(a);
250
+ return n.set(e, t), v({
251
+ id: e,
252
+ value: t
253
+ }), T({
254
+ type: "field_change",
255
+ data: { fieldId: e, value: t, previousValue: c }
256
+ }), _?.({
257
+ id: e,
258
+ value: t,
259
+ previousValue: c
260
+ }), n;
261
+ });
262
+ },
263
+ [_, v]
264
+ ), G = D(() => o.validation?.scroll?.required && !w ? !1 : (r.signer || []).every((e) => {
265
+ if (!e.validation?.required) return !0;
266
+ const t = g.get(e.id);
267
+ return t && (typeof t != "string" || t.trim());
268
+ }), [w, r.signer, g, o.validation?.scroll?.required]);
269
+ A(() => {
270
+ const e = G();
271
+ H(e), V?.({
272
+ scrolled: w,
273
+ fields: g,
274
+ isValid: e,
275
+ isSubmitting: h
276
+ });
277
+ }, [w, g, h, G, V]);
278
+ const ae = D(async () => {
279
+ if (f || q) return;
280
+ P(!0);
281
+ const e = {
282
+ eventId: s,
283
+ documentSource: o.source,
284
+ fields: {
285
+ document: r.document || [],
286
+ signer: (r.signer || []).map((t) => ({
287
+ id: t.id,
288
+ value: g.get(t.id) ?? null
289
+ }))
290
+ },
291
+ fileName: i?.fileName || "document.pdf"
292
+ };
293
+ try {
294
+ await k?.(e);
295
+ } finally {
296
+ P(!1);
297
+ }
298
+ }, [f, q, s, o.source, r, g, i, k]), ce = D(async () => {
299
+ if (!x || f || h) return;
300
+ j(!0), T({ type: "submit" });
301
+ const e = T({ type: "submit" }), t = {
302
+ eventId: s,
303
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
304
+ duration: Math.floor((Date.now() - se.current) / 1e3),
305
+ auditTrail: e,
306
+ documentFields: r.document || [],
307
+ signerFields: (r.signer || []).map((a) => ({
308
+ id: a.id,
309
+ value: g.get(a.id) ?? null
310
+ })),
311
+ isFullyCompleted: x
312
+ };
313
+ try {
314
+ await p(t);
315
+ } finally {
316
+ j(!1);
317
+ }
318
+ }, [x, f, h, s, r, g, p]), le = (e) => {
319
+ const t = e.component || de(e.type);
320
+ return /* @__PURE__ */ d(
321
+ t,
322
+ {
323
+ value: g.get(e.id) ?? null,
324
+ onChange: (a) => ie(e.id, a),
325
+ isDisabled: f,
326
+ label: e.label
327
+ },
328
+ e.id
329
+ );
330
+ }, de = (e) => {
331
+ switch (e) {
332
+ case "signature":
333
+ case "text":
334
+ return we;
335
+ case "checkbox":
336
+ return xe;
337
+ }
338
+ }, ue = () => {
339
+ const e = i?.component || Se(i);
340
+ return e ? /* @__PURE__ */ d(
341
+ e,
342
+ {
343
+ onClick: ae,
344
+ fileName: i?.fileName,
345
+ isDisabled: f,
346
+ isDownloading: q
347
+ }
348
+ ) : null;
349
+ }, pe = () => {
350
+ if (o.mode === "download")
351
+ return null;
352
+ const e = m?.component || Ce(m);
353
+ return /* @__PURE__ */ d("div", { className: "superdoc-esign-actions superdoc-esign-form-actions", children: /* @__PURE__ */ d(e, { onClick: ce, isValid: x, isDisabled: f, isSubmitting: h }) });
354
+ }, J = ue(), ge = pe();
355
+ return ye(
356
+ l,
357
+ () => ({
358
+ getState: () => ({
359
+ scrolled: w,
360
+ fields: g,
361
+ isValid: x,
362
+ isSubmitting: h
363
+ }),
364
+ getAuditTrail: () => N.current,
365
+ reset: () => {
366
+ U(!o.validation?.scroll?.required), $(/* @__PURE__ */ new Map()), H(!1), N.current = [], L([]);
367
+ },
368
+ updateFieldInDocument: v
369
+ }),
370
+ [w, g, x, h, o.validation?.scroll?.required, v]
371
+ ), /* @__PURE__ */ b("div", { className: `superdoc-esign-container ${te || ""}`, style: ne, children: [
372
+ /* @__PURE__ */ b("div", { className: "superdoc-esign-document", "data-testid": "superdoc-esign-document", children: [
373
+ J && /* @__PURE__ */ d("div", { className: "superdoc-esign-document-toolbar", children: /* @__PURE__ */ d("div", { className: "superdoc-esign-document-controls", children: J }) }),
374
+ /* @__PURE__ */ d(
375
+ "div",
350
376
  {
351
- onClick: te,
352
- isValid: S,
353
- isDisabled: f,
354
- isSubmitting: h
377
+ ref: F,
378
+ className: "superdoc-esign-document-viewer",
379
+ "data-testid": "superdoc-scroll-container",
380
+ style: { height: oe, overflow: "auto" }
355
381
  }
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";
382
+ )
383
+ ] }),
384
+ /* @__PURE__ */ b("div", { className: "superdoc-esign-controls", "data-testid": "superdoc-esign-controls", children: [
385
+ r.signer && r.signer.length > 0 && /* @__PURE__ */ d("div", { className: "superdoc-esign-fields", "data-testid": "superdoc-esign-fields", children: r.signer.map(le) }),
386
+ ge
387
+ ] })
388
+ ] });
389
+ });
390
+ De.displayName = "SuperDocESign";
402
391
  export {
403
- ue as CheckboxInput,
404
- de as SignatureInput,
405
- me as default,
406
- le as textToImageDataUrl
392
+ xe as CheckboxInput,
393
+ we as SignatureInput,
394
+ De as default,
395
+ be as textToImageDataUrl
407
396
  };
@@ -1,4 +1,6 @@
1
1
  export declare const resetAuditEvents: () => void;
2
2
  export declare const recordAuditEvent: (type: string, data?: Record<string, unknown>) => void;
3
3
  export declare const getAuditEventTypes: () => string[];
4
+ export declare const getLastConstructorOptions: () => any;
5
+ export declare const resetLastConstructorOptions: () => void;
4
6
  //# sourceMappingURL=setup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAQ1C,eAAO,MAAM,gBAAgB,YAE5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAE5E,CAAC;AAEF,eAAO,MAAM,kBAAkB,gBAA+C,CAAC"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAQ1C,eAAO,MAAM,gBAAgB,YAE5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAE5E,CAAC;AAEF,eAAO,MAAM,kBAAkB,gBAA+C,CAAC;AAoD/E,eAAO,MAAM,yBAAyB,WAA+B,CAAC;AACtE,eAAO,MAAM,2BAA2B,YAEvC,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- /** Value types for esign fields */
2
1
  export type FieldValue = string | boolean | number | null | undefined;
2
+ export type TableFieldValue = string[][];
3
3
  export interface FieldReference {
4
4
  id: string;
5
5
  }
6
6
  export interface DocumentField extends FieldReference {
7
- value: FieldValue;
7
+ type?: 'text' | 'table';
8
+ value: FieldValue | TableFieldValue;
8
9
  }
9
10
  export interface SignerField extends FieldReference {
10
11
  type: 'signature' | 'checkbox' | 'text';
@@ -59,15 +60,22 @@ export interface DocumentConfig {
59
60
  };
60
61
  };
61
62
  /**
63
+ * Document view options (recommended for SuperDoc > v1.6.x):
64
+ * - 'print': Fixed page width, displays document as it prints (default)
65
+ * - 'web': Content reflows to fit container width (mobile/accessibility)
66
+ */
67
+ viewOptions?: {
68
+ layout?: 'web' | 'print';
69
+ };
70
+ /**
71
+ * @deprecated Use `viewOptions: { layout: 'web' }` instead.
62
72
  * Document layout mode:
63
73
  * - 'paginated' (default): Fixed page width, shows page breaks
64
- * - 'responsive': 100% width, text reflows to fit container (useful for mobile/accessibility)
65
- * Note: 'responsive' takes precedence over pagination - pagination is ignored when layoutMode is 'responsive'
74
+ * - 'responsive': 100% width, text reflows to fit container
66
75
  */
67
76
  layoutMode?: 'responsive' | 'paginated';
68
77
  /**
69
- * Custom margins in pixels for responsive layout mode.
70
- * Only applies when layoutMode is 'responsive'.
78
+ * @deprecated No longer supported in v1.x. Use CSS for margin control.
71
79
  */
72
80
  layoutMargins?: LayoutMargins;
73
81
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3D,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.2",
3
+ "version": "2.1.0-next.4",
4
4
  "description": "React eSignature component for SuperDoc",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",