Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

Commit a8bb31e

Browse files
committed
chore: prettier, eslint, typecheck and build - pre-commit hooks
1 parent c85abc1 commit a8bb31e

File tree

12 files changed

+584
-499
lines changed

12 files changed

+584
-499
lines changed

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pnpm type-check && pnpm lint
1+
pnpm lint-staged && pnpm type-check && pnpm build

.prettierrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
{}
1+
{
2+
"singleQuote": true,
3+
"printWidth": 100
4+
}

demo/src/App.tsx

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import React, { useState, useRef, useCallback, useMemo } from "react";
2-
import SuperDocTemplateBuilder from "@superdoc-dev/template-builder";
1+
import React, { useState, useRef, useCallback, useMemo } from 'react';
2+
import SuperDocTemplateBuilder from '@superdoc-dev/template-builder';
33
import type {
44
SuperDocTemplateBuilderHandle,
55
TemplateField,
66
FieldDefinition,
77
ExportEvent,
8-
} from "@superdoc-dev/template-builder";
9-
import "superdoc/style.css";
10-
import "./App.css";
8+
} from '@superdoc-dev/template-builder';
9+
import 'superdoc/style.css';
10+
import './App.css';
1111

1212
const availableFields: FieldDefinition[] = [
13-
{ id: "1242142770", label: "Agreement Date" },
14-
{ id: "1242142771", label: "User Name" },
15-
{ id: "1242142772", label: "Company Name" },
16-
{ id: "1242142773", label: "Service Type" },
17-
{ id: "1242142774", label: "Agreement Jurisdiction" },
18-
{ id: "1242142775", label: "Company Address" },
19-
{ id: "1242142776", label: "Signature" },
13+
{ id: '1242142770', label: 'Agreement Date' },
14+
{ id: '1242142771', label: 'User Name' },
15+
{ id: '1242142772', label: 'Company Name' },
16+
{ id: '1242142773', label: 'Service Type' },
17+
{ id: '1242142774', label: 'Agreement Jurisdiction' },
18+
{ id: '1242142775', label: 'Company Address' },
19+
{ id: '1242142776', label: 'Signature' },
2020
];
2121

2222
export function App() {
23-
const [fields, setFields] = useState<TemplateField[]>([]);
23+
const [, setFields] = useState<TemplateField[]>([]);
2424
const [events, setEvents] = useState<string[]>([]);
2525
const [isDownloading, setIsDownloading] = useState(false);
2626
const [isImporting, setIsImporting] = useState(false);
2727
const [importError, setImportError] = useState<string | null>(null);
2828
const [documentSource, setDocumentSource] = useState<string | File>(
29-
"https://storage.googleapis.com/public_static_hosting/public_demo_docs/new_service_agreement.docx",
29+
'https://storage.googleapis.com/public_static_hosting/public_demo_docs/new_service_agreement.docx',
3030
);
3131
const builderRef = useRef<SuperDocTemplateBuilderHandle>(null);
3232
const fileInputRef = useRef<HTMLInputElement>(null);
@@ -70,28 +70,26 @@ export function App() {
7070
);
7171

7272
const handleReady = useCallback(() => {
73-
log("✓ Template builder ready");
73+
log('✓ Template builder ready');
7474
if (importingRef.current) {
75-
log("📄 Document imported");
75+
log('📄 Document imported');
7676
importingRef.current = false;
7777
setImportError(null);
7878
setIsImporting(false);
7979
}
8080
}, [log]);
8181

8282
const handleTrigger = useCallback(() => {
83-
log("⌨ Trigger detected");
83+
log('⌨ Trigger detected');
8484
}, [log]);
8585

8686
const handleExport = useCallback(
8787
(event: ExportEvent) => {
88-
console.log("Export Event:", event);
89-
console.log("Fields:", JSON.stringify(event.fields, null, 2));
88+
console.log('Export Event:', event);
89+
console.log('Fields:', JSON.stringify(event.fields, null, 2));
9090
log(`Exported ${event.fields.length} fields`);
9191
event.fields.forEach((f) => {
92-
console.log(
93-
` - ${f.alias} (id: ${f.id}, mode: ${f.mode}, group: ${f.group || "none"})`,
94-
);
92+
console.log(` - ${f.alias} (id: ${f.id}, mode: ${f.mode}, group: ${f.group || 'none'})`);
9593
});
9694
},
9795
[log],
@@ -106,20 +104,20 @@ export function App() {
106104
setIsDownloading(true);
107105

108106
await builderRef.current.exportTemplate({
109-
fileName: "template.docx",
107+
fileName: 'template.docx',
110108
});
111109

112-
log("📤 Template exported");
110+
log('📤 Template exported');
113111
} catch (error) {
114-
log("⚠️ Export failed");
115-
console.error("Failed to export template", error);
112+
log('⚠️ Export failed');
113+
console.error('Failed to export template', error);
116114
} finally {
117115
setIsDownloading(false);
118116
}
119117
}, [log]);
120118

121119
const handleKeyDown = (e: React.KeyboardEvent) => {
122-
if (e.key === "Tab") {
120+
if (e.key === 'Tab') {
123121
e.preventDefault();
124122
if (e.shiftKey) {
125123
builderRef.current?.previousField();
@@ -132,7 +130,7 @@ export function App() {
132130
const documentConfig = useMemo(
133131
() => ({
134132
source: documentSource,
135-
mode: "editing" as const,
133+
mode: 'editing' as const,
136134
}),
137135
[documentSource],
138136
);
@@ -145,15 +143,15 @@ export function App() {
145143
const handleFileInputChange = useCallback(
146144
(event: React.ChangeEvent<HTMLInputElement>) => {
147145
const file = event.target.files?.[0];
148-
event.target.value = "";
146+
event.target.value = '';
149147

150148
if (!file) return;
151149

152-
const extension = file.name.split(".").pop()?.toLowerCase();
153-
if (extension !== "docx") {
154-
const message = "Invalid file type. Please choose a .docx file.";
150+
const extension = file.name.split('.').pop()?.toLowerCase();
151+
if (extension !== 'docx') {
152+
const message = 'Invalid file type. Please choose a .docx file.';
155153
setImportError(message);
156-
log("⚠️ " + message);
154+
log('⚠️ ' + message);
157155
return;
158156
}
159157

@@ -176,7 +174,7 @@ export function App() {
176174

177175
const listConfig = useMemo(
178176
() => ({
179-
position: "right" as const,
177+
position: 'right' as const,
180178
}),
181179
[],
182180
);
@@ -196,7 +194,7 @@ export function App() {
196194
</a>
197195
</h1>
198196
<p>
199-
React template builder from{" "}
197+
React template builder from{' '}
200198
<a href="https://superdoc.dev" target="_blank" rel="noopener">
201199
SuperDoc
202200
</a>
@@ -220,7 +218,7 @@ export function App() {
220218
<div className="container">
221219
<div className="toolbar">
222220
<div className="toolbar-left">
223-
<span className="hint">Type {"{{"} to insert a field</span>
221+
<span className="hint">Type {'{{'} to insert a field</span>
224222
<span className="divider">|</span>
225223
<span className="hint">Tab/Shift+Tab to navigate</span>
226224
</div>
@@ -229,22 +227,22 @@ export function App() {
229227
type="file"
230228
accept=".docx"
231229
ref={fileInputRef}
232-
style={{ display: "none" }}
230+
style={{ display: 'none' }}
233231
onChange={handleFileInputChange}
234232
/>
235233
<button
236234
onClick={handleImportButtonClick}
237235
className="import-button"
238236
disabled={isImporting || isDownloading}
239237
>
240-
{isImporting ? "Importing…" : "Import File"}
238+
{isImporting ? 'Importing…' : 'Import File'}
241239
</button>
242240
<button
243241
onClick={handleExportTemplate}
244242
className="export-button"
245243
disabled={isDownloading || isImporting}
246244
>
247-
{isDownloading ? "Exporting..." : "Export Template"}
245+
{isDownloading ? 'Exporting...' : 'Export Template'}
248246
</button>
249247
</div>
250248
</div>

demo/src/main.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { App } from './App';
44
import './index.css';
55

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

demo/vite.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
3-
import path from 'path';
43

54
export default defineConfig({
6-
plugins: [react()],
7-
base: '/'
5+
plugins: [react()],
6+
base: '/',
87
});

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
"dev": "vite build --watch",
2222
"build": "tsc && vite build",
2323
"type-check": "tsc --noEmit",
24-
"lint": "eslint src --ext .ts,.tsx",
25-
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
24+
"lint": "eslint src demo",
25+
"lint:fix": "eslint src demo --fix",
26+
"format": "prettier --write \"src/**/*.{ts,tsx}\" \"demo/**/*.{ts,tsx}\"",
27+
"format:check": "prettier --check \"src/**/*.{ts,tsx}\" \"demo/**/*.{ts,tsx}\"",
2628
"test": "vitest",
2729
"test:watch": "vitest --watch",
2830
"prepare": "husky",
2931
"release": "semantic-release",
30-
"check:all": "pnpm run type-check && pnpm run lint && pnpm run format"
32+
"check:all": "pnpm run format:check && pnpm run lint && pnpm run type-check && pnpm run build"
3133
},
3234
"repository": {
3335
"type": "git",
@@ -71,6 +73,7 @@
7173
"eslint-plugin-react-hooks": "^7.0.1",
7274
"husky": "^9.1.7",
7375
"jsdom": "^27.2.0",
76+
"lint-staged": "^16.2.7",
7477
"prettier": "^3.6.2",
7578
"react": "^19.2.0",
7679
"react-dom": "^19.2.0",
@@ -86,5 +89,11 @@
8689
},
8790
"engines": {
8891
"node": ">=18"
92+
},
93+
"lint-staged": {
94+
"*.{ts,tsx}": [
95+
"prettier --write",
96+
"eslint --fix"
97+
]
8998
}
9099
}

0 commit comments

Comments
 (0)