@sajn/embed-react 0.1.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.
@@ -0,0 +1,10 @@
1
+ export type CssVars = {
2
+ /** Page background color */
3
+ background?: string | null;
4
+ /** Primary action/button color (brand color) */
5
+ primary?: string | null;
6
+ /** Main text color (for dark theme support) */
7
+ foreground?: string | null;
8
+ /** Secondary/muted text color */
9
+ mutedForeground?: string | null;
10
+ };
@@ -0,0 +1 @@
1
+ export { default as EmbedSignDocument } from './sign-document';
@@ -0,0 +1 @@
1
+ export { default as EmbedSignDocument } from './sign-document';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),a=require("react");function d(e){const c=a.useRef(null);function o(){const n=e.host||"https://app.sajn.se",s=btoa(encodeURIComponent(JSON.stringify({name:e.name,css:e.css,cssVars:e.cssVars,allowDocumentRejection:e.allowDocumentRejection,...e.additionalProps})));return`${new URL(`/embed/sign/${e.documentId}?token=${e.token}`,n)}#${s}`}const t=a.useCallback(n=>{if(c.current?.contentWindow===n.source)switch(n.data.action){case"document-ready":e.onDocumentReady?.();break;case"signer-completed":e.onSignerCompleted?.(n.data.data);break;case"document-error":e.onDocumentError?.(n.data.data);break;case"signer-rejected":e.onSignerRejected?.(n.data.data);break}},[e.onDocumentReady,e.onSignerCompleted,e.onDocumentError,e.onSignerRejected]);return a.useEffect(()=>(window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}),[t]),r.jsx("iframe",{ref:c,className:e.className,src:o()})}exports.EmbedSignDocument=d;
package/dist/index.mjs ADDED
@@ -0,0 +1,45 @@
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { useRef as r, useCallback as d, useEffect as i } from "react";
3
+ function f(e) {
4
+ const a = r(null);
5
+ function c() {
6
+ const n = e.host || "https://app.sajn.se", o = btoa(
7
+ encodeURIComponent(
8
+ JSON.stringify({
9
+ name: e.name,
10
+ css: e.css,
11
+ cssVars: e.cssVars,
12
+ allowDocumentRejection: e.allowDocumentRejection,
13
+ ...e.additionalProps
14
+ })
15
+ )
16
+ );
17
+ return `${new URL(`/embed/sign/${e.documentId}?token=${e.token}`, n)}#${o}`;
18
+ }
19
+ const t = d(
20
+ (n) => {
21
+ if (a.current?.contentWindow === n.source)
22
+ switch (n.data.action) {
23
+ case "document-ready":
24
+ e.onDocumentReady?.();
25
+ break;
26
+ case "signer-completed":
27
+ e.onSignerCompleted?.(n.data.data);
28
+ break;
29
+ case "document-error":
30
+ e.onDocumentError?.(n.data.data);
31
+ break;
32
+ case "signer-rejected":
33
+ e.onSignerRejected?.(n.data.data);
34
+ break;
35
+ }
36
+ },
37
+ [e.onDocumentReady, e.onSignerCompleted, e.onDocumentError, e.onSignerRejected]
38
+ );
39
+ return i(() => (window.addEventListener("message", t), () => {
40
+ window.removeEventListener("message", t);
41
+ }), [t]), /* @__PURE__ */ s("iframe", { ref: a, className: e.className, src: c() });
42
+ }
43
+ export {
44
+ f as EmbedSignDocument
45
+ };
@@ -0,0 +1,31 @@
1
+ import { CssVars } from './css-vars';
2
+ export type EmbedSignDocumentProps = {
3
+ className?: string;
4
+ host?: string;
5
+ token: string;
6
+ documentId: string;
7
+ css?: string | undefined;
8
+ cssVars?: (CssVars & Record<string, string>) | undefined;
9
+ name?: string | undefined;
10
+ allowDocumentRejection?: boolean | undefined;
11
+ additionalProps?: Record<string, string | number | boolean> | undefined;
12
+ onDocumentReady?: () => void;
13
+ onSignerCompleted?: (data: {
14
+ token: string;
15
+ documentId: number;
16
+ signerId: number;
17
+ failed?: string;
18
+ }) => void;
19
+ onDocumentError?: (data: {
20
+ code: string;
21
+ message: string;
22
+ }) => void;
23
+ onSignerRejected?: (data: {
24
+ token: string;
25
+ documentId: number;
26
+ signerId: number;
27
+ reason: string;
28
+ }) => void;
29
+ };
30
+ declare function EmbedSignDocument(props: EmbedSignDocumentProps): import("react/jsx-runtime").JSX.Element;
31
+ export default EmbedSignDocument;
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@sajn/embed-react",
3
+ "version": "0.1.1",
4
+ "description": "React component for embedding sajn e-signature functionality",
5
+ "homepage": "https://github.com/sajn-se/embeds#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/sajn-se/embeds/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/sajn-se/embeds.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "sajn",
15
+ "type": "commonjs",
16
+ "exports": {
17
+ "./package.json": "./package.json",
18
+ ".": {
19
+ "import": {
20
+ "types": "./dist/index.d.mts",
21
+ "default": "./dist/index.mjs"
22
+ },
23
+ "require": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ }
28
+ },
29
+ "main": "dist/index.js",
30
+ "types": "dist/index.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "build": "vite build",
36
+ "clean": "rimraf node_modules && rimraf dist",
37
+ "check-exports": "attw --pack .",
38
+ "publint": "publint"
39
+ },
40
+ "devDependencies": {
41
+ "@types/react": "^18.0.0 || ^19.0.0",
42
+ "@vitejs/plugin-react": "^5.0.0",
43
+ "vite": "^7.0.0",
44
+ "vite-plugin-dts": "^4.1.0"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^18.0.0 || ^19.0.0",
48
+ "react-dom": "^18.0.0 || ^19.0.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "module": "dist/index.mjs"
54
+ }