@aglyn/plugins-forms 1.0.0-beta.290 → 1.0.0-beta.292
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/README.md +11 -1
- package/package.json +14 -14
- package/src/lib/components/form-detail-card.js +122 -2
- package/src/lib/components/form-detail-card.js.map +1 -1
- package/src/lib/components/form-file-upload-body.d.ts +32 -0
- package/src/lib/components/form-file-upload-body.js +349 -0
- package/src/lib/components/form-file-upload-body.js.map +1 -0
- package/src/lib/components/form-file-upload.d.ts +39 -0
- package/src/lib/components/form-file-upload.js +175 -0
- package/src/lib/components/form-file-upload.js.map +1 -0
- package/src/lib/components/form-upload-context.d.ts +31 -0
- package/src/lib/components/form-upload-context.js +19 -0
- package/src/lib/components/form-upload-context.js.map +1 -0
- package/src/lib/components/form.js +48 -4
- package/src/lib/components/form.js.map +1 -1
- package/src/lib/declarations.console-server.js +14 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.server.js +18 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/form-request.d.ts +102 -0
- package/src/lib/model/form-request.js +187 -0
- package/src/lib/model/form-request.js.map +1 -0
- package/src/lib/server/form-confirmation-email.d.ts +70 -0
- package/src/lib/server/form-confirmation-email.js +194 -0
- package/src/lib/server/form-confirmation-email.js.map +1 -0
- package/src/lib/server/form-submit-files.d.ts +42 -0
- package/src/lib/server/form-submit-files.js +98 -0
- package/src/lib/server/form-submit-files.js.map +1 -0
- package/src/lib/server/form-submit.js +115 -7
- package/src/lib/server/form-submit.js.map +1 -1
- package/src/lib/server/form-upload-sweep.d.ts +30 -0
- package/src/lib/server/form-upload-sweep.js +83 -0
- package/src/lib/server/form-upload-sweep.js.map +1 -0
- package/src/lib/server/form-upload.d.ts +41 -0
- package/src/lib/server/form-upload.js +226 -0
- package/src/lib/server/form-upload.js.map +1 -0
- package/src/lib/server/form-uploads.d.ts +34 -0
- package/src/lib/server/form-uploads.js +29 -0
- package/src/lib/server/form-uploads.js.map +1 -0
- package/src/lib/server/submission-access.d.ts +38 -0
- package/src/lib/server/submission-access.js +37 -0
- package/src/lib/server/submission-access.js.map +1 -0
- package/src/lib/server/submission-facts.d.ts +37 -0
- package/src/lib/server/submission-facts.js +227 -0
- package/src/lib/server/submission-facts.js.map +1 -0
- package/src/lib/server/submission-files.d.ts +41 -0
- package/src/lib/server/submission-files.js +126 -0
- package/src/lib/server/submission-files.js.map +1 -0
- package/src/lib/server.js +22 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +8 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/tenant-emails.d.ts +29 -0
- package/src/lib/tenant-emails.js +125 -0
- package/src/lib/tenant-emails.js.map +1 -0
- package/src/lib/testing/stand-in-firestore.d.ts +27 -0
- package/src/lib/testing/stand-in-firestore.js +128 -0
- package/src/lib/testing/stand-in-firestore.js.map +1 -0
- package/src/lib/utils/form-confirmation-content.d.ts +47 -0
- package/src/lib/utils/form-confirmation-content.js +109 -0
- package/src/lib/utils/form-confirmation-content.js.map +1 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { FormFileUploadProps } from './form-file-upload';
|
|
18
|
+
/**
|
|
19
|
+
* The File upload field's body (AGL-4098): a button that picks files, each
|
|
20
|
+
* file's progress while it goes up, Remove, and what the form sends — a
|
|
21
|
+
* hidden `field:id` per kept file and, under the field's name, their names.
|
|
22
|
+
* The names' input is a real one, invisible under the button, so a required
|
|
23
|
+
* field with nothing attached stops the form like any required field, and a
|
|
24
|
+
* field still uploading stops it with a sentence that says to wait.
|
|
25
|
+
*
|
|
26
|
+
* The upload itself is the shared visitor upload: a ticket from
|
|
27
|
+
* `/api/forms/upload`, the bytes posted straight to storage, then the route
|
|
28
|
+
* checks and keeps them. A browser cannot report the progress of a post to
|
|
29
|
+
* another site's storage, so a file shows that it is on its way, then kept.
|
|
30
|
+
*/
|
|
31
|
+
declare const FormFileUploadBody: import("react").ForwardRefExoticComponent<FormFileUploadProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
32
|
+
export default FormFileUploadBody;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2026 Aglyn LLC
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/ import * as Aglyn from "@aglyn/aglyn";
|
|
20
|
+
import { formFileFieldLimits } from "@aglyn/aglyn/app-utils/forms";
|
|
21
|
+
import { checkVisitorUploadSelection, describeVisitorUploadTypes, formatVisitorUploadBytes, visitorUploadAccept, VISITOR_UPLOAD_MAX_BYTES } from "@aglyn/aglyn/app-utils/visitor-upload";
|
|
22
|
+
import { sendVisitorUpload } from "@aglyn/aglyn/app-utils/visitor-upload-client";
|
|
23
|
+
import Alert from "@mui/material/Alert";
|
|
24
|
+
import Box from "@mui/material/Box";
|
|
25
|
+
import Button from "@mui/material/Button";
|
|
26
|
+
import FormControl from "@mui/material/FormControl";
|
|
27
|
+
import FormHelperText from "@mui/material/FormHelperText";
|
|
28
|
+
import FormLabel from "@mui/material/FormLabel";
|
|
29
|
+
import LinearProgress from "@mui/material/LinearProgress";
|
|
30
|
+
import Paper from "@mui/material/Paper";
|
|
31
|
+
import Stack from "@mui/material/Stack";
|
|
32
|
+
import Typography from "@mui/material/Typography";
|
|
33
|
+
import { forwardRef, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
34
|
+
import { FORM_FILE_INPUT, formFileInputValue } from "../model/form-request.js";
|
|
35
|
+
import { FormUploadContext } from "./form-upload-context.js";
|
|
36
|
+
const STILL_SENDING = 'Wait for your files to finish uploading.';
|
|
37
|
+
let sequence = 0;
|
|
38
|
+
/**
|
|
39
|
+
* The File upload field's body (AGL-4098): a button that picks files, each
|
|
40
|
+
* file's progress while it goes up, Remove, and what the form sends — a
|
|
41
|
+
* hidden `field:id` per kept file and, under the field's name, their names.
|
|
42
|
+
* The names' input is a real one, invisible under the button, so a required
|
|
43
|
+
* field with nothing attached stops the form like any required field, and a
|
|
44
|
+
* field still uploading stops it with a sentence that says to wait.
|
|
45
|
+
*
|
|
46
|
+
* The upload itself is the shared visitor upload: a ticket from
|
|
47
|
+
* `/api/forms/upload`, the bytes posted straight to storage, then the route
|
|
48
|
+
* checks and keeps them. A browser cannot report the progress of a post to
|
|
49
|
+
* another site's storage, so a file shows that it is on its way, then kept.
|
|
50
|
+
*/ const FormFileUploadBody = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
51
|
+
const { name: rawName, label, helperText, required, kinds: rawKinds, maxFiles: rawMax } = props, rest = _object_without_properties_loose(props, [
|
|
52
|
+
"name",
|
|
53
|
+
"label",
|
|
54
|
+
"helperText",
|
|
55
|
+
"required",
|
|
56
|
+
"kinds",
|
|
57
|
+
"maxFiles"
|
|
58
|
+
]);
|
|
59
|
+
const name = String(rawName != null ? rawName : '').trim() || 'files';
|
|
60
|
+
const { fileKinds, maxFiles } = formFileFieldLimits({
|
|
61
|
+
kinds: rawKinds,
|
|
62
|
+
maxFiles: rawMax
|
|
63
|
+
});
|
|
64
|
+
const upload = useContext(FormUploadContext);
|
|
65
|
+
const { hostId } = Aglyn.useSite();
|
|
66
|
+
const siteFetch = Aglyn.useSiteFetch();
|
|
67
|
+
const inputId = useId();
|
|
68
|
+
const pickerRef = useRef(null);
|
|
69
|
+
const answerRef = useRef(null);
|
|
70
|
+
const [picked, setPicked] = useState([]);
|
|
71
|
+
const [notice, setNotice] = useState('');
|
|
72
|
+
const kept = picked.filter((entry)=>entry.state === 'kept' && entry.file);
|
|
73
|
+
const sending = picked.some((entry)=>entry.state === 'sending');
|
|
74
|
+
const answer = kept.map((entry)=>{
|
|
75
|
+
var _ref;
|
|
76
|
+
var _entry_file;
|
|
77
|
+
return (_ref = (_entry_file = entry.file) == null ? void 0 : _entry_file.name) != null ? _ref : entry.name;
|
|
78
|
+
}).join(', ');
|
|
79
|
+
const live = Boolean((upload == null ? void 0 : upload.live) && upload.formId && hostId);
|
|
80
|
+
// A field still uploading holds the form back, in the browser's own words.
|
|
81
|
+
useEffect(()=>{
|
|
82
|
+
var _answerRef_current;
|
|
83
|
+
(_answerRef_current = answerRef.current) == null ? void 0 : _answerRef_current.setCustomValidity(sending ? STILL_SENDING : '');
|
|
84
|
+
}, [
|
|
85
|
+
sending
|
|
86
|
+
]);
|
|
87
|
+
// Every change is announced, as a typed answer is, to anything listening on the form.
|
|
88
|
+
const announced = useRef(answer);
|
|
89
|
+
useEffect(()=>{
|
|
90
|
+
var _answerRef_current;
|
|
91
|
+
if (announced.current === answer) return;
|
|
92
|
+
announced.current = answer;
|
|
93
|
+
(_answerRef_current = answerRef.current) == null ? void 0 : _answerRef_current.dispatchEvent(new Event('change', {
|
|
94
|
+
bubbles: true
|
|
95
|
+
}));
|
|
96
|
+
}, [
|
|
97
|
+
answer
|
|
98
|
+
]);
|
|
99
|
+
const post = useCallback(async (body)=>{
|
|
100
|
+
const response = await siteFetch('/api/forms/upload', {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json'
|
|
104
|
+
},
|
|
105
|
+
body: JSON.stringify(_extends({
|
|
106
|
+
hostId,
|
|
107
|
+
formId: upload == null ? void 0 : upload.formId,
|
|
108
|
+
key: upload == null ? void 0 : upload.uploadKey(),
|
|
109
|
+
field: name
|
|
110
|
+
}, body))
|
|
111
|
+
});
|
|
112
|
+
const payload = await response.json().catch(()=>({}));
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
return {
|
|
115
|
+
error: typeof (payload == null ? void 0 : payload.error) === 'string' ? payload.error : 'The file could not be sent. Try again.'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return payload;
|
|
119
|
+
}, [
|
|
120
|
+
siteFetch,
|
|
121
|
+
hostId,
|
|
122
|
+
upload,
|
|
123
|
+
name
|
|
124
|
+
]);
|
|
125
|
+
const sendOne = useCallback(async (key, file)=>{
|
|
126
|
+
const outcome = await sendVisitorUpload({
|
|
127
|
+
file,
|
|
128
|
+
requestTicket: (request)=>post({
|
|
129
|
+
action: 'ticket',
|
|
130
|
+
file: request
|
|
131
|
+
}),
|
|
132
|
+
finalize: (ticket)=>post({
|
|
133
|
+
action: 'finalize',
|
|
134
|
+
ticket
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
setPicked((current)=>current.map((entry)=>entry.key !== key ? entry : 'error' in outcome ? _extends({}, entry, {
|
|
138
|
+
state: 'refused',
|
|
139
|
+
error: outcome.error
|
|
140
|
+
}) : _extends({}, entry, {
|
|
141
|
+
state: 'kept',
|
|
142
|
+
file: outcome.file
|
|
143
|
+
})));
|
|
144
|
+
}, [
|
|
145
|
+
post
|
|
146
|
+
]);
|
|
147
|
+
const onPick = useCallback((event)=>{
|
|
148
|
+
var _event_target_files;
|
|
149
|
+
const files = Array.from((_event_target_files = event.target.files) != null ? _event_target_files : []);
|
|
150
|
+
event.target.value = '';
|
|
151
|
+
if (!files.length) return;
|
|
152
|
+
const refused = checkVisitorUploadSelection(files.map((file)=>({
|
|
153
|
+
name: file.name,
|
|
154
|
+
type: file.type,
|
|
155
|
+
size: file.size
|
|
156
|
+
})), picked.filter((entry)=>entry.state !== 'refused').length, maxFiles, fileKinds);
|
|
157
|
+
if (refused) return void setNotice(refused);
|
|
158
|
+
setNotice('');
|
|
159
|
+
const added = files.map((file)=>({
|
|
160
|
+
key: `file-${++sequence}`,
|
|
161
|
+
name: file.name,
|
|
162
|
+
size: file.size,
|
|
163
|
+
state: 'sending'
|
|
164
|
+
}));
|
|
165
|
+
setPicked((current)=>[
|
|
166
|
+
...current.filter((entry)=>entry.state !== 'refused'),
|
|
167
|
+
...added
|
|
168
|
+
]);
|
|
169
|
+
added.forEach((entry, index)=>void sendOne(entry.key, files[index]));
|
|
170
|
+
}, [
|
|
171
|
+
picked,
|
|
172
|
+
maxFiles,
|
|
173
|
+
fileKinds,
|
|
174
|
+
sendOne
|
|
175
|
+
]);
|
|
176
|
+
const onRemove = useCallback((entry)=>{
|
|
177
|
+
setPicked((current)=>current.filter((one)=>one.key !== entry.key));
|
|
178
|
+
if (entry.file) void post({
|
|
179
|
+
action: 'remove',
|
|
180
|
+
fileId: entry.file.id
|
|
181
|
+
}).catch(()=>undefined);
|
|
182
|
+
}, [
|
|
183
|
+
post
|
|
184
|
+
]);
|
|
185
|
+
const hint = useMemo(()=>{
|
|
186
|
+
const count = maxFiles === 1 ? 'One file' : `Up to ${maxFiles} files`;
|
|
187
|
+
return `${count}: ${describeVisitorUploadTypes(fileKinds)}, up to ${formatVisitorUploadBytes(VISITOR_UPLOAD_MAX_BYTES)} each.`;
|
|
188
|
+
}, [
|
|
189
|
+
maxFiles,
|
|
190
|
+
fileKinds
|
|
191
|
+
]);
|
|
192
|
+
const full = picked.filter((entry)=>entry.state !== 'refused').length >= maxFiles;
|
|
193
|
+
return /*#__PURE__*/ _jsxs(FormControl, _extends({
|
|
194
|
+
ref: ref,
|
|
195
|
+
fullWidth: true,
|
|
196
|
+
required: Boolean(required)
|
|
197
|
+
}, rest, {
|
|
198
|
+
children: [
|
|
199
|
+
/*#__PURE__*/ _jsx(FormLabel, {
|
|
200
|
+
htmlFor: inputId,
|
|
201
|
+
children: label || 'Files'
|
|
202
|
+
}),
|
|
203
|
+
helperText ? /*#__PURE__*/ _jsx(FormHelperText, {
|
|
204
|
+
sx: {
|
|
205
|
+
mx: 0
|
|
206
|
+
},
|
|
207
|
+
children: helperText
|
|
208
|
+
}) : null,
|
|
209
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
210
|
+
sx: {
|
|
211
|
+
position: 'relative',
|
|
212
|
+
mt: 1
|
|
213
|
+
},
|
|
214
|
+
children: [
|
|
215
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
216
|
+
variant: "outlined",
|
|
217
|
+
disabled: !live || full,
|
|
218
|
+
onClick: ()=>{
|
|
219
|
+
var _pickerRef_current;
|
|
220
|
+
return (_pickerRef_current = pickerRef.current) == null ? void 0 : _pickerRef_current.click();
|
|
221
|
+
},
|
|
222
|
+
"aria-describedby": `${inputId}-hint`,
|
|
223
|
+
children: picked.length ? 'Attach more files' : maxFiles === 1 ? 'Attach a file' : 'Attach files'
|
|
224
|
+
}),
|
|
225
|
+
/*#__PURE__*/ _jsx("input", {
|
|
226
|
+
ref: pickerRef,
|
|
227
|
+
id: inputId,
|
|
228
|
+
type: "file",
|
|
229
|
+
hidden: true,
|
|
230
|
+
multiple: maxFiles > 1,
|
|
231
|
+
accept: visitorUploadAccept(fileKinds),
|
|
232
|
+
onChange: onPick
|
|
233
|
+
}),
|
|
234
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
235
|
+
component: "input",
|
|
236
|
+
ref: answerRef,
|
|
237
|
+
type: "text",
|
|
238
|
+
name: name,
|
|
239
|
+
value: answer,
|
|
240
|
+
required: Boolean(required),
|
|
241
|
+
onChange: ()=>undefined,
|
|
242
|
+
onInvalid: ()=>{
|
|
243
|
+
var _pickerRef_current;
|
|
244
|
+
return (_pickerRef_current = pickerRef.current) == null ? void 0 : _pickerRef_current.focus();
|
|
245
|
+
},
|
|
246
|
+
tabIndex: -1,
|
|
247
|
+
"aria-hidden": "true",
|
|
248
|
+
autoComplete: "off",
|
|
249
|
+
sx: {
|
|
250
|
+
position: 'absolute',
|
|
251
|
+
left: 0,
|
|
252
|
+
bottom: 0,
|
|
253
|
+
width: 1,
|
|
254
|
+
height: '1px',
|
|
255
|
+
p: 0,
|
|
256
|
+
border: 0,
|
|
257
|
+
opacity: 0,
|
|
258
|
+
pointerEvents: 'none'
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
]
|
|
262
|
+
}),
|
|
263
|
+
/*#__PURE__*/ _jsx(FormHelperText, {
|
|
264
|
+
id: `${inputId}-hint`,
|
|
265
|
+
sx: {
|
|
266
|
+
mx: 0
|
|
267
|
+
},
|
|
268
|
+
children: live ? hint : 'Files can be attached on the published site.'
|
|
269
|
+
}),
|
|
270
|
+
notice ? /*#__PURE__*/ _jsx(Alert, {
|
|
271
|
+
severity: "warning",
|
|
272
|
+
sx: {
|
|
273
|
+
mt: 1
|
|
274
|
+
},
|
|
275
|
+
children: notice
|
|
276
|
+
}) : null,
|
|
277
|
+
picked.length ? /*#__PURE__*/ _jsx(Stack, {
|
|
278
|
+
spacing: 1,
|
|
279
|
+
sx: {
|
|
280
|
+
mt: 1
|
|
281
|
+
},
|
|
282
|
+
children: picked.map((entry)=>{
|
|
283
|
+
var _ref, _ref1;
|
|
284
|
+
var _entry_file, _entry_file1;
|
|
285
|
+
return /*#__PURE__*/ _jsxs(Paper, {
|
|
286
|
+
variant: "outlined",
|
|
287
|
+
sx: {
|
|
288
|
+
p: 1
|
|
289
|
+
},
|
|
290
|
+
children: [
|
|
291
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
292
|
+
direction: "row",
|
|
293
|
+
spacing: 1,
|
|
294
|
+
sx: {
|
|
295
|
+
alignItems: 'center'
|
|
296
|
+
},
|
|
297
|
+
children: [
|
|
298
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
299
|
+
sx: {
|
|
300
|
+
minWidth: 0,
|
|
301
|
+
flex: 1
|
|
302
|
+
},
|
|
303
|
+
children: [
|
|
304
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
305
|
+
variant: "body2",
|
|
306
|
+
noWrap: true,
|
|
307
|
+
title: entry.name,
|
|
308
|
+
children: (_ref = (_entry_file = entry.file) == null ? void 0 : _entry_file.name) != null ? _ref : entry.name
|
|
309
|
+
}),
|
|
310
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
311
|
+
variant: "caption",
|
|
312
|
+
color: entry.state === 'refused' ? 'error' : 'text.secondary',
|
|
313
|
+
children: entry.state === 'sending' ? `Uploading · ${formatVisitorUploadBytes(entry.size)}` : entry.state === 'refused' ? entry.error : formatVisitorUploadBytes((_ref1 = (_entry_file1 = entry.file) == null ? void 0 : _entry_file1.size) != null ? _ref1 : entry.size)
|
|
314
|
+
}),
|
|
315
|
+
entry.state === 'sending' ? /*#__PURE__*/ _jsx(LinearProgress, {
|
|
316
|
+
sx: {
|
|
317
|
+
mt: 0.5
|
|
318
|
+
},
|
|
319
|
+
"aria-label": `Uploading ${entry.name}`
|
|
320
|
+
}) : null
|
|
321
|
+
]
|
|
322
|
+
}),
|
|
323
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
324
|
+
size: "small",
|
|
325
|
+
color: "inherit",
|
|
326
|
+
disabled: entry.state === 'sending',
|
|
327
|
+
onClick: ()=>onRemove(entry),
|
|
328
|
+
"aria-label": `Remove ${entry.name}`,
|
|
329
|
+
children: 'Remove'
|
|
330
|
+
})
|
|
331
|
+
]
|
|
332
|
+
}),
|
|
333
|
+
entry.file ? /*#__PURE__*/ _jsx("input", {
|
|
334
|
+
type: "hidden",
|
|
335
|
+
name: FORM_FILE_INPUT,
|
|
336
|
+
value: formFileInputValue(name, entry.file.id),
|
|
337
|
+
readOnly: true
|
|
338
|
+
}) : null
|
|
339
|
+
]
|
|
340
|
+
}, entry.key);
|
|
341
|
+
})
|
|
342
|
+
}) : null
|
|
343
|
+
]
|
|
344
|
+
}));
|
|
345
|
+
});
|
|
346
|
+
FormFileUploadBody.displayName = 'AglynFormFileUploadBody';
|
|
347
|
+
export default FormFileUploadBody;
|
|
348
|
+
|
|
349
|
+
//# sourceMappingURL=form-file-upload-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/components/form-file-upload-body.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport { formFileFieldLimits } from '@aglyn/aglyn/app-utils/forms'\nimport {\n checkVisitorUploadSelection,\n describeVisitorUploadTypes,\n formatVisitorUploadBytes,\n visitorUploadAccept,\n VISITOR_UPLOAD_MAX_BYTES,\n type VisitorUploadFileView,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { sendVisitorUpload } from '@aglyn/aglyn/app-utils/visitor-upload-client'\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport FormControl from '@mui/material/FormControl'\nimport FormHelperText from '@mui/material/FormHelperText'\nimport FormLabel from '@mui/material/FormLabel'\nimport LinearProgress from '@mui/material/LinearProgress'\nimport Paper from '@mui/material/Paper'\nimport Stack from '@mui/material/Stack'\nimport Typography from '@mui/material/Typography'\nimport {\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n} from 'react'\nimport { FORM_FILE_INPUT, formFileInputValue } from '../model/form-request'\nimport type { FormFileUploadProps } from './form-file-upload'\nimport { FormUploadContext } from './form-upload-context'\n\n/** One file in the field: on its way, kept, or refused. */\ninterface PickedFile {\n key: string\n name: string\n size: number\n state: 'sending' | 'kept' | 'refused'\n error?: string\n file?: VisitorUploadFileView\n}\n\nconst STILL_SENDING = 'Wait for your files to finish uploading.'\n\nlet sequence = 0\n\n/**\n * The File upload field's body (AGL-4098): a button that picks files, each\n * file's progress while it goes up, Remove, and what the form sends — a\n * hidden `field:id` per kept file and, under the field's name, their names.\n * The names' input is a real one, invisible under the button, so a required\n * field with nothing attached stops the form like any required field, and a\n * field still uploading stops it with a sentence that says to wait.\n *\n * The upload itself is the shared visitor upload: a ticket from\n * `/api/forms/upload`, the bytes posted straight to storage, then the route\n * checks and keeps them. A browser cannot report the progress of a post to\n * another site's storage, so a file shows that it is on its way, then kept.\n */\nconst FormFileUploadBody = forwardRef<HTMLDivElement, FormFileUploadProps>((props, ref) => {\n const { name: rawName, label, helperText, required, kinds: rawKinds, maxFiles: rawMax, ...rest } = props\n const name = String(rawName ?? '').trim() || 'files'\n const { fileKinds, maxFiles } = formFileFieldLimits({ kinds: rawKinds, maxFiles: rawMax })\n const upload = useContext(FormUploadContext)\n const { hostId } = Aglyn.useSite()\n const siteFetch = Aglyn.useSiteFetch()\n const inputId = useId()\n const pickerRef = useRef<HTMLInputElement>(null)\n const answerRef = useRef<HTMLInputElement>(null)\n const [picked, setPicked] = useState<PickedFile[]>([])\n const [notice, setNotice] = useState('')\n\n const kept = picked.filter((entry) => entry.state === 'kept' && entry.file)\n const sending = picked.some((entry) => entry.state === 'sending')\n const answer = kept.map((entry) => entry.file?.name ?? entry.name).join(', ')\n const live = Boolean(upload?.live && upload.formId && hostId)\n\n // A field still uploading holds the form back, in the browser's own words.\n useEffect(() => {\n answerRef.current?.setCustomValidity(sending ? STILL_SENDING : '')\n }, [sending])\n\n // Every change is announced, as a typed answer is, to anything listening on the form.\n const announced = useRef(answer)\n useEffect(() => {\n if (announced.current === answer) return\n announced.current = answer\n answerRef.current?.dispatchEvent(new Event('change', { bubbles: true }))\n }, [answer])\n\n const post = useCallback(\n async (body: Record<string, unknown>): Promise<Record<string, any>> => {\n const response = await siteFetch('/api/forms/upload', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, formId: upload?.formId, key: upload?.uploadKey(), field: name, ...body }),\n })\n const payload = await response.json().catch(() => ({}))\n if (!response.ok) {\n return { error: typeof payload?.error === 'string' ? payload.error : 'The file could not be sent. Try again.' }\n }\n return payload\n },\n [siteFetch, hostId, upload, name],\n )\n\n const sendOne = useCallback(\n async (key: string, file: File) => {\n const outcome = await sendVisitorUpload({\n file,\n requestTicket: (request) => post({ action: 'ticket', file: request }) as never,\n finalize: (ticket) => post({ action: 'finalize', ticket }) as never,\n })\n setPicked((current) =>\n current.map((entry) =>\n entry.key !== key\n ? entry\n : 'error' in outcome\n ? { ...entry, state: 'refused', error: outcome.error }\n : { ...entry, state: 'kept', file: outcome.file },\n ),\n )\n },\n [post],\n )\n\n const onPick = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(event.target.files ?? [])\n event.target.value = ''\n if (!files.length) return\n const refused = checkVisitorUploadSelection(\n files.map((file) => ({ name: file.name, type: file.type, size: file.size })),\n picked.filter((entry) => entry.state !== 'refused').length,\n maxFiles,\n fileKinds,\n )\n if (refused) return void setNotice(refused)\n setNotice('')\n const added = files.map((file) => ({ key: `file-${++sequence}`, name: file.name, size: file.size, state: 'sending' as const }))\n setPicked((current) => [...current.filter((entry) => entry.state !== 'refused'), ...added])\n added.forEach((entry, index) => void sendOne(entry.key, files[index]))\n },\n [picked, maxFiles, fileKinds, sendOne],\n )\n\n const onRemove = useCallback(\n (entry: PickedFile) => {\n setPicked((current) => current.filter((one) => one.key !== entry.key))\n if (entry.file) void post({ action: 'remove', fileId: entry.file.id }).catch(() => undefined)\n },\n [post],\n )\n\n const hint = useMemo(() => {\n const count = maxFiles === 1 ? 'One file' : `Up to ${maxFiles} files`\n return `${count}: ${describeVisitorUploadTypes(fileKinds)}, up to ${formatVisitorUploadBytes(VISITOR_UPLOAD_MAX_BYTES)} each.`\n }, [maxFiles, fileKinds])\n const full = picked.filter((entry) => entry.state !== 'refused').length >= maxFiles\n\n return (\n <FormControl ref={ref} fullWidth required={Boolean(required)} {...rest}>\n <FormLabel htmlFor={inputId}>{label || 'Files'}</FormLabel>\n {helperText ? <FormHelperText sx={{ mx: 0 }}>{helperText}</FormHelperText> : null}\n <Box sx={{ position: 'relative', mt: 1 }}>\n <Button\n variant=\"outlined\"\n disabled={!live || full}\n onClick={() => pickerRef.current?.click()}\n aria-describedby={`${inputId}-hint`}\n >\n {picked.length ? 'Attach more files' : maxFiles === 1 ? 'Attach a file' : 'Attach files'}\n </Button>\n <input\n ref={pickerRef}\n id={inputId}\n type=\"file\"\n hidden\n multiple={maxFiles > 1}\n accept={visitorUploadAccept(fileKinds)}\n onChange={onPick}\n />\n {/* The answer the form sends and the browser checks: the files' names. */}\n <Box\n component=\"input\"\n ref={answerRef}\n type=\"text\"\n name={name}\n value={answer}\n required={Boolean(required)}\n onChange={() => undefined}\n onInvalid={() => pickerRef.current?.focus()}\n tabIndex={-1}\n aria-hidden=\"true\"\n autoComplete=\"off\"\n sx={{ position: 'absolute', left: 0, bottom: 0, width: 1, height: '1px', p: 0, border: 0, opacity: 0, pointerEvents: 'none' }}\n />\n </Box>\n <FormHelperText id={`${inputId}-hint`} sx={{ mx: 0 }}>\n {live ? hint : 'Files can be attached on the published site.'}\n </FormHelperText>\n {notice ? (\n <Alert severity=\"warning\" sx={{ mt: 1 }}>\n {notice}\n </Alert>\n ) : null}\n {picked.length ? (\n <Stack spacing={1} sx={{ mt: 1 }}>\n {picked.map((entry) => (\n <Paper key={entry.key} variant=\"outlined\" sx={{ p: 1 }}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Box sx={{ minWidth: 0, flex: 1 }}>\n <Typography variant=\"body2\" noWrap title={entry.name}>\n {entry.file?.name ?? entry.name}\n </Typography>\n <Typography variant=\"caption\" color={entry.state === 'refused' ? 'error' : 'text.secondary'}>\n {entry.state === 'sending'\n ? `Uploading · ${formatVisitorUploadBytes(entry.size)}`\n : entry.state === 'refused'\n ? entry.error\n : formatVisitorUploadBytes(entry.file?.size ?? entry.size)}\n </Typography>\n {entry.state === 'sending' ? (\n <LinearProgress sx={{ mt: 0.5 }} aria-label={`Uploading ${entry.name}`} />\n ) : null}\n </Box>\n <Button\n size=\"small\"\n color=\"inherit\"\n disabled={entry.state === 'sending'}\n onClick={() => onRemove(entry)}\n aria-label={`Remove ${entry.name}`}\n >\n {'Remove'}\n </Button>\n </Stack>\n {entry.file ? (\n <input type=\"hidden\" name={FORM_FILE_INPUT} value={formFileInputValue(name, entry.file.id)} readOnly />\n ) : null}\n </Paper>\n ))}\n </Stack>\n ) : null}\n </FormControl>\n )\n})\nFormFileUploadBody.displayName = 'AglynFormFileUploadBody'\n\nexport default FormFileUploadBody\n"],"names":["Aglyn","formFileFieldLimits","checkVisitorUploadSelection","describeVisitorUploadTypes","formatVisitorUploadBytes","visitorUploadAccept","VISITOR_UPLOAD_MAX_BYTES","sendVisitorUpload","Alert","Box","Button","FormControl","FormHelperText","FormLabel","LinearProgress","Paper","Stack","Typography","forwardRef","useCallback","useContext","useEffect","useId","useMemo","useRef","useState","FORM_FILE_INPUT","formFileInputValue","FormUploadContext","STILL_SENDING","sequence","FormFileUploadBody","props","ref","name","rawName","label","helperText","required","kinds","rawKinds","maxFiles","rawMax","rest","String","trim","fileKinds","upload","hostId","useSite","siteFetch","useSiteFetch","inputId","pickerRef","answerRef","picked","setPicked","notice","setNotice","kept","filter","entry","state","file","sending","some","answer","map","join","live","Boolean","formId","current","setCustomValidity","announced","dispatchEvent","Event","bubbles","post","body","response","method","headers","JSON","stringify","key","uploadKey","field","payload","json","catch","ok","error","sendOne","outcome","requestTicket","request","action","finalize","ticket","onPick","event","files","Array","from","target","value","length","refused","type","size","added","forEach","index","onRemove","one","fileId","id","undefined","hint","count","full","fullWidth","htmlFor","sx","mx","position","mt","variant","disabled","onClick","click","aria-describedby","input","hidden","multiple","accept","onChange","component","onInvalid","focus","tabIndex","aria-hidden","autoComplete","left","bottom","width","height","p","border","opacity","pointerEvents","severity","spacing","direction","alignItems","minWidth","flex","noWrap","title","color","aria-label","readOnly","displayName"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,mBAAmB,QAAQ,+BAA8B;AAClE,SACEC,2BAA2B,EAC3BC,0BAA0B,EAC1BC,wBAAwB,EACxBC,mBAAmB,EACnBC,wBAAwB,QAEnB,wCAAuC;AAC9C,SAASC,iBAAiB,QAAQ,+CAA8C;AAChF,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,gBAAgB,2BAA0B;AACjD,SACEC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,KAAK,EACLC,OAAO,EACPC,MAAM,E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MAAME,IAAI,qBAAVF,YAAY3B,IAAI,mBAAI2B,MAAM3B,IAAI;;0DAEjC,KAACjB;gDAAW+G,SAAQ;gDAAUgC,OAAOnG,MAAMC,KAAK,KAAK,YAAY,UAAU;0DACxED,MAAMC,KAAK,KAAK,YACb,CAAC,YAAY,EAAE1D,yBAAyByD,MAAMiD,IAAI,GAAG,GACrDjD,MAAMC,KAAK,KAAK,YACdD,MAAM+B,KAAK,GACXxF,mCAAyByD,eAAAA,MAAME,IAAI,qBAAVF,aAAYiD,IAAI,oBAAIjD,MAAMiD,IAAI;;4CAE9DjD,MAAMC,KAAK,KAAK,0BACf,KAAChD;gDAAe8G,IAAI;oDAAEG,IAAI;gDAAI;gDAAGkC,cAAY,CAAC,UAAU,EAAEpG,MAAM3B,IAAI,EAAE;iDACpE;;;kDAEN,KAACxB;wCACCoG,MAAK;wCACLkD,OAAM;wCACN/B,UAAUpE,MAAMC,KAAK,KAAK;wCAC1BoE,SAAS,IAAMhB,SAASrD;wCACxBoG,cAAY,CAAC,OAAO,EAAEpG,MAAM3B,IAAI,EAAE;kDAEjC;;;;4BAGJ2B,MAAME,IAAI,iBACT,KAACsE;gCAAMxB,MAAK;gCAAS3E,MAAMR;gCAAiBgF,OAAO/E,mBAAmBO,MAAM2B,MAAME,IAAI,CAACsD,EAAE;gCAAG6C,QAAQ;iCAClG;;uBA7BMrG,MAAMwB,GAAG;;iBAiCvB;;;AAGV;AACAtD,mBAAmBoI,WAAW,GAAG;AAEjC,eAAepI,mBAAkB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import * as Aglyn from '@aglyn/aglyn';
|
|
18
|
+
export declare const FILE_UPLOAD_ID: Aglyn.ComponentId;
|
|
19
|
+
export interface FormFileUploadProps {
|
|
20
|
+
/** What the files' names are sent as. */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** The question, above the button. */
|
|
23
|
+
label?: string;
|
|
24
|
+
/** A line under it: what to attach. */
|
|
25
|
+
helperText?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The kinds of file taken, comma-separated (`images,pdf`); every kind when
|
|
29
|
+
* empty. Picked from a list, never typed.
|
|
30
|
+
*/
|
|
31
|
+
kinds?: string;
|
|
32
|
+
/** At most how many files, 1 to 10. */
|
|
33
|
+
maxFiles?: number | string;
|
|
34
|
+
}
|
|
35
|
+
/** Files a person attaches to a form; sent with it by name. */
|
|
36
|
+
export declare const FormFileUpload: import("react").ForwardRefExoticComponent<FormFileUploadProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
37
|
+
export declare const formFileUploadSchema: Aglyn.ComponentSchema<FormFileUploadProps>;
|
|
38
|
+
export declare const formFileUploadPresets: Aglyn.PresetSchema[];
|
|
39
|
+
export default FormFileUpload;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Aglyn LLC
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/ import * as Aglyn from "@aglyn/aglyn";
|
|
19
|
+
import { mdiPaperclip } from "@aglyn/shared-data-mdi";
|
|
20
|
+
import Box from "@mui/material/Box";
|
|
21
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
|
22
|
+
import { forwardRef, lazy, Suspense } from "react";
|
|
23
|
+
import { BUNDLE_ID } from "../constants/bundle-common.js";
|
|
24
|
+
import { generatePresetId } from "../utils/generate-preset-id.js";
|
|
25
|
+
/*
|
|
26
|
+
* THE FILE UPLOAD FIELD (AGL-4098): files a person attaches to a form, such as
|
|
27
|
+
* a logo with a quote request.
|
|
28
|
+
*
|
|
29
|
+
* A form element like MUI's: it carries a `name`, a label and `required`, and
|
|
30
|
+
* the form sends what it posts. Its files go up as they are picked, through
|
|
31
|
+
* the shared visitor upload, under the pending key its Form minted; the form
|
|
32
|
+
* then sends them by id, and their names are the field's answer.
|
|
33
|
+
*
|
|
34
|
+
* This shell is all a page loads until the field draws: its body, with the
|
|
35
|
+
* upload code, is a chunk of its own (`form-file-upload-body.tsx`).
|
|
36
|
+
*
|
|
37
|
+
* The component id is persisted in documents; never rename it. The core's
|
|
38
|
+
* form reader restates it (`FORM_PLUGIN_ANSWER_ELEMENTS`).
|
|
39
|
+
*/ export const FILE_UPLOAD_ID = 'formFileUpload';
|
|
40
|
+
const FormFileUploadBody = /*#__PURE__*/ lazy(()=>import("./form-file-upload-body.js"));
|
|
41
|
+
/** Files a person attaches to a form; sent with it by name. */ export const FormFileUpload = /*#__PURE__*/ forwardRef((props, ref)=>/*#__PURE__*/ _jsx(Suspense, {
|
|
42
|
+
fallback: /*#__PURE__*/ _jsx(Box, {
|
|
43
|
+
sx: {
|
|
44
|
+
py: 1
|
|
45
|
+
},
|
|
46
|
+
children: /*#__PURE__*/ _jsx(CircularProgress, {
|
|
47
|
+
size: 20,
|
|
48
|
+
"aria-label": "Loading the file field"
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
51
|
+
children: /*#__PURE__*/ _jsx(FormFileUploadBody, _extends({
|
|
52
|
+
ref: ref
|
|
53
|
+
}, props))
|
|
54
|
+
}));
|
|
55
|
+
FormFileUpload.displayName = 'AglynFormFileUpload';
|
|
56
|
+
export const formFileUploadSchema = {
|
|
57
|
+
$id: FILE_UPLOAD_ID,
|
|
58
|
+
pluginId: BUNDLE_ID,
|
|
59
|
+
displayName: 'File upload',
|
|
60
|
+
description: 'Lets a person attach files to the form, such as a logo or a sketch. The files arrive with the submission in your Inbox.',
|
|
61
|
+
category: Aglyn.ComponentCategory.FORMS,
|
|
62
|
+
icon: {
|
|
63
|
+
path: mdiPaperclip.path,
|
|
64
|
+
sx: {
|
|
65
|
+
color: 'info.main'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
flags: {
|
|
69
|
+
selfClosing: Aglyn.FEATURE_FLAG.ENABLED
|
|
70
|
+
},
|
|
71
|
+
attributes: [
|
|
72
|
+
{
|
|
73
|
+
name: 'label',
|
|
74
|
+
label: 'Label',
|
|
75
|
+
description: 'The question above the button, such as “Your logo or artwork”.',
|
|
76
|
+
component: Aglyn.FieldComponentType.TEXT_FIELD
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'name',
|
|
80
|
+
label: 'Field name',
|
|
81
|
+
description: 'The name the files are listed under in the Inbox and exports.',
|
|
82
|
+
component: Aglyn.FieldComponentType.TEXT_FIELD
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'helperText',
|
|
86
|
+
label: 'Hint',
|
|
87
|
+
description: 'A line under the label saying what to attach.',
|
|
88
|
+
component: Aglyn.FieldComponentType.TEXT_FIELD
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'required',
|
|
92
|
+
label: 'Required?',
|
|
93
|
+
description: 'The form can’t be sent until at least one file is attached.',
|
|
94
|
+
component: Aglyn.FieldComponentType.SWITCH
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'kinds',
|
|
98
|
+
label: 'Kinds of file',
|
|
99
|
+
description: 'Which files it takes. Each file can be up to 25 MB.',
|
|
100
|
+
component: Aglyn.FieldComponentType.SELECT,
|
|
101
|
+
options: [
|
|
102
|
+
{
|
|
103
|
+
value: 'images,pdf,design',
|
|
104
|
+
label: 'Images, PDFs and design files'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
value: 'images',
|
|
108
|
+
label: 'Images only (PNG, JPEG, WebP, GIF)'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
value: 'pdf',
|
|
112
|
+
label: 'PDFs only'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
value: 'design',
|
|
116
|
+
label: 'Design files only (SVG, AI, EPS, PSD, TIFF)'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
value: 'images,pdf',
|
|
120
|
+
label: 'Images and PDFs'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
value: 'images,design',
|
|
124
|
+
label: 'Images and design files'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
value: 'pdf,design',
|
|
128
|
+
label: 'PDFs and design files'
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'maxFiles',
|
|
134
|
+
label: 'Most files',
|
|
135
|
+
description: 'How many files a person can attach, up to 10.',
|
|
136
|
+
component: Aglyn.FieldComponentType.SELECT,
|
|
137
|
+
options: Array.from({
|
|
138
|
+
length: 10
|
|
139
|
+
}, (_, index)=>({
|
|
140
|
+
value: String(index + 1),
|
|
141
|
+
label: index === 0 ? '1 file' : `${index + 1} files`
|
|
142
|
+
}))
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
};
|
|
146
|
+
export const formFileUploadPresets = [
|
|
147
|
+
{
|
|
148
|
+
$id: generatePresetId(FILE_UPLOAD_ID),
|
|
149
|
+
type: Aglyn.NodeType.PRESET,
|
|
150
|
+
displayName: 'File upload',
|
|
151
|
+
pluginId: BUNDLE_ID,
|
|
152
|
+
description: 'Lets a person attach files, such as a logo or artwork',
|
|
153
|
+
category: Aglyn.ComponentCategory.FORMS,
|
|
154
|
+
icon: {
|
|
155
|
+
path: mdiPaperclip.path,
|
|
156
|
+
sx: {
|
|
157
|
+
color: 'info.main'
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
data: {
|
|
161
|
+
$id: null,
|
|
162
|
+
componentId: FILE_UPLOAD_ID,
|
|
163
|
+
pluginId: BUNDLE_ID,
|
|
164
|
+
props: {
|
|
165
|
+
name: 'files',
|
|
166
|
+
label: 'Files',
|
|
167
|
+
kinds: 'images,pdf,design',
|
|
168
|
+
maxFiles: '10'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
];
|
|
173
|
+
export default FormFileUpload;
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=form-file-upload.js.map
|