diff --git a/packages/angular/bin/build.sh b/packages/angular/bin/build.sh index 86a39d2..64ea160 100755 --- a/packages/angular/bin/build.sh +++ b/packages/angular/bin/build.sh @@ -8,7 +8,7 @@ cd "$(dirname "$0")/.." cp ./util/trusted-resource-url-pipe.ts ./src/trusted-resource-url-pipe.ts # Array of files to process -files=('./src/direct-template.ts' './src/sign-document.ts' './src/create-document.ts' './src/create-template.ts') +files=('./src/direct-template.ts' './src/sign-document.ts' './src/create-document.ts' './src/create-template.ts' './src/update-document.ts' './src/update-template.ts') # Detect OS type OS_TYPE=$(uname) diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts index b403bbc..a0c0d77 100644 --- a/packages/angular/src/index.ts +++ b/packages/angular/src/index.ts @@ -1,5 +1,9 @@ export { default as EmbedDirectTemplate } from './direct-template'; export { default as EmbedSignDocument } from './sign-document'; +export { default as EmbedCreateDocumentV1 } from './create-document'; +export { default as EmbedCreateTemplateV1 } from './create-template'; +export { default as EmbedUpdateDocumentV1 } from './update-document'; +export { default as EmbedUpdateTemplateV1 } from './update-template'; export { default as unstable_EmbedCreateDocument } from './create-document'; export { default as unstable_EmbedCreateTemplate } from './create-template'; export { default as unstable_EmbedUpdateDocument } from './update-document'; diff --git a/packages/angular/src/update-document.ts b/packages/angular/src/update-document.ts index 38f937d..e030bc2 100644 --- a/packages/angular/src/update-document.ts +++ b/packages/angular/src/update-document.ts @@ -1,3 +1,4 @@ +import { TrustedResourceUrlPipe } from "./trusted-resource-url-pipe"; import { Component, ViewChild, ElementRef, Input } from "@angular/core"; import { CommonModule } from "@angular/common"; @@ -18,7 +19,8 @@ export type EmbedUpdateDocumentProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -33,7 +35,7 @@ import { CssVars } from "./css-vars"; @Component({ selector: "embed-update-document, EmbedUpdateDocument", template: ` - + `, styles: [ ` @@ -43,7 +45,7 @@ import { CssVars } from "./css-vars"; `, ], standalone: true, - imports: [CommonModule], + imports: [CommonModule, TrustedResourceUrlPipe], }) export default class EmbedUpdateDocument { @Input() host!: EmbedUpdateDocumentProps["host"]; @@ -53,6 +55,7 @@ export default class EmbedUpdateDocument { @Input() css!: EmbedUpdateDocumentProps["css"]; @Input() cssVars!: EmbedUpdateDocumentProps["cssVars"]; @Input() darkModeDisabled!: EmbedUpdateDocumentProps["darkModeDisabled"]; + @Input() onlyEditFields!: EmbedUpdateDocumentProps["onlyEditFields"]; @Input() additionalProps!: EmbedUpdateDocumentProps["additionalProps"]; @Input() documentId!: EmbedUpdateDocumentProps["documentId"]; @Input() onDocumentUpdated!: EmbedUpdateDocumentProps["onDocumentUpdated"]; @@ -71,6 +74,7 @@ export default class EmbedUpdateDocument { css: this.css, cssVars: this.cssVars, darkModeDisabled: this.darkModeDisabled, + onlyEditFields: this.onlyEditFields, ...this.additionalProps, }) ) diff --git a/packages/angular/src/update-template.ts b/packages/angular/src/update-template.ts index 4bd1a31..15cca38 100644 --- a/packages/angular/src/update-template.ts +++ b/packages/angular/src/update-template.ts @@ -1,3 +1,4 @@ +import { TrustedResourceUrlPipe } from "./trusted-resource-url-pipe"; import { Component, ViewChild, ElementRef, Input } from "@angular/core"; import { CommonModule } from "@angular/common"; @@ -18,7 +19,8 @@ export type EmbedUpdateTemplateProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -33,7 +35,7 @@ import { CssVars } from "./css-vars"; @Component({ selector: "embed-update-template, EmbedUpdateTemplate", template: ` - + `, styles: [ ` @@ -43,7 +45,7 @@ import { CssVars } from "./css-vars"; `, ], standalone: true, - imports: [CommonModule], + imports: [CommonModule, TrustedResourceUrlPipe], }) export default class EmbedUpdateTemplate { @Input() host!: EmbedUpdateTemplateProps["host"]; @@ -52,6 +54,7 @@ export default class EmbedUpdateTemplate { @Input() css!: EmbedUpdateTemplateProps["css"]; @Input() cssVars!: EmbedUpdateTemplateProps["cssVars"]; @Input() darkModeDisabled!: EmbedUpdateTemplateProps["darkModeDisabled"]; + @Input() onlyEditFields!: EmbedUpdateTemplateProps["onlyEditFields"]; @Input() additionalProps!: EmbedUpdateTemplateProps["additionalProps"]; @Input() templateId!: EmbedUpdateTemplateProps["templateId"]; @Input() presignToken!: EmbedUpdateTemplateProps["presignToken"]; @@ -70,6 +73,7 @@ export default class EmbedUpdateTemplate { css: this.css, cssVars: this.cssVars, darkModeDisabled: this.darkModeDisabled, + onlyEditFields: this.onlyEditFields, ...this.additionalProps, }) ) diff --git a/packages/mitosis/src/index.ts b/packages/mitosis/src/index.ts index 4ae4cab..b8c116c 100644 --- a/packages/mitosis/src/index.ts +++ b/packages/mitosis/src/index.ts @@ -1,5 +1,11 @@ export { default as EmbedDirectTemplate } from './direct-template.lite'; export { default as EmbedSignDocument } from './sign-document.lite'; + +export { default as EmbedCreateDocumentV1 } from './create-document.lite'; +export { default as EmbedCreateTemplateV1 } from './create-template.lite'; +export { default as EmbedUpdateDocumentV1 } from './update-document.lite'; +export { default as EmbedUpdateTemplateV1 } from './update-template.lite'; + export { default as unstable_EmbedCreateDocument } from './create-document.lite'; export { default as unstable_EmbedCreateTemplate } from './create-template.lite'; export { default as unstable_EmbedUpdateDocument } from './update-document.lite'; diff --git a/packages/mitosis/src/update-document.lite.tsx b/packages/mitosis/src/update-document.lite.tsx index a2c6f96..9658859 100644 --- a/packages/mitosis/src/update-document.lite.tsx +++ b/packages/mitosis/src/update-document.lite.tsx @@ -24,6 +24,8 @@ export type EmbedUpdateDocumentProps = { allowConfigureCommunication?: boolean; }; + onlyEditFields?: boolean | undefined; + // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -49,6 +51,7 @@ export default function EmbedUpdateDocument(props: EmbedUpdateDocumentProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }), ), diff --git a/packages/mitosis/src/update-template.lite.tsx b/packages/mitosis/src/update-template.lite.tsx index 401bb3e..0142323 100644 --- a/packages/mitosis/src/update-template.lite.tsx +++ b/packages/mitosis/src/update-template.lite.tsx @@ -24,6 +24,8 @@ export type EmbedUpdateTemplateProps = { allowConfigureCommunication?: boolean; }; + onlyEditFields?: boolean | undefined; + // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -47,6 +49,7 @@ export default function EmbedUpdateTemplate(props: EmbedUpdateTemplateProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }), ), diff --git a/packages/preact/src/index.ts b/packages/preact/src/index.ts index b403bbc..a0c0d77 100644 --- a/packages/preact/src/index.ts +++ b/packages/preact/src/index.ts @@ -1,5 +1,9 @@ export { default as EmbedDirectTemplate } from './direct-template'; export { default as EmbedSignDocument } from './sign-document'; +export { default as EmbedCreateDocumentV1 } from './create-document'; +export { default as EmbedCreateTemplateV1 } from './create-template'; +export { default as EmbedUpdateDocumentV1 } from './update-document'; +export { default as EmbedUpdateTemplateV1 } from './update-template'; export { default as unstable_EmbedCreateDocument } from './create-document'; export { default as unstable_EmbedCreateTemplate } from './create-template'; export { default as unstable_EmbedUpdateDocument } from './update-document'; diff --git a/packages/preact/src/update-document.tsx b/packages/preact/src/update-document.tsx index 4b483a3..6856f5f 100644 --- a/packages/preact/src/update-document.tsx +++ b/packages/preact/src/update-document.tsx @@ -19,7 +19,8 @@ export type EmbedUpdateDocumentProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -43,6 +44,7 @@ function EmbedUpdateDocument(props: EmbedUpdateDocumentProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/preact/src/update-template.tsx b/packages/preact/src/update-template.tsx index 8c5b33f..1d93416 100644 --- a/packages/preact/src/update-template.tsx +++ b/packages/preact/src/update-template.tsx @@ -19,7 +19,8 @@ export type EmbedUpdateTemplateProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -42,6 +43,7 @@ function EmbedUpdateTemplate(props: EmbedUpdateTemplateProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index b403bbc..a0c0d77 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -1,5 +1,9 @@ export { default as EmbedDirectTemplate } from './direct-template'; export { default as EmbedSignDocument } from './sign-document'; +export { default as EmbedCreateDocumentV1 } from './create-document'; +export { default as EmbedCreateTemplateV1 } from './create-template'; +export { default as EmbedUpdateDocumentV1 } from './update-document'; +export { default as EmbedUpdateTemplateV1 } from './update-template'; export { default as unstable_EmbedCreateDocument } from './create-document'; export { default as unstable_EmbedCreateTemplate } from './create-template'; export { default as unstable_EmbedUpdateDocument } from './update-document'; diff --git a/packages/react/src/update-document.tsx b/packages/react/src/update-document.tsx index adf1475..88b5500 100644 --- a/packages/react/src/update-document.tsx +++ b/packages/react/src/update-document.tsx @@ -19,7 +19,8 @@ export type EmbedUpdateDocumentProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -43,6 +44,7 @@ function EmbedUpdateDocument(props: EmbedUpdateDocumentProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/react/src/update-template.tsx b/packages/react/src/update-template.tsx index 6d5599a..2814187 100644 --- a/packages/react/src/update-template.tsx +++ b/packages/react/src/update-template.tsx @@ -19,7 +19,8 @@ export type EmbedUpdateTemplateProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -42,6 +43,7 @@ function EmbedUpdateTemplate(props: EmbedUpdateTemplateProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/solid/src/index.ts b/packages/solid/src/index.ts index b403bbc..a0c0d77 100644 --- a/packages/solid/src/index.ts +++ b/packages/solid/src/index.ts @@ -1,5 +1,9 @@ export { default as EmbedDirectTemplate } from './direct-template'; export { default as EmbedSignDocument } from './sign-document'; +export { default as EmbedCreateDocumentV1 } from './create-document'; +export { default as EmbedCreateTemplateV1 } from './create-template'; +export { default as EmbedUpdateDocumentV1 } from './update-document'; +export { default as EmbedUpdateTemplateV1 } from './update-template'; export { default as unstable_EmbedCreateDocument } from './create-document'; export { default as unstable_EmbedCreateTemplate } from './create-template'; export { default as unstable_EmbedUpdateDocument } from './update-document'; diff --git a/packages/solid/src/update-document.tsx b/packages/solid/src/update-document.tsx index 47bd431..e02e3b7 100644 --- a/packages/solid/src/update-document.tsx +++ b/packages/solid/src/update-document.tsx @@ -17,7 +17,8 @@ export type EmbedUpdateDocumentProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -41,6 +42,7 @@ function EmbedUpdateDocument(props: EmbedUpdateDocumentProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/solid/src/update-template.tsx b/packages/solid/src/update-template.tsx index fb51020..b104158 100644 --- a/packages/solid/src/update-template.tsx +++ b/packages/solid/src/update-template.tsx @@ -17,7 +17,8 @@ export type EmbedUpdateTemplateProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -40,6 +41,7 @@ function EmbedUpdateTemplate(props: EmbedUpdateTemplateProps) { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/svelte/src/index.ts b/packages/svelte/src/index.ts index 2d3f905..4934f8e 100644 --- a/packages/svelte/src/index.ts +++ b/packages/svelte/src/index.ts @@ -1,5 +1,9 @@ export { default as EmbedDirectTemplate } from './direct-template.svelte'; export { default as EmbedSignDocument } from './sign-document.svelte'; +export { default as EmbedCreateDocumentV1 } from './create-document.svelte'; +export { default as EmbedCreateTemplateV1 } from './create-template.svelte'; +export { default as EmbedUpdateDocumentV1 } from './update-document.svelte'; +export { default as EmbedUpdateTemplateV1 } from './update-template.svelte'; export { default as unstable_EmbedCreateDocument } from './create-document.svelte'; export { default as unstable_EmbedCreateTemplate } from './create-template.svelte'; export { default as unstable_EmbedUpdateDocument } from './update-document.svelte'; diff --git a/packages/svelte/src/update-document.svelte b/packages/svelte/src/update-document.svelte index c1b4eff..50908cc 100644 --- a/packages/svelte/src/update-document.svelte +++ b/packages/svelte/src/update-document.svelte @@ -16,7 +16,8 @@ allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -40,6 +41,8 @@ export let cssVars: EmbedUpdateDocumentProps["cssVars"] = undefined; export let darkModeDisabled: EmbedUpdateDocumentProps["darkModeDisabled"] = undefined; + export let onlyEditFields: EmbedUpdateDocumentProps["onlyEditFields"] = + undefined; export let additionalProps: EmbedUpdateDocumentProps["additionalProps"] = undefined; export let documentId: EmbedUpdateDocumentProps["documentId"]; @@ -70,6 +73,7 @@ css: css, cssVars: cssVars, darkModeDisabled: darkModeDisabled, + onlyEditFields: onlyEditFields, ...additionalProps, }) ) diff --git a/packages/svelte/src/update-template.svelte b/packages/svelte/src/update-template.svelte index 8648246..eec2a4d 100644 --- a/packages/svelte/src/update-template.svelte +++ b/packages/svelte/src/update-template.svelte @@ -16,7 +16,8 @@ allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -39,6 +40,8 @@ export let cssVars: EmbedUpdateTemplateProps["cssVars"] = undefined; export let darkModeDisabled: EmbedUpdateTemplateProps["darkModeDisabled"] = undefined; + export let onlyEditFields: EmbedUpdateTemplateProps["onlyEditFields"] = + undefined; export let additionalProps: EmbedUpdateTemplateProps["additionalProps"] = undefined; export let templateId: EmbedUpdateTemplateProps["templateId"]; @@ -69,6 +72,7 @@ css: css, cssVars: cssVars, darkModeDisabled: darkModeDisabled, + onlyEditFields: onlyEditFields, ...additionalProps, }) ) diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index 49bbd38..b100df9 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -1,5 +1,9 @@ export { default as EmbedDirectTemplate } from './direct-template.vue'; export { default as EmbedSignDocument } from './sign-document.vue'; +export { default as EmbedCreateDocumentV1 } from './create-document.vue'; +export { default as EmbedCreateTemplateV1 } from './create-template.vue'; +export { default as EmbedUpdateDocumentV1 } from './update-document.vue'; +export { default as EmbedUpdateTemplateV1 } from './update-template.vue'; export { default as unstable_EmbedCreateDocument } from './create-document.vue'; export { default as unstable_EmbedCreateTemplate } from './create-template.vue'; export { default as unstable_EmbedUpdateDocument } from './update-document.vue'; diff --git a/packages/vue/src/update-document.vue b/packages/vue/src/update-document.vue index 2c24085..9748318 100644 --- a/packages/vue/src/update-document.vue +++ b/packages/vue/src/update-document.vue @@ -24,7 +24,8 @@ export type EmbedUpdateDocumentProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -55,6 +56,7 @@ const src = computed(() => { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/packages/vue/src/update-template.vue b/packages/vue/src/update-template.vue index 98ab3df..4e26eda 100644 --- a/packages/vue/src/update-template.vue +++ b/packages/vue/src/update-template.vue @@ -24,7 +24,8 @@ export type EmbedUpdateTemplateProps = { allowConfigureTimezone?: boolean; allowConfigureRedirectUrl?: boolean; allowConfigureCommunication?: boolean; - }; // Additional props to be passed to the iframe, used for testing out features + }; + onlyEditFields?: boolean | undefined; // Additional props to be passed to the iframe, used for testing out features // prior to being added to the main props additionalProps?: Record | undefined; @@ -54,6 +55,7 @@ const src = computed(() => { css: props.css, cssVars: props.cssVars, darkModeDisabled: props.darkModeDisabled, + onlyEditFields: props.onlyEditFields, ...props.additionalProps, }) ) diff --git a/playground/.env.example b/playground/.env.example index ceaedfc..5dfadf4 100644 --- a/playground/.env.example +++ b/playground/.env.example @@ -1 +1,2 @@ -VITE_EMBED_HOST="https://app.documenso.com" \ No newline at end of file +VITE_EMBED_HOST="https://app.documenso.com" +VITE_API_KEY="" \ No newline at end of file diff --git a/playground/src/App.tsx b/playground/src/App.tsx index a795a9b..3ee7b85 100644 --- a/playground/src/App.tsx +++ b/playground/src/App.tsx @@ -1,7 +1,13 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import './App.css'; +import CreateDocumentEmbedding from './components/embeddings/create-document'; +import CreateTemplateEmbedding from './components/embeddings/create-template'; +import DirectTemplateEmbedding from './components/embeddings/direct-template'; import MultiSignEmbedding from './components/embeddings/multisign'; +import SignDocumentEmbedding from './components/embeddings/sign-document'; +import UpdateDocumentEmbedding from './components/embeddings/update-document'; +import UpdateTemplateEmbedding from './components/embeddings/update-template'; export default function App() { return ( @@ -13,14 +19,44 @@ export default function App() {

- + + Sign Document + Direct Template Multi Sign + Create Document + Update Document + Create Template + Update Template + + + + + + + + + + + + + + + + + + + + + + + + ); diff --git a/playground/src/components/embeddings/create-document.tsx b/playground/src/components/embeddings/create-document.tsx new file mode 100644 index 0000000..592d8fb --- /dev/null +++ b/playground/src/components/embeddings/create-document.tsx @@ -0,0 +1,443 @@ +import { useState } from 'react'; + +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { Checkbox } from '@/components/ui/checkbox'; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import { Separator } from '@/components/ui/separator'; +import { Textarea } from '@/components/ui/textarea'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; + +import { unstable_EmbedCreateDocument as EmbedCreateDocument } from '@documenso/embed-react'; + +const formSchema = z + .object({ + useApiKey: z.boolean(), + apiKey: z.string().optional(), + presignToken: z.string().optional(), + externalId: z.string().optional(), + allowConfigureSignatureTypes: z.boolean().optional(), + allowConfigureLanguage: z.boolean().optional(), + allowConfigureDateFormat: z.boolean().optional(), + allowConfigureTimezone: z.boolean().optional(), + allowConfigureRedirectUrl: z.boolean().optional(), + allowConfigureCommunication: z.boolean().optional(), + darkModeDisabled: z.boolean().optional(), + css: z.string().optional(), + }) + .refine( + (data) => { + if (data.useApiKey) { + return !!data.apiKey && data.apiKey.length > 0; + } + return !!data.presignToken && data.presignToken.length > 0; + }, + { + message: 'Either API key or presign token is required', + path: ['apiKey'], + }, + ); + +type FormData = z.infer; + +export default function CreateDocumentEmbedding() { + const host = import.meta.env.VITE_EMBED_HOST || 'https://app.documenso.com'; + const [showEmbed, setShowEmbed] = useState(false); + const [embedConfig, setEmbedConfig] = useState< + (Omit & { presignToken: string }) | null + >(null); + const [isGenerating, setIsGenerating] = useState(false); + const [error, setError] = useState(null); + + const form = useForm({ + resolver: zodResolver(formSchema), + defaultValues: { + useApiKey: true, + apiKey: '', + presignToken: '', + externalId: '', + allowConfigureSignatureTypes: true, + allowConfigureLanguage: true, + allowConfigureDateFormat: true, + allowConfigureTimezone: true, + allowConfigureRedirectUrl: true, + allowConfigureCommunication: true, + darkModeDisabled: false, + css: '', + }, + }); + + const generatePresignToken = async (apiKey: string) => { + const response = await fetch(`${host}/api/v2-beta/embedding/create-presign-token`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${apiKey}`, + }, + body: JSON.stringify({ + expiresIn: 60, + }), + }); + + if (!response.ok) { + const errorData = await response.json().catch(() => ({ message: 'Failed to parse error' })); + throw new Error(errorData.message || `Failed to generate presign token: ${response.status}`); + } + + const data = await response.json(); + return data.token; + }; + + const onSubmit = async (data: FormData) => { + setIsGenerating(true); + setError(null); + + try { + let token = data.presignToken || ''; + + if (data.useApiKey && data.apiKey) { + token = await generatePresignToken(data.apiKey); + } + + setEmbedConfig({ ...data, presignToken: token }); + setShowEmbed(true); + console.log('Generating Create Document embedding'); + } catch (err) { + setError(err instanceof Error ? err.message : 'Failed to generate token'); + console.error('Error generating presign token:', err); + } finally { + setIsGenerating(false); + } + }; + + const handleClear = () => { + form.reset(); + setShowEmbed(false); + setEmbedConfig(null); + setError(null); + }; + + const useApiKey = form.watch('useApiKey'); + const watchedValue = useApiKey ? form.watch('apiKey') : form.watch('presignToken'); + + return ( +
+
+ + + + Create Document Configurator + + Configure your document authoring embedding parameters + + + + ( + + + + +
+ Use API Key to Generate Token + + Check this to automatically generate a presign token from your API key + +
+
+ )} + /> + + {useApiKey ? ( + ( + + API Key + + + + + Your Documenso API key to generate a presign token + + + + )} + /> + ) : ( + ( + + Presign Token + + + + + A presign token generated from your backend server + + + + )} + /> + )} + + ( + + External ID (Optional) + + + + Unique identifier for tracking this document + + + )} + /> + + + +
+
Feature Configuration
+ + ( + + + + +
+ Allow Configure Signature Types + + Allow users to configure signature field types + +
+
+ )} + /> + + ( + + + + +
+ Allow Configure Language + + Allow users to configure document language + +
+
+ )} + /> + + ( + + + + +
+ Allow Configure Date Format + Allow users to configure date format +
+
+ )} + /> + + ( + + + + +
+ Allow Configure Timezone + Allow users to configure timezone +
+
+ )} + /> + + ( + + + + +
+ Allow Configure Redirect URL + Allow users to set redirect URL +
+
+ )} + /> + + ( + + + + +
+ Allow Configure Communication + + Allow users to configure email notifications + +
+
+ )} + /> +
+ + + + ( + + + + +
+ Disable Dark Mode + Force light mode only +
+
+ )} + /> + + + + ( + + Custom CSS (Optional) + +