Skip to content

Commit 1950d2e

Browse files
committed
chore: fix mount Vue on wrapper element and fix React docs lifecycle cleanup
1 parent 81961f8 commit 1950d2e

12 files changed

Lines changed: 66 additions & 86 deletions

File tree

apps/docs/getting-started/frameworks/react.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function DocEditor({ document }) {
3131
});
3232

3333
return () => {
34+
superdocRef.current?.destroy();
3435
superdocRef.current = null;
3536
};
3637
}, [document]);
@@ -69,6 +70,7 @@ const DocEditor = forwardRef(({ document, user, onReady }, ref) => {
6970
});
7071

7172
return () => {
73+
superdocRef.current?.destroy();
7274
superdocRef.current = null;
7375
};
7476
}, [document, user, onReady]);
@@ -190,6 +192,7 @@ const DocEditor = forwardRef<EditorRef, EditorProps>(
190192
superdocRef.current = new SuperDoc(config);
191193

192194
return () => {
195+
superdocRef.current?.destroy();
193196
superdocRef.current = null;
194197
};
195198
}, [document, userId, onReady]);
@@ -247,6 +250,7 @@ function useSuperDoc(config) {
247250
});
248251

249252
return () => {
253+
superdocRef.current?.destroy();
250254
superdocRef.current = null;
251255
setReady(false);
252256
};

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default [
1212
{
1313
ignores: [
1414
'**/dist/**',
15+
'**/dist-types/**',
1516
'**/node_modules/**',
1617
// Generated/vendor files that shouldn't be linted
1718
'**/pdfjs.js',

packages/ai/src/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ export { createAIProvider } from './ai-actions/providers';
1414
export * from './shared/types';
1515
export * from './shared/utils';
1616
export * from './shared/constants';
17-
export type {
18-
AIToolActions,
19-
SafeRecord,
20-
SelectionRange,
21-
SelectionSnapshot,
22-
PlannerContextSnapshot,
23-
BuilderPlanResult,
24-
} from './shared/types';
2517

2618
export { createToolRegistry, getToolDescriptions, isValidTool } from './ai-actions/tools';
2719

packages/esign/demo/server/server.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import express from 'express';
22
import cors from 'cors';
3-
import dotenv from 'dotenv';
3+
import { config as dotenvConfig } from 'dotenv';
44

5-
dotenv.config();
5+
dotenvConfig();
66

77
const app = express();
88
const PORT = process.env.PORT || 3001;
99
const SUPERDOC_SERVICES_API_KEY = process.env.SUPERDOC_SERVICES_API_KEY;
10-
const SUPERDOC_SERVICES_BASE_URL =
11-
process.env.SUPERDOC_SERVICES_BASE_URL || 'https://api.superdoc.dev';
10+
const SUPERDOC_SERVICES_BASE_URL = process.env.SUPERDOC_SERVICES_BASE_URL || 'https://api.superdoc.dev';
1211
const CONSENT_FIELD_IDS = new Set(['consent_agreement', 'terms', 'email', '406948812']);
1312
const SIGNATURE_FIELD_ID = '789012';
1413
const IP_ADDRESS = '127.0.0.1'; // Replace with real client IP once available
@@ -85,8 +84,7 @@ const sendPdfBuffer = (res, base64, fileName, contentType = 'application/pdf') =
8584

8685
app.post('/v1/download', async (req, res) => {
8786
try {
88-
const { document, fields = {}, fileName = 'document.pdf', signatureMode = 'annotate' } =
89-
req.body || {};
87+
const { document, fields = {}, fileName = 'document.pdf', signatureMode = 'annotate' } = req.body || {};
9088

9189
if (!SUPERDOC_SERVICES_API_KEY) {
9290
return res.status(500).json({ error: 'Missing SUPERDOC_SERVICES_API_KEY on the server' });

packages/esign/demo/src/CustomSignature.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from 'react';
1+
import { useEffect, useRef, useState, type FC } from 'react';
22
import SignaturePad from 'signature_pad';
33
import type { FieldComponentProps } from '@superdoc-dev/esign';
44

@@ -17,12 +17,7 @@ const cropSVG = (svgText: string): string => {
1717
if (bbox.width === 0 || bbox.height === 0) return svgText;
1818

1919
const padding = 5;
20-
const viewBox = [
21-
bbox.x - padding,
22-
bbox.y - padding,
23-
bbox.width + padding * 2,
24-
bbox.height + padding * 2,
25-
].join(' ');
20+
const viewBox = [bbox.x - padding, bbox.y - padding, bbox.width + padding * 2, bbox.height + padding * 2].join(' ');
2621
svgElement.setAttribute('viewBox', viewBox);
2722
svgElement.setAttribute('width', String(Math.ceil(bbox.width + padding * 2)));
2823
svgElement.setAttribute('height', String(Math.ceil(bbox.height + padding * 2)));
@@ -54,7 +49,7 @@ const svgToPngDataUrl = (svgText: string): Promise<string> =>
5449
img.src = svgDataUrl;
5550
});
5651

57-
const CustomSignature: React.FC<FieldComponentProps> = ({ value, onChange, isDisabled, label }) => {
52+
const CustomSignature: FC<FieldComponentProps> = ({ value, onChange, isDisabled, label }) => {
5853
const [mode, setMode] = useState<'type' | 'draw'>('type');
5954
const canvasRef = useRef<HTMLCanvasElement>(null);
6055
const signaturePadRef = useRef<SignaturePad | null>(null);
@@ -164,12 +159,10 @@ const CustomSignature: React.FC<FieldComponentProps> = ({ value, onChange, isDis
164159

165160
return (
166161
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
167-
{label && (
168-
<label style={{ fontSize: '14px', fontWeight: '600', color: '#1f2937' }}>{label}</label>
169-
)}
162+
{label && <label style={{ fontSize: '14px', fontWeight: '600', color: '#1f2937' }}>{label}</label>}
170163
<div style={{ display: 'flex', gap: '8px', marginBottom: '4px' }}>
171164
<button
172-
type="button"
165+
type='button'
173166
onClick={() => switchMode('type')}
174167
disabled={isDisabled}
175168
style={{
@@ -185,7 +178,7 @@ const CustomSignature: React.FC<FieldComponentProps> = ({ value, onChange, isDis
185178
Type
186179
</button>
187180
<button
188-
type="button"
181+
type='button'
189182
onClick={() => switchMode('draw')}
190183
disabled={isDisabled}
191184
style={{
@@ -203,11 +196,11 @@ const CustomSignature: React.FC<FieldComponentProps> = ({ value, onChange, isDis
203196
</div>
204197
{mode === 'type' ? (
205198
<input
206-
type="text"
199+
type='text'
207200
value={String(value || '')}
208201
onChange={(e) => onChange(e.target.value)}
209202
disabled={isDisabled}
210-
placeholder="Type your full name"
203+
placeholder='Type your full name'
211204
style={{
212205
fontFamily: 'cursive',
213206
fontSize: '20px',
@@ -234,7 +227,7 @@ const CustomSignature: React.FC<FieldComponentProps> = ({ value, onChange, isDis
234227
}}
235228
/>
236229
<button
237-
type="button"
230+
type='button'
238231
onClick={clearCanvas}
239232
disabled={isDisabled}
240233
style={{

packages/esign/demo/src/main.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom/client';
1+
import { StrictMode } from 'react';
2+
import { createRoot } from 'react-dom/client';
33
import { App } from './App';
44
import './index.css';
55

6-
ReactDOM.createRoot(document.getElementById('root')!).render(
7-
<React.StrictMode>
6+
createRoot(document.getElementById('root')!).render(
7+
<StrictMode>
88
<App />
9-
</React.StrictMode>,
9+
</StrictMode>,
1010
);

packages/esign/src/defaults/CheckboxInput.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import React from 'react';
1+
import type { FC } from 'react';
22
import type { FieldComponentProps } from '../types';
33

4-
export const CheckboxInput: React.FC<FieldComponentProps> = ({
5-
value,
6-
onChange,
7-
isDisabled,
8-
label,
9-
}) => {
4+
export const CheckboxInput: FC<FieldComponentProps> = ({ value, onChange, isDisabled, label }) => {
105
return (
11-
<label className="superdoc-esign-checkbox-input" style={{ display: 'flex', gap: '8px' }}>
6+
<label className='superdoc-esign-checkbox-input' style={{ display: 'flex', gap: '8px' }}>
127
<input
13-
type="checkbox"
8+
type='checkbox'
149
checked={Boolean(value)}
1510
onChange={(e) => onChange(e.target.checked)}
1611
disabled={isDisabled}

packages/esign/src/defaults/DownloadButton.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import React from 'react';
1+
import type { FC } from 'react';
22
import type { DownloadButtonProps, DownloadConfig } from '../types';
33

44
export const createDownloadButton = (config?: DownloadConfig) => {
5-
const Component: React.FC<DownloadButtonProps> = ({
6-
onClick,
7-
fileName,
8-
isDisabled,
9-
isDownloading,
10-
}) => {
5+
const Component: FC<DownloadButtonProps> = ({ onClick, fileName, isDisabled, isDownloading }) => {
116
const label = config?.label || 'Download';
127
const disabled = isDisabled || isDownloading;
138

@@ -32,7 +27,7 @@ export const createDownloadButton = (config?: DownloadConfig) => {
3227
transition: 'opacity 0.2s ease',
3328
}}
3429
>
35-
{isDownloading && <span className="superdoc-esign-spinner" />}
30+
{isDownloading && <span className='superdoc-esign-spinner' />}
3631
{isDownloading ? 'Downloading...' : label}
3732
{!isDownloading && fileName && ` (${fileName})`}
3833
</button>

packages/esign/src/defaults/SignatureInput.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
import React from 'react';
1+
import type { FC } from 'react';
22
import type { FieldComponentProps } from '../types';
33

4-
export const SignatureInput: React.FC<FieldComponentProps> = ({
5-
value,
6-
onChange,
7-
isDisabled,
8-
label,
9-
}) => {
4+
export const SignatureInput: FC<FieldComponentProps> = ({ value, onChange, isDisabled, label }) => {
105
return (
11-
<div
12-
className={`superdoc-esign-signature-input`}
13-
style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}
14-
>
6+
<div className={`superdoc-esign-signature-input`} style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
157
{label && <label>{label}</label>}
168
<input
17-
type="text"
9+
type='text'
1810
value={String(value || '')}
1911
onChange={(e) => onChange(e.target.value)}
2012
disabled={isDisabled}
21-
placeholder="Type your full name"
13+
placeholder='Type your full name'
2214
style={{
2315
fontFamily: 'cursive',
2416
fontSize: '18px',

packages/esign/src/defaults/SubmitButton.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import React from 'react';
1+
import type { FC } from 'react';
22
import type { SubmitButtonProps, SubmitConfig } from '../types';
33

44
export const createSubmitButton = (config?: SubmitConfig) => {
5-
const Component: React.FC<SubmitButtonProps> = ({
6-
onClick,
7-
isValid,
8-
isDisabled,
9-
isSubmitting,
10-
}) => {
5+
const Component: FC<SubmitButtonProps> = ({ onClick, isValid, isDisabled, isSubmitting }) => {
116
const label = config?.label || 'Submit';
127
const disabled = !isValid || isDisabled || isSubmitting;
138

@@ -32,7 +27,7 @@ export const createSubmitButton = (config?: SubmitConfig) => {
3227
transition: 'opacity 0.2s ease',
3328
}}
3429
>
35-
{isSubmitting && <span className="superdoc-esign-spinner superdoc-esign-spinner--light" />}
30+
{isSubmitting && <span className='superdoc-esign-spinner superdoc-esign-spinner--light' />}
3631
{isSubmitting ? 'Submitting...' : label}
3732
</button>
3833
);

0 commit comments

Comments
 (0)