@superdoc-dev/esign 1.4.0-next.2 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/defaults/DownloadButton.d.ts.map +1 -1
- package/dist/defaults/SubmitButton.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +211 -257
- package/dist/types.d.ts +0 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/styles.css +0 -26
- package/LICENSE +0 -661
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DownloadButton.d.ts","sourceRoot":"","sources":["../../src/defaults/DownloadButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEpE,eAAO,MAAM,oBAAoB,GAAI,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"DownloadButton.d.ts","sourceRoot":"","sources":["../../src/defaults/DownloadButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEpE,eAAO,MAAM,oBAAoB,GAAI,SAAS,cAAc,kCA2B3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubmitButton.d.ts","sourceRoot":"","sources":["../../src/defaults/SubmitButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAAI,SAAS,YAAY,
|
|
1
|
+
{"version":3,"file":"SubmitButton.d.ts","sourceRoot":"","sources":["../../src/defaults/SubmitButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAAI,SAAS,YAAY,gCAkCvD,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AACtC,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AACtC,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,gIAwblB,CAAC;AAIF,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var le=Object.create;var z=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var me=(c,d,u,s)=>{if(d&&typeof d=="object"||typeof d=="function")for(let n of de(d))!ge.call(c,n)&&n!==u&&z(c,n,{get:()=>d[n],enumerable:!(s=ue(d,n))||s.enumerable});return c};var fe=(c,d,u)=>(u=c!=null?le(pe(c)):{},me(d||!c||!c.__esModule?z(u,"default",{value:c,enumerable:!0}):u,c));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),i=require("react"),L=({value:c,onChange:d,isDisabled:u,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(c||""),onChange:n=>d(n.target.value),disabled:u,placeholder:"Type your full name",style:{fontFamily:"cursive",fontSize:"18px"}})]}),P=({value:c,onChange:d,isDisabled:u,label:s})=>l.jsxs("label",{className:"superdoc-esign-checkbox-input",style:{display:"flex",gap:"8px"},children:[l.jsx("input",{type:"checkbox",checked:!!c,onChange:n=>d(n.target.checked),disabled:u}),l.jsx("span",{children:s})]}),he=c=>({onClick:u,fileName:s,isDisabled:n})=>{const g=c?.label||"Download";return l.jsxs("button",{onClick:u,disabled:n,className:"superdoc-esign-btn superdoc-esign-btn--download",style:{padding:"8px 16px",borderRadius:"6px",border:"1px solid #d0d5dd",background:"#ffffff",color:"#333",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,fontSize:"16px",fontWeight:"bold"},children:[g," ",s&&`(${s})`]})},ve=c=>({onClick:u,isValid:s,isDisabled:n,isSubmitting:g})=>{const C=()=>c?.label||"Submit";return l.jsx("button",{onClick:u,disabled:!s||n||g,className:"superdoc-esign-btn superdoc-esign-btn--submit",style:{padding:"12px 24px",borderRadius:"6px",border:"none",background:"#007bff",color:"#fff",cursor:!s||n?"not-allowed":"pointer",opacity:!s||n?.5:1,fontSize:"16px",fontWeight:"bold"},children:C()})},W=i.forwardRef((c,d)=>{const{eventId:u,document:s,fields:n={},download:g,submit:C,onSubmit:R,onDownload:k,onStateChange:E,onFieldChange:T,onFieldsDiscovered:N,isDisabled:f=!1,className:$,style:K,documentHeight:X="600px"}=c,[x,F]=i.useState(!s.validation?.scroll?.required),[p,M]=i.useState(new Map),[b,I]=i.useState(!1),[h,A]=i.useState(!1),[q,_]=i.useState([]),[B,Y]=i.useState(!1),w=i.useRef(null),D=i.useRef(null),G=i.useRef(Date.now()),v=i.useRef(n),y=i.useRef([]),U=i.useRef(N);v.current=n,U.current=N,i.useEffect(()=>{y.current=q},[q]);const j=i.useCallback(e=>{if(!D.current?.activeEditor)return;const t=D.current.activeEditor,r=v.current.signer?.find(o=>o.id===e.id);let a;r?.type==="signature"&&e.value?a={json:{type:"image",attrs:{src:typeof e.value=="string"&&e.value.startsWith("data:image/")?e.value:J(String(e.value)),alt:"Signature"}}}:a={text:String(e.value??"")},e.id&&t.commands.updateStructuredContentById(e.id,a)},[]);function J(e){const t=globalThis.document.createElement("canvas"),r=t.getContext("2d"),a=30;r.font=`italic ${a}px cursive`;const m=r.measureText(e).width,ie=a*1.3,ae=4,ce=6;return t.width=Math.ceil(m+ae*2)+20,t.height=Math.ceil(ie+ce*2),r.font=`italic ${a}px cursive`,r.fillStyle="black",r.textAlign="center",r.textBaseline="middle",r.fillText(e,t.width/2,t.height/2),t.toDataURL("image/png")}const V=i.useCallback(e=>{if(!e)return;const t=e.helpers.structuredContentCommands.getStructuredContentTags(e.state),r=new Map;v.current.document?.forEach(o=>{o.id&&r.set(o.id,o.value)}),v.current.signer?.forEach(o=>{o.value!==void 0&&r.set(o.id,o.value)});const a=t.map(({node:o})=>({id:o.attrs.id,label:o.attrs.label,value:r.get(o.attrs.id)??o.textContent??""})).filter(o=>o.id);a.length>0&&(U.current?.(a),[...v.current.document||[],...v.current.signer||[]].filter(m=>m.value!==void 0).forEach(m=>j({id:m.id,value:m.value})))},[j]),S=e=>{const t={...e,timestamp:new Date().toISOString()},r=globalThis?.__SUPERDOC_AUDIT_MOCK__;r&&r(t);const a=[...y.current,t];return y.current=a,_(a),a};i.useEffect(()=>{if(!w.current)return;let e=!1,t=null;return(async()=>{const{SuperDoc:a}=await import("superdoc");e||(t=new a({selector:w.current,document:s.source,documentMode:"viewing",modules:{comments:!1},onReady:()=>{e||(t?.activeEditor&&V(t.activeEditor),S({type:"ready"}),Y(!0))}}),D.current=t)})(),()=>{e=!0,t&&typeof t.destroy=="function"&&t.destroy(),D.current=null}},[s.source,s.mode,V]),i.useEffect(()=>{if(!s.validation?.scroll?.required||!B)return;const e=w.current;if(!e)return;const t=()=>{const{scrollTop:r,scrollHeight:a,clientHeight:o}=e,m=r/(a-o);(m>=.95||a<=o)&&(F(!0),S({type:"scroll",data:{percent:Math.round(m*100)}}))};return e.addEventListener("scroll",t),t(),()=>e.removeEventListener("scroll",t)},[s.validation?.scroll?.required,B]);const Q=i.useCallback((e,t)=>{M(r=>{const a=r.get(e),o=new Map(r);return o.set(e,t),j({id:e,value:t}),S({type:"field_change",data:{fieldId:e,value:t,previousValue:a}}),T?.({id:e,value:t,previousValue:a}),o})},[T,j]),H=i.useCallback(()=>s.validation?.scroll?.required&&!x?!1:(n.signer||[]).every(e=>{if(!e.validation?.required)return!0;const t=p.get(e.id);return t&&(typeof t!="string"||t.trim())}),[x,n.signer,p,s.validation?.scroll?.required]);i.useEffect(()=>{const e=H();I(e),E?.({scrolled:x,fields:p,isValid:e,isSubmitting:h})},[x,p,h,H,E]);const Z=i.useCallback(async()=>{if(f)return;const e={eventId:u,documentSource:s.source,fields:{document:n.document||[],signer:(n.signer||[]).map(t=>({id:t.id,value:p.get(t.id)??null}))},fileName:g?.fileName||"document.pdf"};await k?.(e)},[f,u,s.source,n,p,g,k]),ee=i.useCallback(async()=>{if(!b||f||h)return;A(!0),S({type:"submit"});const e=S({type:"submit"}),t={eventId:u,timestamp:new Date().toISOString(),duration:Math.floor((Date.now()-G.current)/1e3),auditTrail:e,documentFields:n.document||[],signerFields:(n.signer||[]).map(r=>({id:r.id,value:p.get(r.id)??null})),isFullyCompleted:b};try{await R(t)}finally{A(!1)}},[b,f,h,u,n,p,R]),te=e=>{const t=e.component||ne(e.type);return l.jsx(t,{value:p.get(e.id)??null,onChange:r=>Q(e.id,r),isDisabled:f,label:e.label},e.id)},ne=e=>{switch(e){case"signature":case"text":return L;case"checkbox":return P}},se=()=>{const e=g?.component||he(g);return e?l.jsx(e,{onClick:Z,fileName:g?.fileName,isDisabled:f}):null},re=()=>{if(s.mode==="download")return null;const e=C?.component||ve(C);return l.jsx("div",{className:"superdoc-esign-actions superdoc-esign-form-actions",children:l.jsx(e,{onClick:ee,isValid:b,isDisabled:f,isSubmitting:h})})},O=se(),oe=re();return i.useImperativeHandle(d,()=>({getState:()=>({scrolled:x,fields:p,isValid:b,isSubmitting:h}),getAuditTrail:()=>y.current,reset:()=>{F(!s.validation?.scroll?.required),M(new Map),I(!1),y.current=[],_([])}})),l.jsxs("div",{className:`superdoc-esign-container ${$||""}`,style:K,children:[l.jsxs("div",{className:"superdoc-esign-document","data-testid":"superdoc-esign-document",children:[O&&l.jsx("div",{className:"superdoc-esign-document-toolbar",children:l.jsx("div",{className:"superdoc-esign-document-controls",children:O})}),l.jsx("div",{ref:w,className:"superdoc-esign-document-viewer","data-testid":"superdoc-scroll-container",style:{height:X,overflow:"auto"}})]}),l.jsxs("div",{className:"superdoc-esign-controls","data-testid":"superdoc-esign-controls",children:[n.signer&&n.signer.length>0&&l.jsx("div",{className:"superdoc-esign-fields","data-testid":"superdoc-esign-fields",children:n.signer.map(te)}),oe]})]})});W.displayName="SuperDocESign";exports.CheckboxInput=P;exports.SignatureInput=L;exports.default=W;
|