@sajn/embed-react 0.1.4 → 0.1.6

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/index.d.mts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { default as EmbedSignDocument } from './sign-document';
2
2
  export type { Language, EmbedSignDocumentProps } from './sign-document';
3
+ export { default as EmbedViewDocument } from './view-document';
4
+ export type { EmbedViewDocumentProps } from './view-document';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { default as EmbedSignDocument } from './sign-document';
2
2
  export type { Language, EmbedSignDocumentProps } from './sign-document';
3
+ export { default as EmbedViewDocument } from './view-document';
4
+ export type { EmbedViewDocumentProps } from './view-document';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=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",r=btoa(encodeURIComponent(JSON.stringify({language:e.language??"en",cssVars:e.cssVars,allowDocumentRejection:e.allowDocumentRejection,...e.additionalProps})));return`${new URL(`/embed/sign/${e.documentId}?token=${e.token}`,n)}#${r}`}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]),s.jsx("iframe",{ref:c,className:e.className,src:o()})}exports.EmbedSignDocument=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),c=require("react");function d(e){const t=c.useRef(null);function o(){const n=e.host||"https://app.sajn.se",s=btoa(encodeURIComponent(JSON.stringify({language:e.language??"en",cssVars:e.cssVars,allowDocumentRejection:e.allowDocumentRejection,showScrollIndicator:e.showScrollIndicator??!0,...e.additionalProps})));return`${new URL(`/embed/sign/${e.documentId}?token=${e.token}`,n)}#${s}`}const a=c.useCallback(n=>{if(t.current?.contentWindow===n.source)switch(n.data.action){case"document-ready":t.current?.contentWindow?.postMessage({action:"embed-init"},new URL(e.host||"https://app.sajn.se").origin),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.host,e.onDocumentReady,e.onSignerCompleted,e.onDocumentError,e.onSignerRejected]);return c.useEffect(()=>(window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}),[a]),r.jsx("iframe",{ref:t,className:e.className,src:o()})}function u(e){const t=c.useRef(null);function o(){const n=e.host||"https://app.sajn.se",s=btoa(encodeURIComponent(JSON.stringify({language:e.language??"en",cssVars:e.cssVars,showScrollIndicator:e.showScrollIndicator??!0,...e.additionalProps})));return`${new URL(`/embed/view/${e.documentId}?token=${e.token}`,n)}#${s}`}const a=c.useCallback(n=>{if(t.current?.contentWindow===n.source)switch(n.data.action){case"document-ready":t.current?.contentWindow?.postMessage({action:"embed-init"},new URL(e.host||"https://app.sajn.se").origin),e.onDocumentReady?.();break;case"document-error":e.onDocumentError?.(n.data.data);break}},[e.host,e.onDocumentReady,e.onDocumentError]);return c.useEffect(()=>(window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}),[a]),r.jsx("iframe",{ref:t,className:e.className,src:o()})}exports.EmbedSignDocument=d;exports.EmbedViewDocument=u;
package/dist/index.mjs CHANGED
@@ -1,26 +1,30 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { useRef as d, useCallback as s, useEffect as i } from "react";
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { useRef as r, useCallback as d, useEffect as i } from "react";
3
3
  function g(e) {
4
- const a = d(null);
5
- function c() {
6
- const n = e.host || "https://app.sajn.se", o = btoa(
4
+ const t = r(null);
5
+ function o() {
6
+ const n = e.host || "https://app.sajn.se", c = btoa(
7
7
  encodeURIComponent(
8
8
  JSON.stringify({
9
9
  language: e.language ?? "en",
10
10
  cssVars: e.cssVars,
11
11
  allowDocumentRejection: e.allowDocumentRejection,
12
+ showScrollIndicator: e.showScrollIndicator ?? !0,
12
13
  ...e.additionalProps
13
14
  })
14
15
  )
15
16
  );
16
- return `${new URL(`/embed/sign/${e.documentId}?token=${e.token}`, n)}#${o}`;
17
+ return `${new URL(`/embed/sign/${e.documentId}?token=${e.token}`, n)}#${c}`;
17
18
  }
18
- const t = s(
19
+ const a = d(
19
20
  (n) => {
20
- if (a.current?.contentWindow === n.source)
21
+ if (t.current?.contentWindow === n.source)
21
22
  switch (n.data.action) {
22
23
  case "document-ready":
23
- e.onDocumentReady?.();
24
+ t.current?.contentWindow?.postMessage(
25
+ { action: "embed-init" },
26
+ new URL(e.host || "https://app.sajn.se").origin
27
+ ), e.onDocumentReady?.();
24
28
  break;
25
29
  case "signer-completed":
26
30
  e.onSignerCompleted?.(n.data.data);
@@ -33,12 +37,49 @@ function g(e) {
33
37
  break;
34
38
  }
35
39
  },
36
- [e.onDocumentReady, e.onSignerCompleted, e.onDocumentError, e.onSignerRejected]
40
+ [e.host, e.onDocumentReady, e.onSignerCompleted, e.onDocumentError, e.onSignerRejected]
37
41
  );
38
- return i(() => (window.addEventListener("message", t), () => {
39
- window.removeEventListener("message", t);
40
- }), [t]), /* @__PURE__ */ r("iframe", { ref: a, className: e.className, src: c() });
42
+ return i(() => (window.addEventListener("message", a), () => {
43
+ window.removeEventListener("message", a);
44
+ }), [a]), /* @__PURE__ */ s("iframe", { ref: t, className: e.className, src: o() });
45
+ }
46
+ function w(e) {
47
+ const t = r(null);
48
+ function o() {
49
+ const n = e.host || "https://app.sajn.se", c = btoa(
50
+ encodeURIComponent(
51
+ JSON.stringify({
52
+ language: e.language ?? "en",
53
+ cssVars: e.cssVars,
54
+ showScrollIndicator: e.showScrollIndicator ?? !0,
55
+ ...e.additionalProps
56
+ })
57
+ )
58
+ );
59
+ return `${new URL(`/embed/view/${e.documentId}?token=${e.token}`, n)}#${c}`;
60
+ }
61
+ const a = d(
62
+ (n) => {
63
+ if (t.current?.contentWindow === n.source)
64
+ switch (n.data.action) {
65
+ case "document-ready":
66
+ t.current?.contentWindow?.postMessage(
67
+ { action: "embed-init" },
68
+ new URL(e.host || "https://app.sajn.se").origin
69
+ ), e.onDocumentReady?.();
70
+ break;
71
+ case "document-error":
72
+ e.onDocumentError?.(n.data.data);
73
+ break;
74
+ }
75
+ },
76
+ [e.host, e.onDocumentReady, e.onDocumentError]
77
+ );
78
+ return i(() => (window.addEventListener("message", a), () => {
79
+ window.removeEventListener("message", a);
80
+ }), [a]), /* @__PURE__ */ s("iframe", { ref: t, className: e.className, src: o() });
41
81
  }
42
82
  export {
43
- g as EmbedSignDocument
83
+ g as EmbedSignDocument,
84
+ w as EmbedViewDocument
44
85
  };
@@ -8,12 +8,13 @@ export type EmbedSignDocumentProps = {
8
8
  documentId: string;
9
9
  cssVars?: (CssVars & Record<string, string>) | undefined;
10
10
  allowDocumentRejection?: boolean | undefined;
11
+ showScrollIndicator?: boolean | undefined;
11
12
  additionalProps?: Record<string, string | number | boolean> | undefined;
12
13
  onDocumentReady?: () => void;
13
14
  onSignerCompleted?: (data: {
14
15
  token: string;
15
- documentId: number;
16
- signerId: number;
16
+ documentId: string;
17
+ signerId: string;
17
18
  failed?: string;
18
19
  }) => void;
19
20
  onDocumentError?: (data: {
@@ -22,8 +23,8 @@ export type EmbedSignDocumentProps = {
22
23
  }) => void;
23
24
  onSignerRejected?: (data: {
24
25
  token: string;
25
- documentId: number;
26
- signerId: number;
26
+ documentId: string;
27
+ signerId: string;
27
28
  reason: string;
28
29
  }) => void;
29
30
  };
@@ -0,0 +1,19 @@
1
+ import { CssVars } from './css-vars';
2
+ export type Language = 'sv' | 'en' | 'no' | 'da' | 'fi' | 'de' | 'is' | 'es' | 'fr' | 'it';
3
+ export type EmbedViewDocumentProps = {
4
+ language?: Language;
5
+ className?: string;
6
+ host?: string;
7
+ token: string;
8
+ documentId: string;
9
+ cssVars?: (CssVars & Record<string, string>) | undefined;
10
+ showScrollIndicator?: boolean | undefined;
11
+ additionalProps?: Record<string, string | number | boolean> | undefined;
12
+ onDocumentReady?: () => void;
13
+ onDocumentError?: (data: {
14
+ code: string;
15
+ message: string;
16
+ }) => void;
17
+ };
18
+ declare function EmbedViewDocument(props: EmbedViewDocumentProps): import("react/jsx-runtime").JSX.Element;
19
+ export default EmbedViewDocument;
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
1
  {
2
- "name": "@sajn/embed-react",
3
- "version": "0.1.4",
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
- }
2
+ "name": "@sajn/embed-react",
3
+ "version": "0.1.6",
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
+ "devDependencies": {
35
+ "@types/react": "^18.0.0 || ^19.0.0",
36
+ "@vitejs/plugin-react": "^5.0.0",
37
+ "vite": "^7.0.0",
38
+ "vite-plugin-dts": "^4.1.0"
39
+ },
40
+ "peerDependencies": {
41
+ "react": "^18.0.0 || ^19.0.0",
42
+ "react-dom": "^18.0.0 || ^19.0.0"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "module": "dist/index.mjs",
48
+ "scripts": {
49
+ "build": "vite build",
50
+ "clean": "rimraf node_modules && rimraf dist",
51
+ "check-exports": "attw --pack .",
52
+ "publint": "publint"
53
+ }
54
+ }