docuseal-svelte 0.1.0 → 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.
@@ -122,7 +122,6 @@
122
122
  const scriptId = "docuseal-builder-script"
123
123
  const scriptSrc = `https://${host}/js/builder.js`
124
124
 
125
- // Check if script already exists
126
125
  const existingScript = document.getElementById(scriptId)
127
126
  if (existingScript) {
128
127
  resolve()
@@ -148,50 +147,26 @@
148
147
  }
149
148
 
150
149
  const setupEventListeners = (element: HTMLElement): (() => void) => {
151
- const handleLoad = (e: Event) => {
152
- if (onLoad && e instanceof CustomEvent) {
153
- onLoad(e.detail)
154
- }
155
- }
156
-
157
- const handleUpload = (e: Event) => {
158
- if (onUpload && e instanceof CustomEvent) {
159
- onUpload(e.detail)
160
- }
150
+ const handlers: Record<string, ((detail: any) => void) | undefined> = {
151
+ load: onLoad,
152
+ upload: onUpload,
153
+ send: onSend,
154
+ save: onSave,
155
+ change: onChange,
161
156
  }
162
157
 
163
- const handleSend = (e: Event) => {
164
- if (onSend && e instanceof CustomEvent) {
165
- onSend(e.detail)
166
- }
167
- }
168
-
169
- const handleSave = (e: Event) => {
170
- if (onSave && e instanceof CustomEvent) {
171
- onSave(e.detail)
172
- }
173
- }
174
-
175
- const handleChange = (e: Event) => {
176
- if (onChange && e instanceof CustomEvent) {
177
- onChange(e.detail)
158
+ const removers = Object.entries(handlers).map(([eventName, handler]) => {
159
+ const listener = (e: Event) => {
160
+ if (handler && e instanceof CustomEvent) {
161
+ handler(e.detail)
162
+ }
178
163
  }
179
- }
180
164
 
181
- element.addEventListener("load", handleLoad)
182
- element.addEventListener("upload", handleUpload)
183
- element.addEventListener("send", handleSend)
184
- element.addEventListener("save", handleSave)
185
- element.addEventListener("change", handleChange)
165
+ element.addEventListener(eventName, listener)
166
+ return () => element.removeEventListener(eventName, listener)
167
+ })
186
168
 
187
- // Return cleanup function
188
- return () => {
189
- element.removeEventListener("load", handleLoad)
190
- element.removeEventListener("upload", handleUpload)
191
- element.removeEventListener("send", handleSend)
192
- element.removeEventListener("save", handleSave)
193
- element.removeEventListener("change", handleChange)
194
- }
169
+ return () => removers.forEach((remove) => remove())
195
170
  }
196
171
 
197
172
  const asDocuSealError = (error: unknown): DocuSealError =>
@@ -77,32 +77,25 @@
77
77
  document.head.appendChild(script)
78
78
  }
79
79
 
80
- const handleCompleted = (e: Event) =>
81
- onComplete && onComplete((e as CustomEvent).detail)
82
- const handleInit = (e: Event) => onInit && onInit((e as CustomEvent).detail)
83
- const handleDecline = (e: Event) =>
84
- onDecline && onDecline((e as CustomEvent).detail)
85
- const handleLoad = (e: Event) => onLoad && onLoad((e as CustomEvent).detail)
86
- const handleError = (e: Event) =>
87
- onError && onError((e as CustomEvent).detail)
88
-
89
- if (el) {
90
- el.addEventListener("completed", handleCompleted)
91
- el.addEventListener("init", handleInit)
92
- el.addEventListener("declined", handleDecline)
93
- el.addEventListener("load", handleLoad)
94
- el.addEventListener("error", handleError)
80
+ const handlers: Record<string, ((detail: any) => void) | undefined> = {
81
+ completed: onComplete,
82
+ init: onInit,
83
+ declined: onDecline,
84
+ load: onLoad,
85
+ error: onError,
95
86
  }
96
87
 
97
- return () => {
98
- if (el) {
99
- el.removeEventListener("completed", handleCompleted)
100
- el.removeEventListener("init", handleInit)
101
- el.removeEventListener("declined", handleDecline)
102
- el.removeEventListener("load", handleLoad)
103
- el.removeEventListener("error", handleError)
104
- }
105
- }
88
+ const element = el
89
+ if (!element) return
90
+
91
+ const removers = Object.entries(handlers).map(([eventName, handler]) => {
92
+ const listener = (e: Event) => handler && handler((e as CustomEvent).detail)
93
+
94
+ element.addEventListener(eventName, listener)
95
+ return () => element.removeEventListener(eventName, listener)
96
+ })
97
+
98
+ return () => removers.forEach((remove) => remove())
106
99
  })
107
100
  </script>
108
101
 
@@ -1,4 +1,4 @@
1
- import type { DocuSealFormField } from "../types/index.ts";
1
+ import type { DocuSealFormField } from "../types/index.js";
2
2
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
3
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
4
  $$bindings?: Bindings;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { default as DocuSealForm } from './components/DocuSealForm.svelte';
2
- export { default as DocuSealBuilder } from './components/DocuSealBuilder.svelte';
3
- export type { DocuSealFormProps, DocuSealFormField, DocuSealBuilderField, DocuSealBuilderSubmitter, } from './types/index.js';
4
- export { isValidDocuSealUrl, buildFormUrl, DocuSealEventType, DocuSealError } from './utils/docuseal.js';
1
+ export { default as DocuSealForm } from "./components/DocuSealForm.svelte";
2
+ export { default as DocuSealBuilder } from "./components/DocuSealBuilder.svelte";
3
+ export type { DocuSealFormProps, DocuSealFormField, DocuSealBuilderField, DocuSealBuilderSubmitter, } from "./types/index.js";
4
+ export { isValidDocuSealUrl, buildFormUrl, DocuSealEventType, DocuSealError, } from "./utils/docuseal.js";
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // Reexport your entry components here
2
- // Re-export components
3
- export { default as DocuSealForm } from './components/DocuSealForm.svelte';
4
- export { default as DocuSealBuilder } from './components/DocuSealBuilder.svelte';
5
- // Re-export utilities (optional - if you want users to access them)
6
- export { isValidDocuSealUrl, buildFormUrl, DocuSealEventType, DocuSealError } from './utils/docuseal.js';
1
+ export { default as DocuSealForm } from "./components/DocuSealForm.svelte";
2
+ export { default as DocuSealBuilder } from "./components/DocuSealBuilder.svelte";
3
+ export { isValidDocuSealUrl, buildFormUrl, DocuSealEventType, DocuSealError, } from "./utils/docuseal.js";
@@ -1,16 +1,10 @@
1
1
  export declare function isValidDocuSealUrl(url: string): boolean;
2
- /**
3
- * Builds a DocuSeal form URL with query parameters
4
- */
5
2
  export declare function buildFormUrl(baseUrl: string, params?: {
6
3
  email?: string;
7
4
  name?: string;
8
5
  phone?: string;
9
6
  [key: string]: string | undefined;
10
7
  }): string;
11
- /**
12
- * Message types from DocuSeal iframe
13
- */
14
8
  export declare enum DocuSealEventType {
15
9
  COMPLETED = "completed",
16
10
  DECLINED = "declined",
@@ -18,49 +12,8 @@ export declare enum DocuSealEventType {
18
12
  LOADED = "loaded",
19
13
  RESIZE = "resize"
20
14
  }
21
- /**
22
- * Type guard for DocuSeal messages
23
- */
24
- export declare function isDocuSealMessage(event: MessageEvent): boolean;
25
- /**
26
- * Parse DocuSeal postMessage events
27
- */
28
- export declare function parseDocuSealEvent(event: MessageEvent): {
29
- type: DocuSealEventType;
30
- data?: any;
31
- } | null;
32
- /**
33
- * Create an iframe element with DocuSeal configuration
34
- */
35
- export declare function createDocuSealIframe(src: string, options?: {
36
- title?: string;
37
- className?: string;
38
- allowFullscreen?: boolean;
39
- }): HTMLIFrameElement;
40
- /**
41
- * Send a message to DocuSeal iframe
42
- */
43
- export declare function sendToDocuSeal(iframe: HTMLIFrameElement | null, message: {
44
- type: string;
45
- data?: any;
46
- }): void;
47
- /**
48
- * Calculates optimal iframe height based on content
49
- */
50
- export declare function calculateIframeHeight(contentHeight?: number, minHeight?: number, maxHeight?: number): number;
51
- /**
52
- * Error types that can occur with DocuSeal
53
- */
54
15
  export declare class DocuSealError extends Error {
55
16
  code?: string | undefined;
56
17
  details?: any | undefined;
57
18
  constructor(message: string, code?: string | undefined, details?: any | undefined);
58
19
  }
59
- /**
60
- * Retry logic for failed operations
61
- */
62
- export declare function retryOperation<T>(operation: () => Promise<T>, maxRetries?: number, delayMs?: number): Promise<T>;
63
- /**
64
- * Prefetch DocuSeal resources for faster loading
65
- */
66
- export declare function prefetchDocuSeal(url: string): void;
@@ -1,7 +1,4 @@
1
- /**
2
- * Validates if a URL is a valid DocuSeal URL
3
- */
4
- const DOCUSEAL_DOMAINS = ['docuseal.co', 'docuseal.com'];
1
+ const DOCUSEAL_DOMAINS = ["docuseal.co", "docuseal.com", "docuseal.eu"];
5
2
  export function isValidDocuSealUrl(url) {
6
3
  try {
7
4
  const { hostname } = new URL(url);
@@ -11,9 +8,6 @@ export function isValidDocuSealUrl(url) {
11
8
  return false;
12
9
  }
13
10
  }
14
- /**
15
- * Builds a DocuSeal form URL with query parameters
16
- */
17
11
  export function buildFormUrl(baseUrl, params) {
18
12
  const url = new URL(baseUrl);
19
13
  if (params) {
@@ -25,9 +19,6 @@ export function buildFormUrl(baseUrl, params) {
25
19
  }
26
20
  return url.toString();
27
21
  }
28
- /**
29
- * Message types from DocuSeal iframe
30
- */
31
22
  export var DocuSealEventType;
32
23
  (function (DocuSealEventType) {
33
24
  DocuSealEventType["COMPLETED"] = "completed";
@@ -36,61 +27,6 @@ export var DocuSealEventType;
36
27
  DocuSealEventType["LOADED"] = "loaded";
37
28
  DocuSealEventType["RESIZE"] = "resize";
38
29
  })(DocuSealEventType || (DocuSealEventType = {}));
39
- /**
40
- * Type guard for DocuSeal messages
41
- */
42
- export function isDocuSealMessage(event) {
43
- return event.data?.source === 'docuseal' ||
44
- event.data?.type?.startsWith('docuseal.');
45
- }
46
- /**
47
- * Parse DocuSeal postMessage events
48
- */
49
- export function parseDocuSealEvent(event) {
50
- if (!isDocuSealMessage(event)) {
51
- return null;
52
- }
53
- const { type, data } = event.data;
54
- return { type, data };
55
- }
56
- /**
57
- * Create an iframe element with DocuSeal configuration
58
- */
59
- export function createDocuSealIframe(src, options) {
60
- const iframe = document.createElement('iframe');
61
- iframe.src = src;
62
- iframe.title = options?.title || 'DocuSeal Form';
63
- iframe.className = options?.className || '';
64
- iframe.setAttribute('frameborder', '0');
65
- iframe.setAttribute('allow', 'camera; microphone; clipboard-write');
66
- if (options?.allowFullscreen) {
67
- iframe.setAttribute('allowfullscreen', 'true');
68
- }
69
- iframe.style.width = '100%';
70
- iframe.style.height = '100%';
71
- return iframe;
72
- }
73
- /**
74
- * Send a message to DocuSeal iframe
75
- */
76
- export function sendToDocuSeal(iframe, message) {
77
- if (!iframe?.contentWindow) {
78
- console.warn('DocuSeal iframe not ready');
79
- return;
80
- }
81
- iframe.contentWindow.postMessage({ source: 'parent', ...message }, '*');
82
- }
83
- /**
84
- * Calculates optimal iframe height based on content
85
- */
86
- export function calculateIframeHeight(contentHeight, minHeight = 400, maxHeight = 1200) {
87
- if (!contentHeight)
88
- return minHeight;
89
- return Math.min(Math.max(contentHeight, minHeight), maxHeight);
90
- }
91
- /**
92
- * Error types that can occur with DocuSeal
93
- */
94
30
  export class DocuSealError extends Error {
95
31
  code;
96
32
  details;
@@ -98,33 +34,6 @@ export class DocuSealError extends Error {
98
34
  super(message);
99
35
  this.code = code;
100
36
  this.details = details;
101
- this.name = 'DocuSealError';
102
- }
103
- }
104
- /**
105
- * Retry logic for failed operations
106
- */
107
- export async function retryOperation(operation, maxRetries = 3, delayMs = 1000) {
108
- let lastError = new Error();
109
- for (let i = 0; i < maxRetries; i++) {
110
- try {
111
- return await operation();
112
- }
113
- catch (error) {
114
- lastError = error;
115
- if (i < maxRetries - 1) {
116
- await new Promise(resolve => setTimeout(resolve, delayMs * (i + 1)));
117
- }
118
- }
37
+ this.name = "DocuSealError";
119
38
  }
120
- throw new DocuSealError(`Operation failed after ${maxRetries} retries`, 'RETRY_EXCEEDED', lastError);
121
- }
122
- /**
123
- * Prefetch DocuSeal resources for faster loading
124
- */
125
- export function prefetchDocuSeal(url) {
126
- const link = document.createElement('link');
127
- link.rel = 'prefetch';
128
- link.href = url;
129
- document.head.appendChild(link);
130
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docuseal-svelte",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Docuseal Svelte component library for document signing and management.",
5
5
  "license": "MIT",
6
6
  "repository": {