@kissflow/create-app 0.1.0
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/LICENSE +21 -0
- package/README.md +9 -0
- package/bin/index.js +80 -0
- package/package.json +47 -0
- package/scaffolders/app/index.js +49 -0
- package/scaffolders/app/template/_CLAUDE.md +104 -0
- package/scaffolders/app/template/_README.md +54 -0
- package/scaffolders/app/template/_env.example +10 -0
- package/scaffolders/app/template/_gitignore +6 -0
- package/scaffolders/app/template/_package.json +55 -0
- package/scaffolders/app/template/_prettierrc +6 -0
- package/scaffolders/app/template/agents/design-guidelines.md +172 -0
- package/scaffolders/app/template/agents/kissflow-sdk.md +257 -0
- package/scaffolders/app/template/agents/theming.md +61 -0
- package/scaffolders/app/template/cert/localhost.crt +18 -0
- package/scaffolders/app/template/cert/localhost.key +28 -0
- package/scaffolders/app/template/components.json +21 -0
- package/scaffolders/app/template/index.html +12 -0
- package/scaffolders/app/template/jsconfig.json +8 -0
- package/scaffolders/app/template/lib/kf-schema.json +7 -0
- package/scaffolders/app/template/scripts/zip.js +54 -0
- package/scaffolders/app/template/src/components/app-shell.jsx +208 -0
- package/scaffolders/app/template/src/components/fields/AggregationField.jsx +42 -0
- package/scaffolders/app/template/src/components/fields/AttachmentField.jsx +175 -0
- package/scaffolders/app/template/src/components/fields/BooleanField.jsx +47 -0
- package/scaffolders/app/template/src/components/fields/CheckboxField.jsx +79 -0
- package/scaffolders/app/template/src/components/fields/ChecklistField.jsx +190 -0
- package/scaffolders/app/template/src/components/fields/CurrencyField.jsx +183 -0
- package/scaffolders/app/template/src/components/fields/DateField.jsx +65 -0
- package/scaffolders/app/template/src/components/fields/DateTimeField.jsx +186 -0
- package/scaffolders/app/template/src/components/fields/EmailField.jsx +30 -0
- package/scaffolders/app/template/src/components/fields/FieldError.jsx +11 -0
- package/scaffolders/app/template/src/components/fields/FieldLabel.jsx +14 -0
- package/scaffolders/app/template/src/components/fields/GeolocationField.jsx +99 -0
- package/scaffolders/app/template/src/components/fields/ImageField.jsx +149 -0
- package/scaffolders/app/template/src/components/fields/LookupField.jsx +256 -0
- package/scaffolders/app/template/src/components/fields/MultiSelectField.jsx +152 -0
- package/scaffolders/app/template/src/components/fields/MultiUserSelectField.jsx +153 -0
- package/scaffolders/app/template/src/components/fields/NumberField.jsx +30 -0
- package/scaffolders/app/template/src/components/fields/RadioField.jsx +78 -0
- package/scaffolders/app/template/src/components/fields/RatingField.jsx +64 -0
- package/scaffolders/app/template/src/components/fields/ScannerField.jsx +62 -0
- package/scaffolders/app/template/src/components/fields/SelectField.jsx +74 -0
- package/scaffolders/app/template/src/components/fields/SequenceNumberField.jsx +22 -0
- package/scaffolders/app/template/src/components/fields/SignatureField.jsx +344 -0
- package/scaffolders/app/template/src/components/fields/SliderField.jsx +39 -0
- package/scaffolders/app/template/src/components/fields/SmartAttachmentField.jsx +188 -0
- package/scaffolders/app/template/src/components/fields/TextField.jsx +30 -0
- package/scaffolders/app/template/src/components/fields/TextareaField.jsx +30 -0
- package/scaffolders/app/template/src/components/fields/UserSelectField.jsx +76 -0
- package/scaffolders/app/template/src/components/fields/index.js +87 -0
- package/scaffolders/app/template/src/components/fields/useGeolocationPicker.js +42 -0
- package/scaffolders/app/template/src/components/fields/useScanner.js +43 -0
- package/scaffolders/app/template/src/components/form/FormAction.jsx +86 -0
- package/scaffolders/app/template/src/components/form/FormBody.jsx +163 -0
- package/scaffolders/app/template/src/components/form/FormHeader.jsx +65 -0
- package/scaffolders/app/template/src/components/form/ProcessActions.jsx +270 -0
- package/scaffolders/app/template/src/components/form/index.jsx +119 -0
- package/scaffolders/app/template/src/components/form/shared.jsx +213 -0
- package/scaffolders/app/template/src/components/tablefields/TableAggregationField.jsx +14 -0
- package/scaffolders/app/template/src/components/tablefields/TableAttachmentField.jsx +53 -0
- package/scaffolders/app/template/src/components/tablefields/TableBooleanField.jsx +26 -0
- package/scaffolders/app/template/src/components/tablefields/TableCheckboxField.jsx +6 -0
- package/scaffolders/app/template/src/components/tablefields/TableChecklistField.jsx +48 -0
- package/scaffolders/app/template/src/components/tablefields/TableCurrencyField.jsx +140 -0
- package/scaffolders/app/template/src/components/tablefields/TableDateField.jsx +49 -0
- package/scaffolders/app/template/src/components/tablefields/TableDateTimeField.jsx +170 -0
- package/scaffolders/app/template/src/components/tablefields/TableGeolocationField.jsx +69 -0
- package/scaffolders/app/template/src/components/tablefields/TableImageField.jsx +78 -0
- package/scaffolders/app/template/src/components/tablefields/TableLookupField.jsx +165 -0
- package/scaffolders/app/template/src/components/tablefields/TableMultiSelectField.jsx +111 -0
- package/scaffolders/app/template/src/components/tablefields/TableMultiUserSelectField.jsx +109 -0
- package/scaffolders/app/template/src/components/tablefields/TableNumberField.jsx +33 -0
- package/scaffolders/app/template/src/components/tablefields/TableRatingField.jsx +45 -0
- package/scaffolders/app/template/src/components/tablefields/TableScannerField.jsx +67 -0
- package/scaffolders/app/template/src/components/tablefields/TableSelectField.jsx +47 -0
- package/scaffolders/app/template/src/components/tablefields/TableSequenceNumberField.jsx +7 -0
- package/scaffolders/app/template/src/components/tablefields/TableSignatureField.jsx +59 -0
- package/scaffolders/app/template/src/components/tablefields/TableSliderField.jsx +26 -0
- package/scaffolders/app/template/src/components/tablefields/TableTextField.jsx +28 -0
- package/scaffolders/app/template/src/components/tablefields/TableUserSelectField.jsx +51 -0
- package/scaffolders/app/template/src/components/tablefields/index.js +71 -0
- package/scaffolders/app/template/src/components/tablefields/useTableFieldOptions.js +33 -0
- package/scaffolders/app/template/src/components/ui/accordion.jsx +51 -0
- package/scaffolders/app/template/src/components/ui/avatar.jsx +92 -0
- package/scaffolders/app/template/src/components/ui/badge.jsx +40 -0
- package/scaffolders/app/template/src/components/ui/button.jsx +61 -0
- package/scaffolders/app/template/src/components/ui/calendar.jsx +207 -0
- package/scaffolders/app/template/src/components/ui/card.jsx +92 -0
- package/scaffolders/app/template/src/components/ui/chart.jsx +323 -0
- package/scaffolders/app/template/src/components/ui/checkbox.jsx +27 -0
- package/scaffolders/app/template/src/components/ui/command.jsx +154 -0
- package/scaffolders/app/template/src/components/ui/dialog.jsx +122 -0
- package/scaffolders/app/template/src/components/ui/dropdown-menu.jsx +200 -0
- package/scaffolders/app/template/src/components/ui/input.jsx +21 -0
- package/scaffolders/app/template/src/components/ui/label.jsx +19 -0
- package/scaffolders/app/template/src/components/ui/popover.jsx +40 -0
- package/scaffolders/app/template/src/components/ui/progress.jsx +25 -0
- package/scaffolders/app/template/src/components/ui/radio-group.jsx +37 -0
- package/scaffolders/app/template/src/components/ui/scroll-area.jsx +48 -0
- package/scaffolders/app/template/src/components/ui/select.jsx +156 -0
- package/scaffolders/app/template/src/components/ui/separator.jsx +26 -0
- package/scaffolders/app/template/src/components/ui/sheet.jsx +123 -0
- package/scaffolders/app/template/src/components/ui/skeleton.jsx +13 -0
- package/scaffolders/app/template/src/components/ui/slider.jsx +61 -0
- package/scaffolders/app/template/src/components/ui/sonner.jsx +60 -0
- package/scaffolders/app/template/src/components/ui/switch.jsx +26 -0
- package/scaffolders/app/template/src/components/ui/table.jsx +111 -0
- package/scaffolders/app/template/src/components/ui/tabs.jsx +74 -0
- package/scaffolders/app/template/src/components/ui/textarea.jsx +18 -0
- package/scaffolders/app/template/src/components/ui/tooltip.jsx +43 -0
- package/scaffolders/app/template/src/hooks/useForm.js +841 -0
- package/scaffolders/app/template/src/index.css +143 -0
- package/scaffolders/app/template/src/lib/utils.js +6 -0
- package/scaffolders/app/template/src/main.jsx +18 -0
- package/scaffolders/app/template/src/pages/index.jsx +244 -0
- package/scaffolders/app/template/src/themes.css +153 -0
- package/scaffolders/app/template/src/themes.js +32 -0
- package/scaffolders/app/template/vite-kf-live.js +117 -0
- package/scaffolders/app/template/vite.config.js +56 -0
- package/scaffolders/constants.js +25 -0
- package/scaffolders/helpers.js +12 -0
- package/scaffolders/utils.js +109 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from "react";
|
|
2
|
+
import { Loader2, PenLine, Upload, X } from "lucide-react";
|
|
3
|
+
import { FieldLabel } from "./FieldLabel.jsx";
|
|
4
|
+
|
|
5
|
+
const SIGNATURE_PICKER_OPTIONS = {
|
|
6
|
+
fileExtensions: ["JPG", "JPEG", "PNG"],
|
|
7
|
+
maxSize: 10485760,
|
|
8
|
+
maxCount: 1,
|
|
9
|
+
imageProps: {
|
|
10
|
+
sizes: [
|
|
11
|
+
[1200, 800],
|
|
12
|
+
[300, 300]
|
|
13
|
+
],
|
|
14
|
+
crop: false
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function resolveSignatureUrl(value) {
|
|
19
|
+
if (!value) return null;
|
|
20
|
+
if (typeof value === "string") return value;
|
|
21
|
+
if (value.key && window.kf?.client?.getImageUrl)
|
|
22
|
+
return window.kf.client.getImageUrl(value);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function SignatureField({
|
|
27
|
+
field,
|
|
28
|
+
value,
|
|
29
|
+
onChange,
|
|
30
|
+
onBlur,
|
|
31
|
+
error,
|
|
32
|
+
disabled = false
|
|
33
|
+
}) {
|
|
34
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
35
|
+
const [activeTab, setActiveTab] = useState("draw");
|
|
36
|
+
const [previewUrl, setPreviewUrl] = useState(null);
|
|
37
|
+
const [resolving, setResolving] = useState(false);
|
|
38
|
+
const [saving, setSaving] = useState(false);
|
|
39
|
+
const [picking, setPicking] = useState(false);
|
|
40
|
+
const canvasRef = useRef(null);
|
|
41
|
+
const isDrawingRef = useRef(false);
|
|
42
|
+
const readOnly = disabled || field?.ReadOnly;
|
|
43
|
+
|
|
44
|
+
const valueKey = typeof value === "string" ? value : value?.key;
|
|
45
|
+
|
|
46
|
+
useEffect(
|
|
47
|
+
function resolvePreview() {
|
|
48
|
+
let cancelled = false;
|
|
49
|
+
const resolve = async () => {
|
|
50
|
+
if (!value) {
|
|
51
|
+
setPreviewUrl(null);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setResolving(true);
|
|
55
|
+
try {
|
|
56
|
+
const url = await Promise.resolve(resolveSignatureUrl(value));
|
|
57
|
+
if (!cancelled) setPreviewUrl(url);
|
|
58
|
+
} catch {
|
|
59
|
+
if (!cancelled) setPreviewUrl(null);
|
|
60
|
+
} finally {
|
|
61
|
+
if (!cancelled) setResolving(false);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
resolve();
|
|
65
|
+
return function cleanup() {
|
|
66
|
+
cancelled = true;
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
[valueKey]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
useEffect(
|
|
73
|
+
function initCanvas() {
|
|
74
|
+
if (!isEditing || activeTab !== "draw" || !canvasRef.current) return;
|
|
75
|
+
const canvas = canvasRef.current;
|
|
76
|
+
canvas.width = canvas.clientWidth;
|
|
77
|
+
canvas.height = canvas.clientHeight;
|
|
78
|
+
const ctx = canvas.getContext("2d");
|
|
79
|
+
ctx.strokeStyle = "#263045";
|
|
80
|
+
ctx.lineWidth = 2;
|
|
81
|
+
ctx.lineCap = "round";
|
|
82
|
+
ctx.lineJoin = "round";
|
|
83
|
+
if (previewUrl) {
|
|
84
|
+
const img = new Image();
|
|
85
|
+
img.onload = () =>
|
|
86
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
87
|
+
img.src = previewUrl;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
[isEditing, activeTab]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const getPos = (e) => {
|
|
94
|
+
const rect = canvasRef.current.getBoundingClientRect();
|
|
95
|
+
const src = e.touches ? e.touches[0] : e;
|
|
96
|
+
return { x: src.clientX - rect.left, y: src.clientY - rect.top };
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const startDraw = (e) => {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
isDrawingRef.current = true;
|
|
102
|
+
const ctx = canvasRef.current.getContext("2d");
|
|
103
|
+
const { x, y } = getPos(e);
|
|
104
|
+
ctx.beginPath();
|
|
105
|
+
ctx.moveTo(x, y);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const draw = (e) => {
|
|
109
|
+
if (!isDrawingRef.current) return;
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
const ctx = canvasRef.current.getContext("2d");
|
|
112
|
+
const { x, y } = getPos(e);
|
|
113
|
+
ctx.lineTo(x, y);
|
|
114
|
+
ctx.stroke();
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const stopDraw = () => {
|
|
118
|
+
isDrawingRef.current = false;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const clearCanvas = () => {
|
|
122
|
+
const canvas = canvasRef.current;
|
|
123
|
+
canvas.getContext("2d").clearRect(0, 0, canvas.width, canvas.height);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleSaveDraw = async () => {
|
|
127
|
+
setSaving(true);
|
|
128
|
+
try {
|
|
129
|
+
const blob = await new Promise((resolve) =>
|
|
130
|
+
canvasRef.current.toBlob(resolve, "image/png")
|
|
131
|
+
);
|
|
132
|
+
const file = new File([blob], "signature.png", { type: "image/png" });
|
|
133
|
+
const result = await window.kf.client.uploadFile(file);
|
|
134
|
+
if (result) {
|
|
135
|
+
onChange(result);
|
|
136
|
+
onBlur(result);
|
|
137
|
+
setIsEditing(false);
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.error("Signature draw upload failed:", err);
|
|
141
|
+
} finally {
|
|
142
|
+
setSaving(false);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const handleUpload = async () => {
|
|
147
|
+
setPicking(true);
|
|
148
|
+
try {
|
|
149
|
+
const files = await window.kf.client.openFilePicker(
|
|
150
|
+
SIGNATURE_PICKER_OPTIONS
|
|
151
|
+
);
|
|
152
|
+
const file = files?.[0];
|
|
153
|
+
if (file) {
|
|
154
|
+
onChange(file);
|
|
155
|
+
onBlur(file);
|
|
156
|
+
setIsEditing(false);
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.error("Signature upload failed:", err);
|
|
160
|
+
} finally {
|
|
161
|
+
setPicking(false);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const handleRemove = (e) => {
|
|
166
|
+
e.stopPropagation();
|
|
167
|
+
onChange(null);
|
|
168
|
+
onBlur(null);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div className="space-y-2">
|
|
173
|
+
<FieldLabel field={field} htmlFor={field.Id} />
|
|
174
|
+
|
|
175
|
+
{/* Display */}
|
|
176
|
+
{!isEditing && (
|
|
177
|
+
<>
|
|
178
|
+
{value ? (
|
|
179
|
+
<div
|
|
180
|
+
className={`relative group rounded-lg border overflow-hidden bg-muted ${
|
|
181
|
+
error ? "border-destructive/50" : "border-border"
|
|
182
|
+
}`}
|
|
183
|
+
style={{ height: "80px", maxWidth: "300px" }}
|
|
184
|
+
>
|
|
185
|
+
{resolving && (
|
|
186
|
+
<div className="absolute inset-0 flex items-center justify-center">
|
|
187
|
+
<Loader2 className="w-5 h-5 animate-spin text-muted-foreground" />
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
190
|
+
{!resolving && previewUrl && (
|
|
191
|
+
<img
|
|
192
|
+
src={previewUrl}
|
|
193
|
+
alt={`${field.Name} signature`}
|
|
194
|
+
className="w-full h-full object-contain p-2"
|
|
195
|
+
/>
|
|
196
|
+
)}
|
|
197
|
+
{!readOnly && (
|
|
198
|
+
<div className="absolute inset-0 flex items-center justify-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity bg-background/80">
|
|
199
|
+
<button
|
|
200
|
+
type="button"
|
|
201
|
+
onClick={() => setIsEditing(true)}
|
|
202
|
+
className="px-2 py-1 text-xs font-medium text-primary border border-primary/40 rounded hover:bg-primary/10"
|
|
203
|
+
>
|
|
204
|
+
Edit
|
|
205
|
+
</button>
|
|
206
|
+
<button
|
|
207
|
+
type="button"
|
|
208
|
+
onClick={handleRemove}
|
|
209
|
+
className="p-1 text-muted-foreground border border-border rounded hover:text-destructive hover:border-destructive/40"
|
|
210
|
+
>
|
|
211
|
+
<X className="w-3.5 h-3.5" />
|
|
212
|
+
</button>
|
|
213
|
+
</div>
|
|
214
|
+
)}
|
|
215
|
+
</div>
|
|
216
|
+
) : readOnly ? (
|
|
217
|
+
<div
|
|
218
|
+
className="flex items-center justify-center rounded-lg border border-dashed border-border bg-muted text-muted-foreground text-sm"
|
|
219
|
+
style={{ height: "80px", maxWidth: "300px" }}
|
|
220
|
+
>
|
|
221
|
+
No signature
|
|
222
|
+
</div>
|
|
223
|
+
) : (
|
|
224
|
+
<button
|
|
225
|
+
id={field.Id}
|
|
226
|
+
type="button"
|
|
227
|
+
onClick={() => setIsEditing(true)}
|
|
228
|
+
className={`flex items-center gap-2 px-4 py-2 rounded-lg border border-dashed text-sm text-muted-foreground hover:border-input hover:text-foreground transition-colors ${
|
|
229
|
+
error
|
|
230
|
+
? "border-destructive/50 bg-destructive/10"
|
|
231
|
+
: "border-input bg-muted"
|
|
232
|
+
}`}
|
|
233
|
+
>
|
|
234
|
+
<PenLine className="w-4 h-4" />
|
|
235
|
+
Add signature
|
|
236
|
+
</button>
|
|
237
|
+
)}
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
|
|
241
|
+
{/* Inline editor */}
|
|
242
|
+
{isEditing && (
|
|
243
|
+
<div className="rounded-lg border border-border overflow-hidden">
|
|
244
|
+
{/* Tabs */}
|
|
245
|
+
<div className="flex border-b border-border bg-muted">
|
|
246
|
+
{["draw", "upload"].map((tab) => (
|
|
247
|
+
<button
|
|
248
|
+
key={tab}
|
|
249
|
+
type="button"
|
|
250
|
+
onClick={() => setActiveTab(tab)}
|
|
251
|
+
className={`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${
|
|
252
|
+
activeTab === tab
|
|
253
|
+
? "border-ring text-primary bg-background"
|
|
254
|
+
: "border-transparent text-muted-foreground hover:text-foreground"
|
|
255
|
+
}`}
|
|
256
|
+
>
|
|
257
|
+
{tab === "draw" ? "Draw" : "Upload"}
|
|
258
|
+
</button>
|
|
259
|
+
))}
|
|
260
|
+
</div>
|
|
261
|
+
|
|
262
|
+
{activeTab === "draw" ? (
|
|
263
|
+
<div className="p-3 space-y-2 bg-background">
|
|
264
|
+
<canvas
|
|
265
|
+
ref={canvasRef}
|
|
266
|
+
className="w-full rounded border border-border bg-background cursor-crosshair touch-none"
|
|
267
|
+
style={{ height: "160px", display: "block" }}
|
|
268
|
+
onMouseDown={startDraw}
|
|
269
|
+
onMouseMove={draw}
|
|
270
|
+
onMouseUp={stopDraw}
|
|
271
|
+
onMouseLeave={stopDraw}
|
|
272
|
+
onTouchStart={startDraw}
|
|
273
|
+
onTouchMove={draw}
|
|
274
|
+
onTouchEnd={stopDraw}
|
|
275
|
+
/>
|
|
276
|
+
<div className="flex items-center justify-between">
|
|
277
|
+
<button
|
|
278
|
+
type="button"
|
|
279
|
+
onClick={clearCanvas}
|
|
280
|
+
className="text-xs text-muted-foreground hover:text-foreground underline underline-offset-2"
|
|
281
|
+
>
|
|
282
|
+
Clear
|
|
283
|
+
</button>
|
|
284
|
+
<div className="flex gap-2">
|
|
285
|
+
<button
|
|
286
|
+
type="button"
|
|
287
|
+
onClick={() => setIsEditing(false)}
|
|
288
|
+
disabled={saving}
|
|
289
|
+
className="px-3 py-1.5 text-sm text-muted-foreground border border-border rounded-md hover:bg-muted disabled:opacity-50"
|
|
290
|
+
>
|
|
291
|
+
Cancel
|
|
292
|
+
</button>
|
|
293
|
+
<button
|
|
294
|
+
type="button"
|
|
295
|
+
onClick={handleSaveDraw}
|
|
296
|
+
disabled={saving}
|
|
297
|
+
className="flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50"
|
|
298
|
+
>
|
|
299
|
+
{saving && <Loader2 className="w-3.5 h-3.5 animate-spin" />}
|
|
300
|
+
Save
|
|
301
|
+
</button>
|
|
302
|
+
</div>
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
) : (
|
|
306
|
+
<div className="p-3 bg-background flex flex-col items-center gap-3 py-6">
|
|
307
|
+
<p className="text-sm text-muted-foreground">
|
|
308
|
+
Upload a JPG or PNG image of your signature
|
|
309
|
+
</p>
|
|
310
|
+
<div className="flex gap-2">
|
|
311
|
+
<button
|
|
312
|
+
type="button"
|
|
313
|
+
onClick={() => setIsEditing(false)}
|
|
314
|
+
className="px-3 py-1.5 text-sm text-muted-foreground border border-border rounded-md hover:bg-muted"
|
|
315
|
+
>
|
|
316
|
+
Cancel
|
|
317
|
+
</button>
|
|
318
|
+
<button
|
|
319
|
+
type="button"
|
|
320
|
+
onClick={handleUpload}
|
|
321
|
+
disabled={picking}
|
|
322
|
+
className="flex items-center gap-2 px-4 py-1.5 text-sm font-medium border border-input rounded-md hover:bg-muted disabled:opacity-50"
|
|
323
|
+
>
|
|
324
|
+
{picking ? (
|
|
325
|
+
<Loader2 className="w-4 h-4 animate-spin" />
|
|
326
|
+
) : (
|
|
327
|
+
<Upload className="w-4 h-4" />
|
|
328
|
+
)}
|
|
329
|
+
Choose image
|
|
330
|
+
</button>
|
|
331
|
+
</div>
|
|
332
|
+
</div>
|
|
333
|
+
)}
|
|
334
|
+
</div>
|
|
335
|
+
)}
|
|
336
|
+
|
|
337
|
+
{error && !isEditing && (
|
|
338
|
+
<p className="text-sm text-destructive">
|
|
339
|
+
{Array.isArray(error) ? error[0] : error}
|
|
340
|
+
</p>
|
|
341
|
+
)}
|
|
342
|
+
</div>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Slider } from "@/components/ui/slider";
|
|
2
|
+
import { FieldError } from "./FieldError.jsx";
|
|
3
|
+
import { FieldLabel } from "./FieldLabel.jsx";
|
|
4
|
+
|
|
5
|
+
export function SliderField({
|
|
6
|
+
field,
|
|
7
|
+
value,
|
|
8
|
+
onChange,
|
|
9
|
+
onBlur,
|
|
10
|
+
error,
|
|
11
|
+
disabled = false
|
|
12
|
+
}) {
|
|
13
|
+
const min = Number(field.MinValue) ?? 0;
|
|
14
|
+
const max = Number(field.MaxValue) ?? 10;
|
|
15
|
+
const step = Number(field.IntervalSize) ?? 1;
|
|
16
|
+
const current = value ?? Number(field.DefaultValue) ?? min;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="space-y-2">
|
|
20
|
+
<FieldLabel field={field} htmlFor={field.Id} />
|
|
21
|
+
<div className="flex items-center gap-4 pt-2">
|
|
22
|
+
<Slider
|
|
23
|
+
id={field.Id}
|
|
24
|
+
value={[current]}
|
|
25
|
+
min={min}
|
|
26
|
+
max={max}
|
|
27
|
+
step={step}
|
|
28
|
+
disabled={disabled || field.ReadOnly}
|
|
29
|
+
onValueChange={([val]) => onChange(val)}
|
|
30
|
+
onValueCommit={([val]) => onBlur(val)}
|
|
31
|
+
/>
|
|
32
|
+
<span className="w-12 text-right text-sm font-medium text-muted-foreground tabular-nums">
|
|
33
|
+
{current}
|
|
34
|
+
</span>
|
|
35
|
+
</div>
|
|
36
|
+
<FieldError error={error} />
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Paperclip,
|
|
4
|
+
X,
|
|
5
|
+
Loader2,
|
|
6
|
+
Sparkles,
|
|
7
|
+
FileText,
|
|
8
|
+
FileImage
|
|
9
|
+
} from "lucide-react";
|
|
10
|
+
import { FieldError } from "./FieldError.jsx";
|
|
11
|
+
import { FieldLabel } from "./FieldLabel.jsx";
|
|
12
|
+
|
|
13
|
+
// Matches the platform's SMART_ATTACHMENT_WIDGET constants
|
|
14
|
+
// (widgets/common/src/libs/document.parser.service.js)
|
|
15
|
+
const SMART_ATTACHMENT_PICKER_OPTIONS = {
|
|
16
|
+
fileExtensions: ["PDF", "JPG", "JPEG", "PNG"],
|
|
17
|
+
maxSize: 1024 * 1024 * 20,
|
|
18
|
+
maxCount: 1
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const ICONS_BY_EXT = {
|
|
22
|
+
JPG: FileImage,
|
|
23
|
+
JPEG: FileImage,
|
|
24
|
+
PNG: FileImage,
|
|
25
|
+
PDF: FileText
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const iconForFile = (file) =>
|
|
29
|
+
ICONS_BY_EXT[(file.fileExtension || "").toUpperCase()] || FileText;
|
|
30
|
+
|
|
31
|
+
const formatSize = (bytes) => {
|
|
32
|
+
if (!bytes && bytes !== 0) return "";
|
|
33
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
34
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
35
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export function SmartAttachmentField({
|
|
39
|
+
field,
|
|
40
|
+
value,
|
|
41
|
+
onChange,
|
|
42
|
+
onBlur,
|
|
43
|
+
error,
|
|
44
|
+
disabled = false,
|
|
45
|
+
parseAttachment
|
|
46
|
+
}) {
|
|
47
|
+
const [file, setFile] = useState(
|
|
48
|
+
Array.isArray(value) ? value[0] : value || null
|
|
49
|
+
);
|
|
50
|
+
const [picking, setPicking] = useState(false);
|
|
51
|
+
const [parsing, setParsing] = useState(false);
|
|
52
|
+
const [autofillResult, setAutofillResult] = useState(null);
|
|
53
|
+
const [parseError, setParseError] = useState(null);
|
|
54
|
+
const readOnly = disabled || field.ReadOnly;
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
setFile(Array.isArray(value) ? value[0] : value || null);
|
|
58
|
+
}, [value]);
|
|
59
|
+
|
|
60
|
+
const handlePick = async () => {
|
|
61
|
+
setPicking(true);
|
|
62
|
+
setParseError(null);
|
|
63
|
+
try {
|
|
64
|
+
const picked = await window.kf.client.openFilePicker(
|
|
65
|
+
SMART_ATTACHMENT_PICKER_OPTIONS
|
|
66
|
+
);
|
|
67
|
+
const pickedFile = picked?.[0];
|
|
68
|
+
if (!pickedFile) return;
|
|
69
|
+
|
|
70
|
+
setFile(pickedFile);
|
|
71
|
+
onChange([pickedFile]);
|
|
72
|
+
onBlur([pickedFile]);
|
|
73
|
+
|
|
74
|
+
if (!parseAttachment) return;
|
|
75
|
+
setParsing(true);
|
|
76
|
+
setAutofillResult(null);
|
|
77
|
+
try {
|
|
78
|
+
const result = await parseAttachment(field.Id, pickedFile);
|
|
79
|
+
setAutofillResult(result);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
setParseError(err.message || "Autofill failed, please try again.");
|
|
82
|
+
} finally {
|
|
83
|
+
setParsing(false);
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(`Failed to pick file for ${field.Name}:`, err);
|
|
87
|
+
} finally {
|
|
88
|
+
setPicking(false);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handlePreview = () => {
|
|
93
|
+
if (!file) return;
|
|
94
|
+
window.kf.client.openFilePreview({ files: [file] });
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleRemove = (e) => {
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
setFile(null);
|
|
100
|
+
setAutofillResult(null);
|
|
101
|
+
setParseError(null);
|
|
102
|
+
onChange(null);
|
|
103
|
+
onBlur(null);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const Icon = file ? iconForFile(file) : Paperclip;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div className="space-y-2">
|
|
110
|
+
<FieldLabel
|
|
111
|
+
field={field}
|
|
112
|
+
htmlFor={field.Id}
|
|
113
|
+
className="flex items-center gap-1.5 text-sm font-semibold text-foreground"
|
|
114
|
+
>
|
|
115
|
+
<Sparkles className="w-3.5 h-3.5 text-info" />
|
|
116
|
+
</FieldLabel>
|
|
117
|
+
<div
|
|
118
|
+
id={field.Id}
|
|
119
|
+
className="space-y-2 border border-input rounded-lg p-3"
|
|
120
|
+
>
|
|
121
|
+
{file ? (
|
|
122
|
+
<div
|
|
123
|
+
onClick={handlePreview}
|
|
124
|
+
className="group flex items-center gap-2.5 rounded-md border border-border bg-muted px-3 py-2 cursor-pointer hover:border-input hover:bg-muted transition-colors"
|
|
125
|
+
>
|
|
126
|
+
<Icon className="w-5 h-5 text-muted-foreground shrink-0" />
|
|
127
|
+
<div className="min-w-0 flex-1">
|
|
128
|
+
<p className="text-sm text-foreground truncate">{file.name}</p>
|
|
129
|
+
{file.size != null && (
|
|
130
|
+
<p className="text-xs text-muted-foreground">
|
|
131
|
+
{formatSize(file.size)}
|
|
132
|
+
</p>
|
|
133
|
+
)}
|
|
134
|
+
</div>
|
|
135
|
+
{!readOnly && (
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
onClick={handleRemove}
|
|
139
|
+
className="p-1 rounded-full text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer hover:text-destructive hover:bg-background"
|
|
140
|
+
aria-label={`Remove ${file.name}`}
|
|
141
|
+
>
|
|
142
|
+
<X className="w-3.5 h-3.5" />
|
|
143
|
+
</button>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
) : (
|
|
147
|
+
<p className="text-sm text-muted-foreground">No file attached</p>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{!readOnly && !file && (
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
onClick={handlePick}
|
|
154
|
+
disabled={picking}
|
|
155
|
+
className="w-full flex items-center justify-center gap-2 rounded-md border border-dashed border-input bg-muted px-3 py-2 text-sm text-muted-foreground transition-colors cursor-pointer hover:border-input hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60"
|
|
156
|
+
>
|
|
157
|
+
{picking ? (
|
|
158
|
+
<Loader2 className="w-4 h-4 animate-spin" />
|
|
159
|
+
) : (
|
|
160
|
+
<Paperclip className="w-4 h-4" />
|
|
161
|
+
)}
|
|
162
|
+
<span>Attach file (PDF, JPG, PNG)</span>
|
|
163
|
+
</button>
|
|
164
|
+
)}
|
|
165
|
+
|
|
166
|
+
{parsing && (
|
|
167
|
+
<p className="flex items-center gap-1.5 text-sm text-info">
|
|
168
|
+
<Loader2 className="w-3.5 h-3.5 animate-spin" />
|
|
169
|
+
Autofilling fields from {file?.name}...
|
|
170
|
+
</p>
|
|
171
|
+
)}
|
|
172
|
+
|
|
173
|
+
{!parsing && autofillResult && (
|
|
174
|
+
<p className="text-sm text-info">
|
|
175
|
+
Auto-filled {autofillResult.appliedFields?.length || 0} field
|
|
176
|
+
{autofillResult.appliedFields?.length === 1 ? "" : "s"} from{" "}
|
|
177
|
+
{autofillResult.suggestedBy}
|
|
178
|
+
</p>
|
|
179
|
+
)}
|
|
180
|
+
|
|
181
|
+
{!parsing && parseError && (
|
|
182
|
+
<p className="text-sm text-destructive">{parseError}</p>
|
|
183
|
+
)}
|
|
184
|
+
</div>
|
|
185
|
+
<FieldError error={error} />
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Input } from "@/components/ui/input";
|
|
2
|
+
import { FieldError } from "./FieldError.jsx";
|
|
3
|
+
import { FieldLabel } from "./FieldLabel.jsx";
|
|
4
|
+
|
|
5
|
+
export function TextField({
|
|
6
|
+
field,
|
|
7
|
+
value,
|
|
8
|
+
onChange,
|
|
9
|
+
onBlur,
|
|
10
|
+
error,
|
|
11
|
+
disabled = false
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<div className="space-y-2">
|
|
15
|
+
<FieldLabel field={field} htmlFor={field.Id} />
|
|
16
|
+
<Input
|
|
17
|
+
id={field.Id}
|
|
18
|
+
type="text"
|
|
19
|
+
name={field.Id}
|
|
20
|
+
value={value || ""}
|
|
21
|
+
onChange={(e) => onChange(e.target.value)}
|
|
22
|
+
onBlur={(e) => onBlur(e.target.value)}
|
|
23
|
+
placeholder={`Enter ${field.Name.toLowerCase()}`}
|
|
24
|
+
disabled={disabled || field.ReadOnly}
|
|
25
|
+
className={error ? "border-destructive/50 bg-destructive/10" : ""}
|
|
26
|
+
/>
|
|
27
|
+
<FieldError error={error} />
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
2
|
+
import { FieldError } from "./FieldError.jsx";
|
|
3
|
+
import { FieldLabel } from "./FieldLabel.jsx";
|
|
4
|
+
|
|
5
|
+
export function TextareaField({
|
|
6
|
+
field,
|
|
7
|
+
value,
|
|
8
|
+
onChange,
|
|
9
|
+
onBlur,
|
|
10
|
+
error,
|
|
11
|
+
disabled = false
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<div className="space-y-2">
|
|
15
|
+
<FieldLabel field={field} htmlFor={field.Id} />
|
|
16
|
+
<Textarea
|
|
17
|
+
id={field.Id}
|
|
18
|
+
name={field.Id}
|
|
19
|
+
value={value || ""}
|
|
20
|
+
onChange={(e) => onChange(e.target.value)}
|
|
21
|
+
onBlur={(e) => onBlur(e.target.value)}
|
|
22
|
+
placeholder={`Enter ${field.Name.toLowerCase()}`}
|
|
23
|
+
disabled={disabled || field.ReadOnly}
|
|
24
|
+
rows={4}
|
|
25
|
+
className={error ? "border-destructive/50 bg-destructive/10" : ""}
|
|
26
|
+
/>
|
|
27
|
+
<FieldError error={error} />
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|