@superdoc-dev/esign 1.4.2 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +11 -11
- package/dist/__tests__/signature.test.d.ts +2 -0
- package/dist/__tests__/signature.test.d.ts.map +1 -0
- package/dist/defaults/DownloadButton.d.ts.map +1 -1
- package/dist/defaults/SubmitButton.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +299 -216
- package/dist/types.d.ts +23 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/signature.d.ts +2 -0
- package/dist/utils/signature.d.ts.map +1 -0
- package/package.json +3 -4
- package/src/styles.css +26 -0
package/README.md
CHANGED
|
@@ -37,22 +37,22 @@ function App() {
|
|
|
37
37
|
|
|
38
38
|
fields={{
|
|
39
39
|
document: [
|
|
40
|
-
{ id: '
|
|
41
|
-
{ id: '
|
|
42
|
-
{ id: '
|
|
43
|
-
{ id: '
|
|
44
|
-
{ id: '
|
|
45
|
-
{ id: '
|
|
40
|
+
{ id: '1', value: 'John Doe' },
|
|
41
|
+
{ id: '2', value: new Date().toLocaleDateString() },
|
|
42
|
+
{ id: '3', value: 'SuperDoc' },
|
|
43
|
+
{ id: '4', value: 'Premium' },
|
|
44
|
+
{ id: '5', value: 'CA' },
|
|
45
|
+
{ id: '6', value: '123 Main St, Anytown, USA' }
|
|
46
46
|
],
|
|
47
47
|
signer: [
|
|
48
48
|
{
|
|
49
|
-
id: '
|
|
49
|
+
id: '7',
|
|
50
50
|
type: 'signature',
|
|
51
51
|
validation: { required: true },
|
|
52
52
|
label: 'Type your full name'
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
id: '
|
|
55
|
+
id: '8',
|
|
56
56
|
type: 'checkbox',
|
|
57
57
|
validation: { required: true },
|
|
58
58
|
label: 'I accept the terms'
|
|
@@ -118,11 +118,11 @@ See [Python, Node.js, and more examples](https://docs.superdoc.dev/solutions/esi
|
|
|
118
118
|
timestamp: "2024-01-15T10:30:00Z",
|
|
119
119
|
duration: 45000,
|
|
120
120
|
documentFields: [
|
|
121
|
-
{ id: "
|
|
121
|
+
{ id: "1", value: "John Doe" }
|
|
122
122
|
],
|
|
123
123
|
signerFields: [
|
|
124
|
-
{ id: "
|
|
125
|
-
{ id: "
|
|
124
|
+
{ id: "7", value: "John Doe" },
|
|
125
|
+
{ id: "8", value: true }
|
|
126
126
|
],
|
|
127
127
|
auditTrail: [
|
|
128
128
|
{ type: "ready", timestamp: "..." },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/signature.test.ts"],"names":[],"mappings":""}
|
|
@@ -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,kCAuC3D,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,gCAsCvD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { textToImageDataUrl } from './utils/signature';
|
|
1
2
|
import { SignatureInput, CheckboxInput } from './defaults';
|
|
2
3
|
import type * as Types from './types';
|
|
3
4
|
export * from './types';
|
|
5
|
+
export { textToImageDataUrl };
|
|
4
6
|
export { SignatureInput, CheckboxInput };
|
|
5
7
|
declare const SuperDocESign: import('react').ForwardRefExoticComponent<Types.SuperDocESignProps & import('react').RefAttributes<Types.SuperDocESignHandle>>;
|
|
6
8
|
export default SuperDocESign;
|
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,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAIzC,QAAA,MAAM,aAAa,gIAuflB,CAAC;AAIF,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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;
|