@vulcantech/forms 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/README.md +73 -0
- package/dist/index.d.mts +977 -0
- package/dist/index.d.ts +977 -0
- package/dist/index.js +2919 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2852 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2919 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Yup = require('yup');
|
|
4
|
+
var formik = require('formik');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var tailwindMerge = require('tailwind-merge');
|
|
7
|
+
var radixUi = require('radix-ui');
|
|
8
|
+
var bs = require('react-icons/bs');
|
|
9
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
10
|
+
var DatePicker = require('react-datepicker');
|
|
11
|
+
var dateFns = require('date-fns');
|
|
12
|
+
require('react-datepicker/dist/react-datepicker.css');
|
|
13
|
+
var fi = require('react-icons/fi');
|
|
14
|
+
|
|
15
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
|
|
17
|
+
function _interopNamespace(e) {
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n.default = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var Yup__namespace = /*#__PURE__*/_interopNamespace(Yup);
|
|
36
|
+
var DatePicker__default = /*#__PURE__*/_interopDefault(DatePicker);
|
|
37
|
+
|
|
38
|
+
var __defProp = Object.defineProperty;
|
|
39
|
+
var __defProps = Object.defineProperties;
|
|
40
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
41
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
42
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
43
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
44
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
45
|
+
var __spreadValues = (a, b) => {
|
|
46
|
+
for (var prop in b || (b = {}))
|
|
47
|
+
if (__hasOwnProp.call(b, prop))
|
|
48
|
+
__defNormalProp(a, prop, b[prop]);
|
|
49
|
+
if (__getOwnPropSymbols)
|
|
50
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
51
|
+
if (__propIsEnum.call(b, prop))
|
|
52
|
+
__defNormalProp(a, prop, b[prop]);
|
|
53
|
+
}
|
|
54
|
+
return a;
|
|
55
|
+
};
|
|
56
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
57
|
+
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
58
|
+
var __objRest = (source, exclude) => {
|
|
59
|
+
var target = {};
|
|
60
|
+
for (var prop in source)
|
|
61
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
62
|
+
target[prop] = source[prop];
|
|
63
|
+
if (source != null && __getOwnPropSymbols)
|
|
64
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
65
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
66
|
+
target[prop] = source[prop];
|
|
67
|
+
}
|
|
68
|
+
return target;
|
|
69
|
+
};
|
|
70
|
+
var __async = (__this, __arguments, generator) => {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
var fulfilled = (value) => {
|
|
73
|
+
try {
|
|
74
|
+
step(generator.next(value));
|
|
75
|
+
} catch (e) {
|
|
76
|
+
reject(e);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var rejected = (value) => {
|
|
80
|
+
try {
|
|
81
|
+
step(generator.throw(value));
|
|
82
|
+
} catch (e) {
|
|
83
|
+
reject(e);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
87
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/types.ts
|
|
92
|
+
var DEFAULT_SENSITIVE_FIELD_CONFIG = {
|
|
93
|
+
ttlDays: 30,
|
|
94
|
+
viewerRoles: ["admin", "sensitive_data_viewer"],
|
|
95
|
+
inputMask: "ssn"
|
|
96
|
+
};
|
|
97
|
+
var DEFAULT_FILE_FIELD_CONFIG = {
|
|
98
|
+
accept: "image/*",
|
|
99
|
+
maxSizeBytes: 10 * 1024 * 1024,
|
|
100
|
+
multiple: false,
|
|
101
|
+
maxFiles: 5,
|
|
102
|
+
resizeImages: true,
|
|
103
|
+
maxImageWidth: 1600
|
|
104
|
+
};
|
|
105
|
+
var HONEYPOT_FIELD_NAME = "_hp_website";
|
|
106
|
+
var SAME_AS_TOGGLE_PREFIX = "_sameAs_";
|
|
107
|
+
var sameAsToggleKey = (sectionId) => `${SAME_AS_TOGGLE_PREFIX}${sectionId}`;
|
|
108
|
+
var DEFAULT_SPAM_PROTECTION = {
|
|
109
|
+
honeypot: true,
|
|
110
|
+
minSubmitTime: 3
|
|
111
|
+
};
|
|
112
|
+
var DEFAULT_FORM_STYLE = {
|
|
113
|
+
preset: "default",
|
|
114
|
+
borderRadius: "md",
|
|
115
|
+
spacing: "normal",
|
|
116
|
+
buttonVariant: "filled",
|
|
117
|
+
buttonPlacement: "below",
|
|
118
|
+
sectionDividers: false,
|
|
119
|
+
inputVariant: "outlined"
|
|
120
|
+
};
|
|
121
|
+
var NEWSLETTER_ALLOWED_FIELD_TYPES = ["email", "checkbox"];
|
|
122
|
+
var DEFAULT_NOTIFICATION_EMAIL_SUBJECT = "New Contact Form: {{name}}";
|
|
123
|
+
var DEFAULT_NOTIFICATION_EMAIL_HTML = `<!DOCTYPE html>
|
|
124
|
+
<html lang="en">
|
|
125
|
+
<head><meta charset="UTF-8" /></head>
|
|
126
|
+
<body style="font-family: sans-serif; color: #333; max-width: 600px; margin: 0 auto;">
|
|
127
|
+
<div style="background: #4f46e5; color: white; padding: 20px; border-radius: 8px 8px 0 0;">
|
|
128
|
+
<h1 style="margin: 0; font-size: 20px;">New {{formName}} Submission</h1>
|
|
129
|
+
<p style="margin: 4px 0 0; opacity: 0.9; font-size: 14px;">{{projectName}}</p>
|
|
130
|
+
</div>
|
|
131
|
+
<div style="border: 1px solid #e5e7eb; border-top: none; padding: 20px; border-radius: 0 0 8px 8px;">
|
|
132
|
+
<table style="width: 100%; border-collapse: collapse;">
|
|
133
|
+
<tr>
|
|
134
|
+
<td style="padding: 8px 0; font-weight: 600; width: 120px; vertical-align: top;">Name:</td>
|
|
135
|
+
<td style="padding: 8px 0;">{{name}}</td>
|
|
136
|
+
</tr>
|
|
137
|
+
<tr>
|
|
138
|
+
<td style="padding: 8px 0; font-weight: 600; vertical-align: top;">Email:</td>
|
|
139
|
+
<td style="padding: 8px 0;"><a href="mailto:{{email}}">{{email}}</a></td>
|
|
140
|
+
</tr>
|
|
141
|
+
<tr>
|
|
142
|
+
<td style="padding: 8px 0; font-weight: 600; vertical-align: top;">Phone:</td>
|
|
143
|
+
<td style="padding: 8px 0;"><a href="tel:{{phone}}">{{phone}}</a></td>
|
|
144
|
+
</tr>
|
|
145
|
+
<tr>
|
|
146
|
+
<td style="padding: 8px 0; font-weight: 600; vertical-align: top;">Message:</td>
|
|
147
|
+
<td style="padding: 8px 0;">{{message}}</td>
|
|
148
|
+
</tr>
|
|
149
|
+
</table>
|
|
150
|
+
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
|
151
|
+
<p style="font-size: 12px; color: #9ca3af; margin: 0;">
|
|
152
|
+
Sent via VulcanTech CMS · <a href="https://cms.vulcantech.io">Dashboard</a>
|
|
153
|
+
</p>
|
|
154
|
+
</div>
|
|
155
|
+
</body>
|
|
156
|
+
</html>`;
|
|
157
|
+
var DEFAULT_NOTIFICATION_EMAIL_TEMPLATE = {
|
|
158
|
+
subject: DEFAULT_NOTIFICATION_EMAIL_SUBJECT,
|
|
159
|
+
html: DEFAULT_NOTIFICATION_EMAIL_HTML
|
|
160
|
+
};
|
|
161
|
+
var APPLICATION_STATUS_KEYS = [
|
|
162
|
+
"received",
|
|
163
|
+
"reviewing",
|
|
164
|
+
"approved",
|
|
165
|
+
"denied",
|
|
166
|
+
"pending-documents",
|
|
167
|
+
"withdrawn"
|
|
168
|
+
];
|
|
169
|
+
function buildDefaultStatusEmailHtml(bodyHtml) {
|
|
170
|
+
return `<!DOCTYPE html>
|
|
171
|
+
<html lang="en">
|
|
172
|
+
<head><meta charset="UTF-8" /></head>
|
|
173
|
+
<body style="font-family: sans-serif; color: #333; max-width: 600px; margin: 0 auto;">
|
|
174
|
+
<div style="background: #4f46e5; color: white; padding: 20px; border-radius: 8px 8px 0 0;">
|
|
175
|
+
<h1 style="margin: 0; font-size: 20px;">{{projectName}}</h1>
|
|
176
|
+
<p style="margin: 4px 0 0; opacity: 0.9; font-size: 14px;">Application update</p>
|
|
177
|
+
</div>
|
|
178
|
+
<div style="border: 1px solid #e5e7eb; border-top: none; padding: 20px; border-radius: 0 0 8px 8px;">
|
|
179
|
+
<p style="margin-top: 0;">Hi {{applicantName}},</p>
|
|
180
|
+
${bodyHtml}
|
|
181
|
+
<p style="font-size: 13px; color: #6b7280; margin: 20px 0 0;">
|
|
182
|
+
Reference number: <strong style="font-family: monospace;">{{referenceNumber}}</strong>
|
|
183
|
+
</p>
|
|
184
|
+
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
|
185
|
+
<p style="font-size: 12px; color: #9ca3af; margin: 0;">
|
|
186
|
+
This is an automated message from {{projectName}}.
|
|
187
|
+
</p>
|
|
188
|
+
</div>
|
|
189
|
+
</body>
|
|
190
|
+
</html>`;
|
|
191
|
+
}
|
|
192
|
+
var DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES = {
|
|
193
|
+
received: {
|
|
194
|
+
subject: "We've received your application \u2014 {{referenceNumber}}",
|
|
195
|
+
html: buildDefaultStatusEmailHtml(
|
|
196
|
+
`<p>Thanks for applying to {{projectName}}. We've received your submission and our team will be in touch as it moves through review.</p>`
|
|
197
|
+
)
|
|
198
|
+
},
|
|
199
|
+
reviewing: {
|
|
200
|
+
subject: "Your application is under review \u2014 {{referenceNumber}}",
|
|
201
|
+
html: buildDefaultStatusEmailHtml(
|
|
202
|
+
`<p>Good news \u2014 your application has moved into active review. We'll reach out as soon as a decision is made or we need anything else from you.</p>`
|
|
203
|
+
)
|
|
204
|
+
},
|
|
205
|
+
approved: {
|
|
206
|
+
subject: "Your application has been approved \u2014 {{referenceNumber}}",
|
|
207
|
+
html: buildDefaultStatusEmailHtml(
|
|
208
|
+
`<p>Congratulations \u2014 your application has been <strong style="color: #047857;">approved</strong>. We'll follow up shortly with next steps.</p>`
|
|
209
|
+
)
|
|
210
|
+
},
|
|
211
|
+
denied: {
|
|
212
|
+
subject: "Update on your application \u2014 {{referenceNumber}}",
|
|
213
|
+
html: buildDefaultStatusEmailHtml(
|
|
214
|
+
`<p>Thank you for taking the time to apply to {{projectName}}. After review, we won't be moving forward with your application at this time.</p>
|
|
215
|
+
<p>We appreciate your interest and wish you the best.</p>`
|
|
216
|
+
)
|
|
217
|
+
},
|
|
218
|
+
"pending-documents": {
|
|
219
|
+
subject: "Additional documents needed \u2014 {{referenceNumber}}",
|
|
220
|
+
html: buildDefaultStatusEmailHtml(
|
|
221
|
+
`<p>To continue reviewing your application we need a few more documents from you:</p>
|
|
222
|
+
<div style="white-space: pre-wrap; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin: 12px 0; font-size: 14px;">{{requestedDocuments}}</div>
|
|
223
|
+
<p>Reply to this email with the requested items and we'll resume review as soon as they arrive.</p>`
|
|
224
|
+
)
|
|
225
|
+
},
|
|
226
|
+
withdrawn: {
|
|
227
|
+
subject: "Your application has been withdrawn \u2014 {{referenceNumber}}",
|
|
228
|
+
html: buildDefaultStatusEmailHtml(
|
|
229
|
+
`<p>Per request, your application to {{projectName}} has been withdrawn. If this wasn't expected, please reply and let us know.</p>`
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
function parseFormDefinition(json) {
|
|
234
|
+
return json;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/utils/visibility.ts
|
|
238
|
+
function isVisibilityConditionMet(condition, watchedValue) {
|
|
239
|
+
var _a;
|
|
240
|
+
const operator = (_a = condition.operator) != null ? _a : "equals";
|
|
241
|
+
switch (operator) {
|
|
242
|
+
case "greater-than":
|
|
243
|
+
case "less-than": {
|
|
244
|
+
if (typeof watchedValue === "boolean") return false;
|
|
245
|
+
const actual = typeof watchedValue === "number" ? watchedValue : parseFloat(String(watchedValue != null ? watchedValue : ""));
|
|
246
|
+
const expected = parseFloat(String(condition.value));
|
|
247
|
+
if (Number.isNaN(actual) || Number.isNaN(expected)) return false;
|
|
248
|
+
return operator === "greater-than" ? actual > expected : actual < expected;
|
|
249
|
+
}
|
|
250
|
+
case "not-equals":
|
|
251
|
+
return watchedValue !== condition.value;
|
|
252
|
+
case "equals":
|
|
253
|
+
default:
|
|
254
|
+
return watchedValue === condition.value;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/schema/buildYupSchema.ts
|
|
259
|
+
function getBaseSchema(field) {
|
|
260
|
+
var _a, _b, _c;
|
|
261
|
+
switch (field.type) {
|
|
262
|
+
case "number":
|
|
263
|
+
return Yup__namespace.number().transform(
|
|
264
|
+
(value, original) => original === "" || original === null ? void 0 : value
|
|
265
|
+
).typeError(`${field.label} must be a number`);
|
|
266
|
+
case "checkbox":
|
|
267
|
+
return Yup__namespace.boolean();
|
|
268
|
+
case "url":
|
|
269
|
+
return Yup__namespace.string().url(`${field.label} must be a valid URL`);
|
|
270
|
+
case "datetime":
|
|
271
|
+
return Yup__namespace.string();
|
|
272
|
+
case "select":
|
|
273
|
+
case "radio": {
|
|
274
|
+
const allowed = ((_a = field.options) != null ? _a : []).map((o) => o.value);
|
|
275
|
+
if (allowed.length === 0) return Yup__namespace.string();
|
|
276
|
+
return Yup__namespace.string().oneOf(
|
|
277
|
+
[...allowed, ""],
|
|
278
|
+
`${field.label} has an invalid selection`
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
case "sensitive": {
|
|
282
|
+
let schema = Yup__namespace.string();
|
|
283
|
+
if (((_b = field.sensitiveConfig) == null ? void 0 : _b.inputMask) === "ssn" || field.transform === "ssn") {
|
|
284
|
+
schema = schema.matches(
|
|
285
|
+
/^\d{3}-\d{2}-\d{4}$/,
|
|
286
|
+
`${field.label} must be a valid Social Security number`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
return schema;
|
|
290
|
+
}
|
|
291
|
+
case "file":
|
|
292
|
+
if ((_c = field.fileConfig) == null ? void 0 : _c.multiple) {
|
|
293
|
+
return Yup__namespace.array().of(Yup__namespace.string().url()).default([]);
|
|
294
|
+
}
|
|
295
|
+
return Yup__namespace.string();
|
|
296
|
+
default:
|
|
297
|
+
return Yup__namespace.string();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function applyValidationRule(schema, rule, field) {
|
|
301
|
+
switch (rule.type) {
|
|
302
|
+
case "required":
|
|
303
|
+
if (field.type === "checkbox" && schema instanceof Yup__namespace.BooleanSchema) {
|
|
304
|
+
return schema.required(rule.message).oneOf([true], rule.message);
|
|
305
|
+
}
|
|
306
|
+
return schema.required(rule.message);
|
|
307
|
+
case "email":
|
|
308
|
+
if (schema instanceof Yup__namespace.StringSchema) {
|
|
309
|
+
return schema.email(rule.message);
|
|
310
|
+
}
|
|
311
|
+
return schema;
|
|
312
|
+
case "phone":
|
|
313
|
+
if (schema instanceof Yup__namespace.StringSchema) {
|
|
314
|
+
return schema.matches(
|
|
315
|
+
/^[\d\s\-()+ .]+$/,
|
|
316
|
+
rule.message
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
return schema;
|
|
320
|
+
case "min":
|
|
321
|
+
if (schema instanceof Yup__namespace.NumberSchema && typeof rule.value === "number") {
|
|
322
|
+
return schema.min(rule.value, rule.message);
|
|
323
|
+
}
|
|
324
|
+
return schema;
|
|
325
|
+
case "max":
|
|
326
|
+
if (schema instanceof Yup__namespace.NumberSchema && typeof rule.value === "number") {
|
|
327
|
+
return schema.max(rule.value, rule.message);
|
|
328
|
+
}
|
|
329
|
+
return schema;
|
|
330
|
+
case "minLength":
|
|
331
|
+
if (schema instanceof Yup__namespace.StringSchema && typeof rule.value === "number") {
|
|
332
|
+
return schema.min(rule.value, rule.message);
|
|
333
|
+
}
|
|
334
|
+
return schema;
|
|
335
|
+
case "maxLength":
|
|
336
|
+
if (schema instanceof Yup__namespace.StringSchema && typeof rule.value === "number") {
|
|
337
|
+
return schema.max(rule.value, rule.message);
|
|
338
|
+
}
|
|
339
|
+
return schema;
|
|
340
|
+
case "pattern":
|
|
341
|
+
if (schema instanceof Yup__namespace.StringSchema && typeof rule.value === "string") {
|
|
342
|
+
try {
|
|
343
|
+
return schema.matches(new RegExp(rule.value), rule.message);
|
|
344
|
+
} catch (e) {
|
|
345
|
+
console.warn(
|
|
346
|
+
`[forms] Invalid pattern for field "${field.id}": ${rule.value}`
|
|
347
|
+
);
|
|
348
|
+
return schema;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return schema;
|
|
352
|
+
case "notEquals":
|
|
353
|
+
if (schema instanceof Yup__namespace.StringSchema && rule.value !== void 0) {
|
|
354
|
+
return schema.notOneOf([String(rule.value)], rule.message);
|
|
355
|
+
}
|
|
356
|
+
if (schema instanceof Yup__namespace.NumberSchema && typeof rule.value === "number") {
|
|
357
|
+
return schema.notOneOf([rule.value], rule.message);
|
|
358
|
+
}
|
|
359
|
+
return schema;
|
|
360
|
+
default:
|
|
361
|
+
return schema;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function buildYupSchema(definition) {
|
|
365
|
+
var _a;
|
|
366
|
+
const shape = {};
|
|
367
|
+
for (const section of definition.sections) {
|
|
368
|
+
const hideToggleKey = ((_a = section.sameAs) == null ? void 0 : _a.behavior) === "hide" ? sameAsToggleKey(section.id) : null;
|
|
369
|
+
const hiddenTargetIds = hideToggleKey ? new Set(Object.keys(section.sameAs.fieldMap)) : null;
|
|
370
|
+
for (const field of section.fields) {
|
|
371
|
+
let schema = getBaseSchema(field);
|
|
372
|
+
for (const rule of field.validation) {
|
|
373
|
+
schema = applyValidationRule(schema, rule, field);
|
|
374
|
+
}
|
|
375
|
+
const baseSchema = getBaseSchema(field);
|
|
376
|
+
if (field.showWhen) {
|
|
377
|
+
const condition = field.showWhen;
|
|
378
|
+
shape[field.id] = Yup__namespace.mixed().when(condition.fieldId, {
|
|
379
|
+
is: (value) => isVisibilityConditionMet(condition, value),
|
|
380
|
+
then: () => schema,
|
|
381
|
+
otherwise: () => baseSchema.notRequired()
|
|
382
|
+
});
|
|
383
|
+
} else if (hideToggleKey && (hiddenTargetIds == null ? void 0 : hiddenTargetIds.has(field.id))) {
|
|
384
|
+
shape[field.id] = Yup__namespace.mixed().when(hideToggleKey, {
|
|
385
|
+
is: true,
|
|
386
|
+
then: () => baseSchema.notRequired(),
|
|
387
|
+
otherwise: () => schema
|
|
388
|
+
});
|
|
389
|
+
} else {
|
|
390
|
+
shape[field.id] = schema;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return Yup__namespace.object().shape(shape);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/utils/initialValues.ts
|
|
398
|
+
function buildInitialValues(definition) {
|
|
399
|
+
var _a;
|
|
400
|
+
const values = {};
|
|
401
|
+
for (const section of definition.sections) {
|
|
402
|
+
if (section.sameAs) values[sameAsToggleKey(section.id)] = false;
|
|
403
|
+
for (const field of section.fields) {
|
|
404
|
+
if (field.type === "checkbox") {
|
|
405
|
+
values[field.id] = field.defaultValue === "true";
|
|
406
|
+
} else if (field.type === "datetime") {
|
|
407
|
+
values[field.id] = field.defaultValue || "";
|
|
408
|
+
} else if (field.type === "sensitive") {
|
|
409
|
+
values[field.id] = "";
|
|
410
|
+
} else if (field.type === "file") {
|
|
411
|
+
values[field.id] = ((_a = field.fileConfig) == null ? void 0 : _a.multiple) ? [] : "";
|
|
412
|
+
} else {
|
|
413
|
+
values[field.id] = field.defaultValue || "";
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return values;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/utils/transforms.ts
|
|
421
|
+
function applyTransform(value, transform) {
|
|
422
|
+
if (!value) return "";
|
|
423
|
+
if (!transform || transform === "full") return value;
|
|
424
|
+
switch (transform) {
|
|
425
|
+
case "extractFirstName":
|
|
426
|
+
return value.trim().split(/\s+/)[0] || value;
|
|
427
|
+
case "extractLastName": {
|
|
428
|
+
const parts = value.trim().split(/\s+/);
|
|
429
|
+
return parts.length > 1 ? parts.slice(1).join(" ") : "";
|
|
430
|
+
}
|
|
431
|
+
case "extractStreet":
|
|
432
|
+
case "extractCity":
|
|
433
|
+
case "extractState":
|
|
434
|
+
case "extractZip":
|
|
435
|
+
return extractAddressPart(value, transform);
|
|
436
|
+
default:
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function extractAddressPart(value, transform) {
|
|
441
|
+
var _a, _b, _c, _d;
|
|
442
|
+
const parts = value.split(",").map((p) => p.trim());
|
|
443
|
+
if (transform === "extractStreet") return (_a = parts[0]) != null ? _a : "";
|
|
444
|
+
if (transform === "extractCity") return (_b = parts[1]) != null ? _b : "";
|
|
445
|
+
const tail = ((_c = parts[2]) != null ? _c : "").split(/\s+/).filter(Boolean);
|
|
446
|
+
if (transform === "extractState") return (_d = tail[0]) != null ? _d : "";
|
|
447
|
+
if (transform === "extractZip") return tail.slice(1).join(" ") || "";
|
|
448
|
+
return "";
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// src/utils/redirect.ts
|
|
452
|
+
function getSafeRedirectUrl(raw) {
|
|
453
|
+
if (typeof raw !== "string") return null;
|
|
454
|
+
const url = raw.trim();
|
|
455
|
+
if (!url) return null;
|
|
456
|
+
if (url.startsWith("/") && !url.startsWith("//")) return url;
|
|
457
|
+
try {
|
|
458
|
+
const parsed = new URL(url);
|
|
459
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
460
|
+
return url;
|
|
461
|
+
}
|
|
462
|
+
} catch (e) {
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/utils/textTransforms.ts
|
|
468
|
+
function formatSsn(raw) {
|
|
469
|
+
const digits = raw.replace(/\D/g, "").slice(0, 9);
|
|
470
|
+
if (digits.length <= 3) return digits;
|
|
471
|
+
if (digits.length <= 5) return `${digits.slice(0, 3)}-${digits.slice(3)}`;
|
|
472
|
+
return `${digits.slice(0, 3)}-${digits.slice(3, 5)}-${digits.slice(5)}`;
|
|
473
|
+
}
|
|
474
|
+
function formatUsPhone(raw) {
|
|
475
|
+
const digits = raw.replace(/[^\d]/g, "");
|
|
476
|
+
const onlyNums = (digits.length === 11 && digits.startsWith("1") ? digits.slice(1) : digits).slice(0, 10);
|
|
477
|
+
if (onlyNums.length > 6) {
|
|
478
|
+
return `(${onlyNums.slice(0, 3)}) ${onlyNums.slice(3, 6)} - ${onlyNums.slice(6, 10)}`;
|
|
479
|
+
}
|
|
480
|
+
if (onlyNums.length > 3) {
|
|
481
|
+
return `(${onlyNums.slice(0, 3)}) ${onlyNums.slice(3)}`;
|
|
482
|
+
}
|
|
483
|
+
if (onlyNums.length > 0) {
|
|
484
|
+
return `(${onlyNums}`;
|
|
485
|
+
}
|
|
486
|
+
return "";
|
|
487
|
+
}
|
|
488
|
+
function applyTextTransform(value, transform) {
|
|
489
|
+
switch (transform) {
|
|
490
|
+
case "capitalize-sentences":
|
|
491
|
+
return value.replace(
|
|
492
|
+
/(^|\. *)([a-z])/g,
|
|
493
|
+
(letter) => letter.toUpperCase()
|
|
494
|
+
);
|
|
495
|
+
case "capitalize-words":
|
|
496
|
+
return value.replace(
|
|
497
|
+
/^([a-z])|\s+([a-z])/g,
|
|
498
|
+
(letter) => letter.toUpperCase()
|
|
499
|
+
);
|
|
500
|
+
case "phone-number":
|
|
501
|
+
return formatUsPhone(value);
|
|
502
|
+
case "ssn":
|
|
503
|
+
return formatSsn(value);
|
|
504
|
+
default:
|
|
505
|
+
return value;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// src/utils/renderEmailTemplate.ts
|
|
510
|
+
function escapeHtml(value) {
|
|
511
|
+
if (value === null || value === void 0) return "";
|
|
512
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
513
|
+
}
|
|
514
|
+
function renderEmailTemplate(template, variables, options = {}) {
|
|
515
|
+
const shouldEscape = options.escape !== false;
|
|
516
|
+
return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, key) => {
|
|
517
|
+
const value = variables[key];
|
|
518
|
+
if (value === void 0 || value === null || value === "") return "";
|
|
519
|
+
return shouldEscape ? escapeHtml(value) : String(value);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function buildEmailTemplateVariables(args) {
|
|
523
|
+
var _a, _b;
|
|
524
|
+
const { definition, projectName, submission, submittedAt } = args;
|
|
525
|
+
const vars = {
|
|
526
|
+
projectName,
|
|
527
|
+
formName: (_b = (_a = args.formName) != null ? _a : definition == null ? void 0 : definition.name) != null ? _b : "Contact Form",
|
|
528
|
+
submittedAt: submittedAt != null ? submittedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
529
|
+
};
|
|
530
|
+
for (const [key, value] of Object.entries(submission)) {
|
|
531
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
532
|
+
vars[key] = value;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (definition == null ? void 0 : definition.sections) {
|
|
536
|
+
for (const section of definition.sections) {
|
|
537
|
+
for (const field of section.fields) {
|
|
538
|
+
const value = submission[field.id];
|
|
539
|
+
if (value === void 0 || value === null) continue;
|
|
540
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const slug = labelToSlug(field.label);
|
|
544
|
+
if (slug && vars[slug] === void 0) vars[slug] = value;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return vars;
|
|
549
|
+
}
|
|
550
|
+
function labelToSlug(label) {
|
|
551
|
+
return label.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
552
|
+
}
|
|
553
|
+
var CORE_EMAIL_TEMPLATE_VARIABLES = [
|
|
554
|
+
{
|
|
555
|
+
key: "projectName",
|
|
556
|
+
description: "Project (site) display name.",
|
|
557
|
+
example: "Acme Co."
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
key: "formName",
|
|
561
|
+
description: "Name of the form that was submitted.",
|
|
562
|
+
example: "Contact Form"
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
key: "submittedAt",
|
|
566
|
+
description: "Submission timestamp (ISO 8601).",
|
|
567
|
+
example: (/* @__PURE__ */ new Date()).toISOString()
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
key: "name",
|
|
571
|
+
description: "Submitter's name.",
|
|
572
|
+
example: "Jane Doe"
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
key: "email",
|
|
576
|
+
description: "Submitter's email.",
|
|
577
|
+
example: "jane@example.com"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
key: "phone",
|
|
581
|
+
description: "Submitter's phone (if collected).",
|
|
582
|
+
example: "555-123-4567"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
key: "message",
|
|
586
|
+
description: "Free-text message body (if collected).",
|
|
587
|
+
example: "I'd like to schedule a consultation."
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
key: "serviceType",
|
|
591
|
+
description: "Selected service / category (if collected).",
|
|
592
|
+
example: "Roof Repair"
|
|
593
|
+
}
|
|
594
|
+
];
|
|
595
|
+
var SAMPLE_EMAIL_TEMPLATE_VARIABLES = {
|
|
596
|
+
projectName: "Acme Co.",
|
|
597
|
+
formName: "Contact Form",
|
|
598
|
+
submittedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
599
|
+
name: "Jane Doe",
|
|
600
|
+
email: "jane@example.com",
|
|
601
|
+
phone: "555-123-4567",
|
|
602
|
+
message: "I'd like to schedule a consultation about your services.",
|
|
603
|
+
serviceType: "Roof Repair"
|
|
604
|
+
};
|
|
605
|
+
function renderNotificationEmail(template, variables) {
|
|
606
|
+
const subject = renderEmailTemplate(template.subject, variables, {
|
|
607
|
+
escape: false
|
|
608
|
+
}).replace(/[\r\n]+/g, " ");
|
|
609
|
+
return {
|
|
610
|
+
subject,
|
|
611
|
+
html: renderEmailTemplate(template.html, variables)
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/crypto/sensitive.ts
|
|
616
|
+
function bufferToBase64(buf) {
|
|
617
|
+
const bytes = new Uint8Array(buf);
|
|
618
|
+
let binary = "";
|
|
619
|
+
for (let i = 0; i < bytes.byteLength; i += 1) {
|
|
620
|
+
binary += String.fromCharCode(bytes[i]);
|
|
621
|
+
}
|
|
622
|
+
return btoa(binary);
|
|
623
|
+
}
|
|
624
|
+
function base64ToBuffer(b64) {
|
|
625
|
+
const binary = atob(b64);
|
|
626
|
+
const bytes = new Uint8Array(binary.length);
|
|
627
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
628
|
+
bytes[i] = binary.charCodeAt(i);
|
|
629
|
+
}
|
|
630
|
+
return bytes.buffer;
|
|
631
|
+
}
|
|
632
|
+
function importTransportPublicKey(jwk) {
|
|
633
|
+
return __async(this, null, function* () {
|
|
634
|
+
return crypto.subtle.importKey(
|
|
635
|
+
"jwk",
|
|
636
|
+
jwk,
|
|
637
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
638
|
+
false,
|
|
639
|
+
["wrapKey", "encrypt"]
|
|
640
|
+
);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
function encryptSensitiveValue(plaintext, publicKey) {
|
|
644
|
+
return __async(this, null, function* () {
|
|
645
|
+
if (typeof crypto === "undefined" || !crypto.subtle) {
|
|
646
|
+
throw new Error(
|
|
647
|
+
"Web Crypto API is unavailable \u2014 sensitive fields require a secure browser context"
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
if (typeof plaintext !== "string" || plaintext.length === 0) {
|
|
651
|
+
throw new Error("encryptSensitiveValue: plaintext must be a non-empty string");
|
|
652
|
+
}
|
|
653
|
+
const rsaKey = yield importTransportPublicKey(publicKey.jwk);
|
|
654
|
+
const dataKey = yield crypto.subtle.generateKey(
|
|
655
|
+
{ name: "AES-GCM", length: 256 },
|
|
656
|
+
true,
|
|
657
|
+
["encrypt"]
|
|
658
|
+
);
|
|
659
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
660
|
+
const encoded = new TextEncoder().encode(plaintext);
|
|
661
|
+
const ciphertext = yield crypto.subtle.encrypt(
|
|
662
|
+
{ name: "AES-GCM", iv },
|
|
663
|
+
dataKey,
|
|
664
|
+
encoded
|
|
665
|
+
);
|
|
666
|
+
const wrappedKey = yield crypto.subtle.wrapKey("raw", dataKey, rsaKey, {
|
|
667
|
+
name: "RSA-OAEP"
|
|
668
|
+
});
|
|
669
|
+
return {
|
|
670
|
+
v: "v1",
|
|
671
|
+
kid: publicKey.kid,
|
|
672
|
+
wrappedKey: bufferToBase64(wrappedKey),
|
|
673
|
+
iv: bufferToBase64(iv.buffer),
|
|
674
|
+
ciphertext: bufferToBase64(ciphertext),
|
|
675
|
+
last4: deriveLast4(plaintext)
|
|
676
|
+
};
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
function deriveLast4(plaintext) {
|
|
680
|
+
const digits = plaintext.replace(/\D/g, "");
|
|
681
|
+
return digits.slice(-4).padStart(4, "\u2022");
|
|
682
|
+
}
|
|
683
|
+
var FormStyleContext = react.createContext(DEFAULT_FORM_STYLE);
|
|
684
|
+
var useFormStyle = () => react.useContext(FormStyleContext);
|
|
685
|
+
var FormStyleProvider = FormStyleContext.Provider;
|
|
686
|
+
var FormPreviewOverridesContext = react.createContext(
|
|
687
|
+
null
|
|
688
|
+
);
|
|
689
|
+
var useFormPreviewOverrides = () => react.useContext(FormPreviewOverridesContext);
|
|
690
|
+
var FormPreviewOverridesProvider = FormPreviewOverridesContext.Provider;
|
|
691
|
+
|
|
692
|
+
// src/renderer/cssVars.ts
|
|
693
|
+
var FORM_CSS_VAR = {
|
|
694
|
+
formBg: "--form-bg",
|
|
695
|
+
inputBg: "--form-input-bg",
|
|
696
|
+
inputBorder: "--form-input-border",
|
|
697
|
+
inputFocusBorder: "--form-input-focus-border",
|
|
698
|
+
inputText: "--form-input-text",
|
|
699
|
+
placeholder: "--form-placeholder",
|
|
700
|
+
labelText: "--form-label-text",
|
|
701
|
+
error: "--form-error",
|
|
702
|
+
buttonBg: "--form-button-bg",
|
|
703
|
+
buttonText: "--form-button-text"
|
|
704
|
+
};
|
|
705
|
+
var FORM_DEFAULT_COLOR = {
|
|
706
|
+
formBg: "transparent",
|
|
707
|
+
inputBg: "inherit",
|
|
708
|
+
inputBorder: "#d1d5db",
|
|
709
|
+
inputFocusBorder: "#2563eb",
|
|
710
|
+
inputText: "inherit",
|
|
711
|
+
placeholder: "#9ca3af",
|
|
712
|
+
labelText: "inherit",
|
|
713
|
+
error: "#ef4444",
|
|
714
|
+
buttonBg: "#2563eb",
|
|
715
|
+
buttonText: "#ffffff"
|
|
716
|
+
};
|
|
717
|
+
function ref(name, fallback) {
|
|
718
|
+
return `var(${name}, ${fallback})`;
|
|
719
|
+
}
|
|
720
|
+
var FORM_VAR = {
|
|
721
|
+
formBg: ref(FORM_CSS_VAR.formBg, FORM_DEFAULT_COLOR.formBg),
|
|
722
|
+
inputBg: ref(FORM_CSS_VAR.inputBg, FORM_DEFAULT_COLOR.inputBg),
|
|
723
|
+
inputBorder: ref(FORM_CSS_VAR.inputBorder, FORM_DEFAULT_COLOR.inputBorder),
|
|
724
|
+
inputFocusBorder: ref(
|
|
725
|
+
FORM_CSS_VAR.inputFocusBorder,
|
|
726
|
+
FORM_DEFAULT_COLOR.inputFocusBorder
|
|
727
|
+
),
|
|
728
|
+
inputText: ref(FORM_CSS_VAR.inputText, FORM_DEFAULT_COLOR.inputText),
|
|
729
|
+
placeholder: ref(FORM_CSS_VAR.placeholder, FORM_DEFAULT_COLOR.placeholder),
|
|
730
|
+
labelText: ref(FORM_CSS_VAR.labelText, FORM_DEFAULT_COLOR.labelText),
|
|
731
|
+
error: ref(FORM_CSS_VAR.error, FORM_DEFAULT_COLOR.error),
|
|
732
|
+
buttonBg: ref(FORM_CSS_VAR.buttonBg, FORM_DEFAULT_COLOR.buttonBg),
|
|
733
|
+
buttonText: ref(FORM_CSS_VAR.buttonText, FORM_DEFAULT_COLOR.buttonText)
|
|
734
|
+
};
|
|
735
|
+
function buildFormCssVars(style, previewBg) {
|
|
736
|
+
const out = {};
|
|
737
|
+
const effectiveFormBg = previewBg != null ? previewBg : style.formBackgroundColor;
|
|
738
|
+
if (effectiveFormBg) out[FORM_CSS_VAR.formBg] = effectiveFormBg;
|
|
739
|
+
const effectiveInputBg = previewBg != null ? previewBg : style.inputBgColor;
|
|
740
|
+
if (effectiveInputBg) out[FORM_CSS_VAR.inputBg] = effectiveInputBg;
|
|
741
|
+
if (style.inputBorderColor)
|
|
742
|
+
out[FORM_CSS_VAR.inputBorder] = style.inputBorderColor;
|
|
743
|
+
if (style.inputFocusColor)
|
|
744
|
+
out[FORM_CSS_VAR.inputFocusBorder] = style.inputFocusColor;
|
|
745
|
+
if (style.inputTextColor)
|
|
746
|
+
out[FORM_CSS_VAR.inputText] = style.inputTextColor;
|
|
747
|
+
if (style.placeholderColor)
|
|
748
|
+
out[FORM_CSS_VAR.placeholder] = style.placeholderColor;
|
|
749
|
+
if (style.labelColor) out[FORM_CSS_VAR.labelText] = style.labelColor;
|
|
750
|
+
if (style.errorColor) out[FORM_CSS_VAR.error] = style.errorColor;
|
|
751
|
+
if (style.buttonColor) out[FORM_CSS_VAR.buttonBg] = style.buttonColor;
|
|
752
|
+
if (style.buttonTextColor)
|
|
753
|
+
out[FORM_CSS_VAR.buttonText] = style.buttonTextColor;
|
|
754
|
+
return out;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/renderer/fields/useInputStyles.ts
|
|
758
|
+
var placeholderClass = "placeholder:[color:var(--form-placeholder,#9ca3af)]";
|
|
759
|
+
var textClass = "text-[color:var(--form-input-text,inherit)]";
|
|
760
|
+
function getVariantClasses(style) {
|
|
761
|
+
switch (style.inputVariant) {
|
|
762
|
+
case "stacked":
|
|
763
|
+
return {
|
|
764
|
+
inputClass: tailwindMerge.twMerge(
|
|
765
|
+
"w-full rounded-lg border px-4 py-3 text-base transition focus:outline-none disabled:cursor-not-allowed",
|
|
766
|
+
textClass,
|
|
767
|
+
placeholderClass
|
|
768
|
+
),
|
|
769
|
+
inputStyle: {
|
|
770
|
+
borderColor: FORM_VAR.inputBorder,
|
|
771
|
+
backgroundColor: FORM_VAR.inputBg
|
|
772
|
+
},
|
|
773
|
+
labelClass: "mb-1 block text-sm font-medium"
|
|
774
|
+
};
|
|
775
|
+
case "filled":
|
|
776
|
+
return {
|
|
777
|
+
inputClass: tailwindMerge.twMerge(
|
|
778
|
+
"rounded-t-md px-3 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed",
|
|
779
|
+
textClass,
|
|
780
|
+
placeholderClass
|
|
781
|
+
),
|
|
782
|
+
inputStyle: {
|
|
783
|
+
borderStyle: "solid",
|
|
784
|
+
borderWidth: 0,
|
|
785
|
+
borderBottomWidth: 2,
|
|
786
|
+
borderBottomColor: FORM_VAR.inputBorder,
|
|
787
|
+
backgroundColor: FORM_VAR.inputBg
|
|
788
|
+
},
|
|
789
|
+
labelClass: "absolute left-2 top-2 z-10 flex min-h-[1ch] w-min -translate-y-[18px] cursor-text flex-col justify-around whitespace-nowrap rounded-md px-1 text-sm transition-transform group-focus-within:-translate-y-[18px] peer-placeholder-shown:translate-y-0 peer-focus:-translate-y-[18px]"
|
|
790
|
+
};
|
|
791
|
+
case "underlined":
|
|
792
|
+
return {
|
|
793
|
+
inputClass: tailwindMerge.twMerge(
|
|
794
|
+
"rounded-none bg-transparent px-1 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed",
|
|
795
|
+
textClass,
|
|
796
|
+
placeholderClass
|
|
797
|
+
),
|
|
798
|
+
inputStyle: {
|
|
799
|
+
borderStyle: "solid",
|
|
800
|
+
borderWidth: 0,
|
|
801
|
+
borderBottomWidth: 2,
|
|
802
|
+
borderBottomColor: FORM_VAR.inputBorder
|
|
803
|
+
},
|
|
804
|
+
labelClass: "absolute left-1 top-2 z-10 flex min-h-[1ch] w-min -translate-y-[18px] cursor-text flex-col justify-around whitespace-nowrap px-0 text-sm transition-transform group-focus-within:-translate-y-[18px] peer-placeholder-shown:translate-y-0 peer-focus:-translate-y-[18px]"
|
|
805
|
+
};
|
|
806
|
+
case "outlined":
|
|
807
|
+
default:
|
|
808
|
+
return {
|
|
809
|
+
inputClass: tailwindMerge.twMerge(
|
|
810
|
+
"rounded px-3 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed bg-transparent",
|
|
811
|
+
textClass,
|
|
812
|
+
placeholderClass
|
|
813
|
+
),
|
|
814
|
+
inputStyle: {
|
|
815
|
+
borderStyle: "solid",
|
|
816
|
+
borderWidth: 1,
|
|
817
|
+
borderColor: FORM_VAR.inputBorder
|
|
818
|
+
},
|
|
819
|
+
// Label must paint a solid bg on top of the input border. `bg-inherit`
|
|
820
|
+
// doesn't work — wrapper divs between the form root and the label
|
|
821
|
+
// have transparent bgs, so `inherit` resolves to transparent. Read
|
|
822
|
+
// from `--form-input-bg`, which DynamicForm publishes on the form
|
|
823
|
+
// root from the resolved input background (or the editor preview
|
|
824
|
+
// override). The fallback matches FORM_DEFAULT_COLOR.inputBg.
|
|
825
|
+
labelClass: "absolute left-2 top-2 z-10 flex min-h-[1ch] w-min -translate-y-[18px] cursor-text flex-col justify-around whitespace-nowrap rounded-md bg-[var(--form-input-bg,inherit)] px-1 text-sm transition-transform group-focus-within:-translate-y-[18px] peer-placeholder-shown:translate-y-0 peer-focus:-translate-y-[18px]"
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
function getFocusStyle(style) {
|
|
830
|
+
if (style.inputVariant === "filled" || style.inputVariant === "underlined") {
|
|
831
|
+
return { borderBottomColor: FORM_VAR.inputFocusBorder };
|
|
832
|
+
}
|
|
833
|
+
if (style.inputVariant === "stacked") {
|
|
834
|
+
return {
|
|
835
|
+
borderColor: FORM_VAR.inputFocusBorder,
|
|
836
|
+
boxShadow: "0 0 0 2px rgba(37, 99, 235, 0.2)"
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
return { borderColor: FORM_VAR.inputFocusBorder };
|
|
840
|
+
}
|
|
841
|
+
function useInputStyles() {
|
|
842
|
+
const style = useFormStyle();
|
|
843
|
+
const variant = getVariantClasses(style);
|
|
844
|
+
const isStacked = style.inputVariant === "stacked";
|
|
845
|
+
return {
|
|
846
|
+
wrapperClass: isStacked ? "flex w-full flex-col" : "group relative flex w-full flex-col pt-3",
|
|
847
|
+
inputClass: isStacked ? tailwindMerge.twMerge("block w-full", variant.inputClass) : tailwindMerge.twMerge(
|
|
848
|
+
"peer m-0 mb-3 block min-h-8 w-full overflow-hidden",
|
|
849
|
+
variant.inputClass
|
|
850
|
+
),
|
|
851
|
+
inputStyle: variant.inputStyle,
|
|
852
|
+
inputFocusStyle: getFocusStyle(style),
|
|
853
|
+
labelClass: variant.labelClass,
|
|
854
|
+
labelStyle: { color: FORM_VAR.labelText },
|
|
855
|
+
errorStyle: { color: FORM_VAR.error },
|
|
856
|
+
accentColor: FORM_VAR.inputFocusBorder,
|
|
857
|
+
isStacked
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
function getErrorOutlineStyle(hasError, variant) {
|
|
861
|
+
if (!hasError) return {};
|
|
862
|
+
if (variant === "stacked") {
|
|
863
|
+
return {
|
|
864
|
+
outline: `2px solid ${FORM_VAR.error}`,
|
|
865
|
+
outlineOffset: "-2px"
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
if (variant === "outlined") {
|
|
869
|
+
return {
|
|
870
|
+
outline: `1px solid ${FORM_VAR.error}`,
|
|
871
|
+
outlineOffset: "-1px",
|
|
872
|
+
borderColor: FORM_VAR.error
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
borderBottomColor: FORM_VAR.error
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
var StyledInput = ({
|
|
880
|
+
id,
|
|
881
|
+
label,
|
|
882
|
+
placeholder,
|
|
883
|
+
type = "text",
|
|
884
|
+
value,
|
|
885
|
+
error,
|
|
886
|
+
touched,
|
|
887
|
+
disabled,
|
|
888
|
+
onChange,
|
|
889
|
+
onBlur
|
|
890
|
+
}) => {
|
|
891
|
+
const [focused, setFocused] = react.useState(false);
|
|
892
|
+
const style = useFormStyle();
|
|
893
|
+
const styles = useInputStyles();
|
|
894
|
+
const hasError = !!(error && touched);
|
|
895
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, style.inputVariant));
|
|
896
|
+
if (styles.isStacked) {
|
|
897
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
898
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: styles.labelClass, style: styles.labelStyle, children: label }),
|
|
899
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
900
|
+
"input",
|
|
901
|
+
{
|
|
902
|
+
className: styles.inputClass,
|
|
903
|
+
style: borderStyle,
|
|
904
|
+
id,
|
|
905
|
+
name: id,
|
|
906
|
+
type,
|
|
907
|
+
placeholder,
|
|
908
|
+
value,
|
|
909
|
+
disabled,
|
|
910
|
+
onChange,
|
|
911
|
+
onFocus: () => setFocused(true),
|
|
912
|
+
onBlur: (e) => {
|
|
913
|
+
setFocused(false);
|
|
914
|
+
onBlur(e);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
),
|
|
918
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
919
|
+
"span",
|
|
920
|
+
{
|
|
921
|
+
className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
|
|
922
|
+
style: styles.errorStyle,
|
|
923
|
+
children: error
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
] });
|
|
927
|
+
}
|
|
928
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
929
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: id, className: "relative inline-block", children: [
|
|
930
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
931
|
+
"input",
|
|
932
|
+
{
|
|
933
|
+
className: styles.inputClass,
|
|
934
|
+
style: borderStyle,
|
|
935
|
+
id,
|
|
936
|
+
name: id,
|
|
937
|
+
type,
|
|
938
|
+
placeholder: placeholder || label,
|
|
939
|
+
value,
|
|
940
|
+
disabled,
|
|
941
|
+
onChange,
|
|
942
|
+
onFocus: () => setFocused(true),
|
|
943
|
+
onBlur: (e) => {
|
|
944
|
+
setFocused(false);
|
|
945
|
+
onBlur(e);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
),
|
|
949
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: label })
|
|
950
|
+
] }),
|
|
951
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: error })
|
|
952
|
+
] });
|
|
953
|
+
};
|
|
954
|
+
var TextField = ({ field: fieldDef, disabled }) => {
|
|
955
|
+
const [field, meta] = formik.useField(fieldDef.id);
|
|
956
|
+
const handleChange = (e) => {
|
|
957
|
+
e.target.value = applyTextTransform(e.target.value, fieldDef.transform);
|
|
958
|
+
field.onChange(e);
|
|
959
|
+
};
|
|
960
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
961
|
+
StyledInput,
|
|
962
|
+
{
|
|
963
|
+
id: fieldDef.id,
|
|
964
|
+
label: fieldDef.label,
|
|
965
|
+
placeholder: fieldDef.placeholder,
|
|
966
|
+
value: field.value,
|
|
967
|
+
error: meta.error,
|
|
968
|
+
touched: meta.touched,
|
|
969
|
+
disabled,
|
|
970
|
+
onChange: handleChange,
|
|
971
|
+
onBlur: field.onBlur
|
|
972
|
+
}
|
|
973
|
+
);
|
|
974
|
+
};
|
|
975
|
+
var EmailField = ({ field: fieldDef, disabled }) => {
|
|
976
|
+
const [field, meta] = formik.useField(fieldDef.id);
|
|
977
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
978
|
+
StyledInput,
|
|
979
|
+
{
|
|
980
|
+
id: fieldDef.id,
|
|
981
|
+
label: fieldDef.label,
|
|
982
|
+
placeholder: fieldDef.placeholder,
|
|
983
|
+
type: "email",
|
|
984
|
+
value: field.value,
|
|
985
|
+
error: meta.error,
|
|
986
|
+
touched: meta.touched,
|
|
987
|
+
disabled,
|
|
988
|
+
onChange: field.onChange,
|
|
989
|
+
onBlur: field.onBlur
|
|
990
|
+
}
|
|
991
|
+
);
|
|
992
|
+
};
|
|
993
|
+
var PhoneField = ({ field: fieldDef, disabled }) => {
|
|
994
|
+
var _a, _b;
|
|
995
|
+
const [field, meta, helpers] = formik.useField(fieldDef.id);
|
|
996
|
+
const [focused, setFocused] = react.useState(false);
|
|
997
|
+
const formStyle = useFormStyle();
|
|
998
|
+
const styles = useInputStyles();
|
|
999
|
+
const hasError = !!(meta.error && meta.touched);
|
|
1000
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
|
|
1001
|
+
const handleChange = (e) => {
|
|
1002
|
+
helpers.setValue(formatUsPhone(e.target.value));
|
|
1003
|
+
};
|
|
1004
|
+
if (styles.isStacked) {
|
|
1005
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1006
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1007
|
+
"label",
|
|
1008
|
+
{
|
|
1009
|
+
htmlFor: fieldDef.id,
|
|
1010
|
+
className: styles.labelClass,
|
|
1011
|
+
style: styles.labelStyle,
|
|
1012
|
+
children: fieldDef.label
|
|
1013
|
+
}
|
|
1014
|
+
),
|
|
1015
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1016
|
+
"input",
|
|
1017
|
+
{
|
|
1018
|
+
className: styles.inputClass,
|
|
1019
|
+
style: borderStyle,
|
|
1020
|
+
id: fieldDef.id,
|
|
1021
|
+
name: fieldDef.id,
|
|
1022
|
+
type: "tel",
|
|
1023
|
+
placeholder: fieldDef.placeholder,
|
|
1024
|
+
value: (_a = field.value) != null ? _a : "",
|
|
1025
|
+
disabled,
|
|
1026
|
+
onChange: handleChange,
|
|
1027
|
+
onFocus: () => setFocused(true),
|
|
1028
|
+
onBlur: (e) => {
|
|
1029
|
+
setFocused(false);
|
|
1030
|
+
field.onBlur(e);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
),
|
|
1034
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1035
|
+
"span",
|
|
1036
|
+
{
|
|
1037
|
+
className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
|
|
1038
|
+
style: styles.errorStyle,
|
|
1039
|
+
children: meta.error
|
|
1040
|
+
}
|
|
1041
|
+
)
|
|
1042
|
+
] });
|
|
1043
|
+
}
|
|
1044
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1045
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
|
|
1046
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1047
|
+
"input",
|
|
1048
|
+
{
|
|
1049
|
+
className: styles.inputClass,
|
|
1050
|
+
style: borderStyle,
|
|
1051
|
+
id: fieldDef.id,
|
|
1052
|
+
name: fieldDef.id,
|
|
1053
|
+
type: "tel",
|
|
1054
|
+
placeholder: fieldDef.placeholder || fieldDef.label,
|
|
1055
|
+
value: (_b = field.value) != null ? _b : "",
|
|
1056
|
+
onChange: handleChange,
|
|
1057
|
+
onFocus: () => setFocused(true),
|
|
1058
|
+
onBlur: (e) => {
|
|
1059
|
+
setFocused(false);
|
|
1060
|
+
field.onBlur(e);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
),
|
|
1064
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
|
|
1065
|
+
] }),
|
|
1066
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1067
|
+
] });
|
|
1068
|
+
};
|
|
1069
|
+
var UrlField = ({ field: fieldDef, disabled }) => {
|
|
1070
|
+
const [field, meta] = formik.useField(fieldDef.id);
|
|
1071
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1072
|
+
StyledInput,
|
|
1073
|
+
{
|
|
1074
|
+
id: fieldDef.id,
|
|
1075
|
+
label: fieldDef.label,
|
|
1076
|
+
placeholder: fieldDef.placeholder || "https://example.com",
|
|
1077
|
+
type: "url",
|
|
1078
|
+
value: field.value,
|
|
1079
|
+
error: meta.error,
|
|
1080
|
+
touched: meta.touched,
|
|
1081
|
+
disabled,
|
|
1082
|
+
onChange: field.onChange,
|
|
1083
|
+
onBlur: field.onBlur
|
|
1084
|
+
}
|
|
1085
|
+
);
|
|
1086
|
+
};
|
|
1087
|
+
var AddressField = ({ field: fieldDef, disabled }) => {
|
|
1088
|
+
var _a;
|
|
1089
|
+
const [field, meta] = formik.useField(fieldDef.id);
|
|
1090
|
+
const [focused, setFocused] = react.useState(false);
|
|
1091
|
+
const handleChange = (e) => {
|
|
1092
|
+
e.target.value = applyTextTransform(e.target.value, fieldDef.transform);
|
|
1093
|
+
field.onChange(e);
|
|
1094
|
+
};
|
|
1095
|
+
const formStyle = useFormStyle();
|
|
1096
|
+
const styles = useInputStyles();
|
|
1097
|
+
const hasError = !!(meta.error && meta.touched);
|
|
1098
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
|
|
1099
|
+
const placeholder = fieldDef.placeholder || "123 Main St, City, State 12345";
|
|
1100
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${styles.wrapperClass} pb-5 lg:pb-0`, children: [
|
|
1101
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
|
|
1102
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1103
|
+
"textarea",
|
|
1104
|
+
{
|
|
1105
|
+
className: `${styles.inputClass} min-h-[4ch] resize-y`,
|
|
1106
|
+
style: borderStyle,
|
|
1107
|
+
id: fieldDef.id,
|
|
1108
|
+
name: fieldDef.id,
|
|
1109
|
+
autoComplete: "street-address",
|
|
1110
|
+
placeholder,
|
|
1111
|
+
rows: (_a = fieldDef.rows) != null ? _a : 2,
|
|
1112
|
+
value: field.value,
|
|
1113
|
+
disabled,
|
|
1114
|
+
onChange: handleChange,
|
|
1115
|
+
onFocus: () => setFocused(true),
|
|
1116
|
+
onBlur: (e) => {
|
|
1117
|
+
setFocused(false);
|
|
1118
|
+
field.onBlur(e);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
),
|
|
1122
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
|
|
1123
|
+
] }),
|
|
1124
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", style: styles.errorStyle, children: meta.error })
|
|
1125
|
+
] });
|
|
1126
|
+
};
|
|
1127
|
+
var TextAreaField = ({ field: fieldDef, disabled }) => {
|
|
1128
|
+
var _a;
|
|
1129
|
+
const [field, meta] = formik.useField(fieldDef.id);
|
|
1130
|
+
const [focused, setFocused] = react.useState(false);
|
|
1131
|
+
const handleChange = (e) => {
|
|
1132
|
+
e.target.value = applyTextTransform(e.target.value, fieldDef.transform);
|
|
1133
|
+
field.onChange(e);
|
|
1134
|
+
};
|
|
1135
|
+
const formStyle = useFormStyle();
|
|
1136
|
+
const styles = useInputStyles();
|
|
1137
|
+
const hasError = !!(meta.error && meta.touched);
|
|
1138
|
+
const value = (_a = field.value) != null ? _a : "";
|
|
1139
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
|
|
1140
|
+
if (styles.isStacked) {
|
|
1141
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tailwindMerge.twMerge(styles.wrapperClass, "relative"), children: [
|
|
1142
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1143
|
+
"label",
|
|
1144
|
+
{
|
|
1145
|
+
htmlFor: fieldDef.id,
|
|
1146
|
+
className: styles.labelClass,
|
|
1147
|
+
style: styles.labelStyle,
|
|
1148
|
+
children: fieldDef.label
|
|
1149
|
+
}
|
|
1150
|
+
),
|
|
1151
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1152
|
+
"textarea",
|
|
1153
|
+
{
|
|
1154
|
+
className: tailwindMerge.twMerge(styles.inputClass, "resize-y"),
|
|
1155
|
+
style: borderStyle,
|
|
1156
|
+
id: fieldDef.id,
|
|
1157
|
+
name: fieldDef.id,
|
|
1158
|
+
placeholder: fieldDef.placeholder,
|
|
1159
|
+
rows: fieldDef.rows,
|
|
1160
|
+
value,
|
|
1161
|
+
disabled,
|
|
1162
|
+
onChange: handleChange,
|
|
1163
|
+
onFocus: () => setFocused(true),
|
|
1164
|
+
onBlur: (e) => {
|
|
1165
|
+
setFocused(false);
|
|
1166
|
+
field.onBlur(e);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
),
|
|
1170
|
+
fieldDef.characterCounter && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-1 text-right text-xs text-gray-500 dark:text-zinc-400", children: value.length }),
|
|
1171
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1172
|
+
"span",
|
|
1173
|
+
{
|
|
1174
|
+
className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
|
|
1175
|
+
style: styles.errorStyle,
|
|
1176
|
+
children: meta.error
|
|
1177
|
+
}
|
|
1178
|
+
)
|
|
1179
|
+
] });
|
|
1180
|
+
}
|
|
1181
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tailwindMerge.twMerge(styles.wrapperClass, "pb-5 lg:pb-0"), children: [
|
|
1182
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block", children: [
|
|
1183
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1184
|
+
"textarea",
|
|
1185
|
+
{
|
|
1186
|
+
className: tailwindMerge.twMerge(styles.inputClass, "min-h-[5ch] resize-y"),
|
|
1187
|
+
style: borderStyle,
|
|
1188
|
+
id: fieldDef.id,
|
|
1189
|
+
name: fieldDef.id,
|
|
1190
|
+
placeholder: fieldDef.placeholder || fieldDef.label,
|
|
1191
|
+
rows: fieldDef.rows,
|
|
1192
|
+
value,
|
|
1193
|
+
disabled,
|
|
1194
|
+
onChange: handleChange,
|
|
1195
|
+
onFocus: () => setFocused(true),
|
|
1196
|
+
onBlur: (e) => {
|
|
1197
|
+
setFocused(false);
|
|
1198
|
+
field.onBlur(e);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
),
|
|
1202
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
|
|
1203
|
+
] }),
|
|
1204
|
+
fieldDef.characterCounter && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute bottom-1.5 right-2 rounded-md text-sm", children: value.length }),
|
|
1205
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", style: styles.errorStyle, children: meta.error })
|
|
1206
|
+
] });
|
|
1207
|
+
};
|
|
1208
|
+
var SelectField = ({ field: fieldDef, disabled }) => {
|
|
1209
|
+
var _a;
|
|
1210
|
+
const [field, meta, helpers] = formik.useField(fieldDef.id);
|
|
1211
|
+
const [focused, setFocused] = react.useState(false);
|
|
1212
|
+
const formStyle = useFormStyle();
|
|
1213
|
+
const styles = useInputStyles();
|
|
1214
|
+
const hasError = !!(meta.error && meta.touched);
|
|
1215
|
+
const [currentValue, setCurrentValue] = react.useState(field.value || "");
|
|
1216
|
+
react.useEffect(() => {
|
|
1217
|
+
setCurrentValue(field.value || "");
|
|
1218
|
+
}, [field.value]);
|
|
1219
|
+
const options = (fieldDef.options || []).filter((opt) => opt.value !== "");
|
|
1220
|
+
const displayName = ((_a = options.find((opt) => opt.value === currentValue)) == null ? void 0 : _a.label) || "";
|
|
1221
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
|
|
1222
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1223
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1224
|
+
radixUi.Select.Root,
|
|
1225
|
+
{
|
|
1226
|
+
disabled,
|
|
1227
|
+
onValueChange: (value) => {
|
|
1228
|
+
helpers.setValue(value);
|
|
1229
|
+
setCurrentValue(value);
|
|
1230
|
+
},
|
|
1231
|
+
value: currentValue,
|
|
1232
|
+
children: [
|
|
1233
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1234
|
+
"label",
|
|
1235
|
+
{
|
|
1236
|
+
htmlFor: fieldDef.id,
|
|
1237
|
+
className: "relative block bg-inherit",
|
|
1238
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1239
|
+
radixUi.Select.Trigger,
|
|
1240
|
+
{
|
|
1241
|
+
className: `${styles.inputClass} cursor-pointer text-left`,
|
|
1242
|
+
style: borderStyle,
|
|
1243
|
+
"aria-label": fieldDef.label,
|
|
1244
|
+
onFocus: () => setFocused(true),
|
|
1245
|
+
onBlur: () => {
|
|
1246
|
+
setFocused(false);
|
|
1247
|
+
helpers.setTouched(true);
|
|
1248
|
+
},
|
|
1249
|
+
children: [
|
|
1250
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Value, { placeholder: "Choose an option", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block truncate", children: displayName }) }),
|
|
1251
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Icon, { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, { style: { color: FORM_VAR.placeholder } }) }),
|
|
1252
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
|
|
1253
|
+
]
|
|
1254
|
+
}
|
|
1255
|
+
)
|
|
1256
|
+
}
|
|
1257
|
+
),
|
|
1258
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1259
|
+
radixUi.Select.Content,
|
|
1260
|
+
{
|
|
1261
|
+
className: "z-20 rounded-md border p-3 shadow-lg",
|
|
1262
|
+
style: {
|
|
1263
|
+
// Portal renders outside the form DOM tree, so CSS variables
|
|
1264
|
+
// from the form wrapper don't cascade. Use resolved style
|
|
1265
|
+
// values from the form context instead.
|
|
1266
|
+
backgroundColor: formStyle.inputBgColor || "#ffffff",
|
|
1267
|
+
borderColor: formStyle.inputBorderColor || "#e5e7eb",
|
|
1268
|
+
color: formStyle.inputTextColor || "#1f2937"
|
|
1269
|
+
},
|
|
1270
|
+
children: [
|
|
1271
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.ScrollUpButton, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, { className: "rotate-180" }) }),
|
|
1272
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Viewport, { children: /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Group, { children: options.map((opt) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1273
|
+
radixUi.Select.Item,
|
|
1274
|
+
{
|
|
1275
|
+
className: "relative m-1 flex cursor-pointer select-none justify-between rounded p-1 pr-8 hover:ring-1 focus:ring-1",
|
|
1276
|
+
style: {
|
|
1277
|
+
"--tw-ring-color": formStyle.inputFocusColor || "#2563eb"
|
|
1278
|
+
},
|
|
1279
|
+
value: opt.value,
|
|
1280
|
+
children: [
|
|
1281
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.ItemText, { children: opt.label }),
|
|
1282
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsCheck, { className: "absolute bottom-0 right-3 top-0 my-auto" }) })
|
|
1283
|
+
]
|
|
1284
|
+
},
|
|
1285
|
+
opt.value
|
|
1286
|
+
)) }) }),
|
|
1287
|
+
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.ScrollDownButton, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, {}) })
|
|
1288
|
+
]
|
|
1289
|
+
}
|
|
1290
|
+
) })
|
|
1291
|
+
]
|
|
1292
|
+
}
|
|
1293
|
+
),
|
|
1294
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", style: styles.errorStyle, children: meta.error })
|
|
1295
|
+
] });
|
|
1296
|
+
};
|
|
1297
|
+
var CheckboxField = ({ field: fieldDef }) => {
|
|
1298
|
+
const [field, meta, helpers] = formik.useField(fieldDef.id);
|
|
1299
|
+
const formStyle = useFormStyle();
|
|
1300
|
+
const isChecked = field.value === true;
|
|
1301
|
+
const isStacked = formStyle.inputVariant === "stacked";
|
|
1302
|
+
const checkboxStyle = isChecked ? { borderColor: FORM_VAR.inputFocusBorder, backgroundColor: FORM_VAR.inputFocusBorder } : { borderColor: FORM_VAR.inputBorder, backgroundColor: FORM_VAR.inputBg };
|
|
1303
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1304
|
+
"div",
|
|
1305
|
+
{
|
|
1306
|
+
className: tailwindMerge.twMerge(
|
|
1307
|
+
isStacked ? "flex items-start gap-3" : "flex items-center gap-3 pt-3"
|
|
1308
|
+
),
|
|
1309
|
+
children: [
|
|
1310
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1311
|
+
radixUi.Checkbox.Root,
|
|
1312
|
+
{
|
|
1313
|
+
id: fieldDef.id,
|
|
1314
|
+
checked: isChecked,
|
|
1315
|
+
onCheckedChange: (checked) => {
|
|
1316
|
+
helpers.setValue(checked === true);
|
|
1317
|
+
helpers.setTouched(true, false);
|
|
1318
|
+
},
|
|
1319
|
+
className: tailwindMerge.twMerge(
|
|
1320
|
+
"flex h-5 w-5 items-center justify-center rounded border",
|
|
1321
|
+
isStacked && "mt-0.5 shrink-0"
|
|
1322
|
+
),
|
|
1323
|
+
style: checkboxStyle,
|
|
1324
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(radixUi.Checkbox.Indicator, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsCheck, { className: "text-white" }) })
|
|
1325
|
+
}
|
|
1326
|
+
),
|
|
1327
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1328
|
+
"label",
|
|
1329
|
+
{
|
|
1330
|
+
htmlFor: fieldDef.id,
|
|
1331
|
+
className: "cursor-pointer text-sm",
|
|
1332
|
+
style: { color: FORM_VAR.labelText },
|
|
1333
|
+
children: fieldDef.label
|
|
1334
|
+
}
|
|
1335
|
+
),
|
|
1336
|
+
meta.touched && meta.error && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", style: { color: FORM_VAR.error }, children: meta.error })
|
|
1337
|
+
]
|
|
1338
|
+
}
|
|
1339
|
+
);
|
|
1340
|
+
};
|
|
1341
|
+
var RadioField = ({ field: fieldDef, disabled }) => {
|
|
1342
|
+
const [field, meta, helpers] = formik.useField(fieldDef.id);
|
|
1343
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pt-3", children: [
|
|
1344
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1345
|
+
"span",
|
|
1346
|
+
{
|
|
1347
|
+
className: "mb-2 block text-sm",
|
|
1348
|
+
style: { color: FORM_VAR.labelText },
|
|
1349
|
+
children: fieldDef.label
|
|
1350
|
+
}
|
|
1351
|
+
),
|
|
1352
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1353
|
+
radixUi.RadioGroup.Root,
|
|
1354
|
+
{
|
|
1355
|
+
value: field.value,
|
|
1356
|
+
disabled,
|
|
1357
|
+
onValueChange: (value) => {
|
|
1358
|
+
helpers.setValue(value);
|
|
1359
|
+
helpers.setTouched(true, false);
|
|
1360
|
+
},
|
|
1361
|
+
className: "flex flex-col gap-2",
|
|
1362
|
+
children: (fieldDef.options || []).map((opt) => {
|
|
1363
|
+
const isSelected = field.value === opt.value;
|
|
1364
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1365
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1366
|
+
radixUi.RadioGroup.Item,
|
|
1367
|
+
{
|
|
1368
|
+
value: opt.value,
|
|
1369
|
+
id: `${fieldDef.id}-${opt.value}`,
|
|
1370
|
+
className: "flex h-5 w-5 items-center justify-center rounded-full border",
|
|
1371
|
+
style: {
|
|
1372
|
+
borderColor: isSelected ? FORM_VAR.inputFocusBorder : FORM_VAR.inputBorder,
|
|
1373
|
+
backgroundColor: FORM_VAR.inputBg
|
|
1374
|
+
},
|
|
1375
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1376
|
+
radixUi.RadioGroup.Indicator,
|
|
1377
|
+
{
|
|
1378
|
+
className: "h-2.5 w-2.5 rounded-full",
|
|
1379
|
+
style: { backgroundColor: FORM_VAR.inputFocusBorder }
|
|
1380
|
+
}
|
|
1381
|
+
)
|
|
1382
|
+
}
|
|
1383
|
+
),
|
|
1384
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1385
|
+
"label",
|
|
1386
|
+
{
|
|
1387
|
+
htmlFor: `${fieldDef.id}-${opt.value}`,
|
|
1388
|
+
className: "cursor-pointer text-sm",
|
|
1389
|
+
style: { color: FORM_VAR.labelText },
|
|
1390
|
+
children: opt.label
|
|
1391
|
+
}
|
|
1392
|
+
)
|
|
1393
|
+
] }, opt.value);
|
|
1394
|
+
})
|
|
1395
|
+
}
|
|
1396
|
+
),
|
|
1397
|
+
meta.touched && meta.error && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-1 block text-sm", style: { color: FORM_VAR.error }, children: meta.error })
|
|
1398
|
+
] });
|
|
1399
|
+
};
|
|
1400
|
+
var NumberField = ({ field: fieldDef, disabled }) => {
|
|
1401
|
+
const [field, meta] = formik.useField(fieldDef.id);
|
|
1402
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1403
|
+
StyledInput,
|
|
1404
|
+
{
|
|
1405
|
+
id: fieldDef.id,
|
|
1406
|
+
label: fieldDef.label,
|
|
1407
|
+
placeholder: fieldDef.placeholder,
|
|
1408
|
+
type: "number",
|
|
1409
|
+
value: field.value,
|
|
1410
|
+
error: meta.error,
|
|
1411
|
+
touched: meta.touched,
|
|
1412
|
+
disabled,
|
|
1413
|
+
onChange: field.onChange,
|
|
1414
|
+
onBlur: field.onBlur
|
|
1415
|
+
}
|
|
1416
|
+
);
|
|
1417
|
+
};
|
|
1418
|
+
function nextBusinessDay(from) {
|
|
1419
|
+
let d = dateFns.addDays(from, 1);
|
|
1420
|
+
while (dateFns.isWeekend(d)) d = dateFns.addDays(d, 1);
|
|
1421
|
+
return d;
|
|
1422
|
+
}
|
|
1423
|
+
function buildDateFilter(config) {
|
|
1424
|
+
var _a, _b, _c, _d;
|
|
1425
|
+
const excludeWeekends = (_a = config == null ? void 0 : config.excludeWeekends) != null ? _a : false;
|
|
1426
|
+
const excludeToday = (_b = config == null ? void 0 : config.excludeToday) != null ? _b : false;
|
|
1427
|
+
const excludeTomorrow = (_c = config == null ? void 0 : config.excludeTomorrow) != null ? _c : false;
|
|
1428
|
+
const excludeNext = (_d = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _d : false;
|
|
1429
|
+
if (!excludeWeekends && !excludeToday && !excludeTomorrow && !excludeNext) {
|
|
1430
|
+
return void 0;
|
|
1431
|
+
}
|
|
1432
|
+
return (date) => {
|
|
1433
|
+
const now = /* @__PURE__ */ new Date();
|
|
1434
|
+
if (excludeWeekends && dateFns.isWeekend(date)) return false;
|
|
1435
|
+
if (excludeToday && dateFns.isSameDay(date, now)) return false;
|
|
1436
|
+
if (excludeTomorrow && dateFns.isSameDay(date, dateFns.addDays(now, 1))) return false;
|
|
1437
|
+
if (excludeNext && dateFns.isSameDay(date, nextBusinessDay(now))) return false;
|
|
1438
|
+
return true;
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
function parseTimeString(value, fallbackHours, fallbackMinutes) {
|
|
1442
|
+
if (!value) {
|
|
1443
|
+
return dateFns.set(/* @__PURE__ */ new Date(), { hours: fallbackHours, minutes: fallbackMinutes, seconds: 0, milliseconds: 0 });
|
|
1444
|
+
}
|
|
1445
|
+
try {
|
|
1446
|
+
return dateFns.parse(value, "HH:mm", /* @__PURE__ */ new Date());
|
|
1447
|
+
} catch (e) {
|
|
1448
|
+
return dateFns.set(/* @__PURE__ */ new Date(), { hours: fallbackHours, minutes: fallbackMinutes, seconds: 0, milliseconds: 0 });
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
function parseStoredValue(value) {
|
|
1452
|
+
if (!value) return null;
|
|
1453
|
+
const d = /^\d{4}-\d{2}-\d{2}$/.test(value) ? dateFns.parse(value, "yyyy-MM-dd", /* @__PURE__ */ new Date()) : new Date(value);
|
|
1454
|
+
return dateFns.isValid(d) ? d : null;
|
|
1455
|
+
}
|
|
1456
|
+
var DateTimeField = ({
|
|
1457
|
+
field: fieldDef,
|
|
1458
|
+
dateOnly = false,
|
|
1459
|
+
disabled
|
|
1460
|
+
}) => {
|
|
1461
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1462
|
+
const [field, meta, helpers] = formik.useField(fieldDef.id);
|
|
1463
|
+
const [focused, setFocused] = react.useState(false);
|
|
1464
|
+
const formStyle = useFormStyle();
|
|
1465
|
+
const styles = useInputStyles();
|
|
1466
|
+
const hasError = !!(meta.error && meta.touched);
|
|
1467
|
+
const config = (_a = fieldDef.datetimeConfig) != null ? _a : {};
|
|
1468
|
+
const showTimeSelect = dateOnly ? false : (_b = config.showTimeSelect) != null ? _b : true;
|
|
1469
|
+
const timeIntervals = (_c = config.timeIntervals) != null ? _c : 30;
|
|
1470
|
+
const excludePastDates = (_d = config.excludePastDates) != null ? _d : true;
|
|
1471
|
+
const filterPastTimes = (_e = config.filterPastTimes) != null ? _e : true;
|
|
1472
|
+
const dateFormat = (_f = config.dateFormat) != null ? _f : showTimeSelect ? "MMMM d, yyyy h:mm aa" : "MMMM d, yyyy";
|
|
1473
|
+
const placeholderText = (_h = (_g = config.placeholderText) != null ? _g : fieldDef.placeholder) != null ? _h : dateOnly ? "Select date" : "Select date and time";
|
|
1474
|
+
const minTime = showTimeSelect ? parseTimeString(config.minTime, 0, 0) : void 0;
|
|
1475
|
+
const maxTime = showTimeSelect ? parseTimeString(config.maxTime, 23, 59) : void 0;
|
|
1476
|
+
const minDate = excludePastDates ? /* @__PURE__ */ new Date() : void 0;
|
|
1477
|
+
const selected = parseStoredValue(field.value);
|
|
1478
|
+
const filterDate = buildDateFilter(config);
|
|
1479
|
+
const filterTime = (time) => {
|
|
1480
|
+
if (!filterPastTimes) return true;
|
|
1481
|
+
return time.getTime() >= Date.now();
|
|
1482
|
+
};
|
|
1483
|
+
const handleChange = (date) => {
|
|
1484
|
+
if (!date) {
|
|
1485
|
+
helpers.setValue("");
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
helpers.setValue(dateOnly ? dateFns.format(date, "yyyy-MM-dd") : date.toISOString());
|
|
1489
|
+
};
|
|
1490
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
|
|
1491
|
+
const pickerProps = {
|
|
1492
|
+
id: fieldDef.id,
|
|
1493
|
+
name: fieldDef.id,
|
|
1494
|
+
wrapperClassName: "block w-full",
|
|
1495
|
+
disabled,
|
|
1496
|
+
selected,
|
|
1497
|
+
onChange: handleChange,
|
|
1498
|
+
onFocus: () => setFocused(true),
|
|
1499
|
+
onBlur: () => {
|
|
1500
|
+
setFocused(false);
|
|
1501
|
+
helpers.setTouched(true);
|
|
1502
|
+
},
|
|
1503
|
+
showTimeSelect,
|
|
1504
|
+
timeIntervals,
|
|
1505
|
+
minDate,
|
|
1506
|
+
minTime,
|
|
1507
|
+
maxTime,
|
|
1508
|
+
filterDate,
|
|
1509
|
+
filterTime: showTimeSelect && filterPastTimes ? filterTime : void 0,
|
|
1510
|
+
dateFormat,
|
|
1511
|
+
placeholderText,
|
|
1512
|
+
autoComplete: "off"
|
|
1513
|
+
};
|
|
1514
|
+
if (styles.isStacked) {
|
|
1515
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1516
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1517
|
+
"label",
|
|
1518
|
+
{
|
|
1519
|
+
htmlFor: fieldDef.id,
|
|
1520
|
+
className: styles.labelClass,
|
|
1521
|
+
style: styles.labelStyle,
|
|
1522
|
+
children: fieldDef.label
|
|
1523
|
+
}
|
|
1524
|
+
),
|
|
1525
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1526
|
+
DatePicker__default.default,
|
|
1527
|
+
__spreadProps(__spreadValues({}, pickerProps), {
|
|
1528
|
+
customInput: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1529
|
+
"input",
|
|
1530
|
+
{
|
|
1531
|
+
className: tailwindMerge.twMerge(styles.inputClass, "cursor-pointer"),
|
|
1532
|
+
style: borderStyle
|
|
1533
|
+
}
|
|
1534
|
+
)
|
|
1535
|
+
})
|
|
1536
|
+
),
|
|
1537
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1538
|
+
"span",
|
|
1539
|
+
{
|
|
1540
|
+
className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
|
|
1541
|
+
style: styles.errorStyle,
|
|
1542
|
+
children: meta.error
|
|
1543
|
+
}
|
|
1544
|
+
)
|
|
1545
|
+
] });
|
|
1546
|
+
}
|
|
1547
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1548
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
|
|
1549
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1550
|
+
DatePicker__default.default,
|
|
1551
|
+
__spreadProps(__spreadValues({}, pickerProps), {
|
|
1552
|
+
className: styles.inputClass,
|
|
1553
|
+
customInput: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1554
|
+
"input",
|
|
1555
|
+
{
|
|
1556
|
+
className: styles.inputClass,
|
|
1557
|
+
style: borderStyle
|
|
1558
|
+
}
|
|
1559
|
+
)
|
|
1560
|
+
})
|
|
1561
|
+
),
|
|
1562
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1563
|
+
"span",
|
|
1564
|
+
{
|
|
1565
|
+
className: tailwindMerge.twMerge(
|
|
1566
|
+
styles.labelClass,
|
|
1567
|
+
// react-datepicker nests the real input inside wrapper divs, so
|
|
1568
|
+
// the `peer-placeholder-shown` rest rule from labelClass never
|
|
1569
|
+
// matches (the peer must be a direct sibling). Recreate the
|
|
1570
|
+
// resting position from tracked state instead.
|
|
1571
|
+
!focused && !field.value && "translate-y-0"
|
|
1572
|
+
),
|
|
1573
|
+
style: styles.labelStyle,
|
|
1574
|
+
children: fieldDef.label
|
|
1575
|
+
}
|
|
1576
|
+
)
|
|
1577
|
+
] }),
|
|
1578
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1579
|
+
] });
|
|
1580
|
+
};
|
|
1581
|
+
var DateField = ({ field, disabled }) => {
|
|
1582
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DateTimeField, { field, dateOnly: true, disabled });
|
|
1583
|
+
};
|
|
1584
|
+
var HiddenField = ({ field: fieldDef }) => {
|
|
1585
|
+
const [field] = formik.useField(fieldDef.id);
|
|
1586
|
+
return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name: fieldDef.id, value: field.value });
|
|
1587
|
+
};
|
|
1588
|
+
var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
1589
|
+
var _a;
|
|
1590
|
+
const [field, meta, helpers] = formik.useField(fieldDef.id);
|
|
1591
|
+
const [reveal, setReveal] = react.useState(false);
|
|
1592
|
+
const formStyle = useFormStyle();
|
|
1593
|
+
const styles = useInputStyles();
|
|
1594
|
+
const [focused, setFocused] = react.useState(false);
|
|
1595
|
+
const hasError = !!(meta.error && meta.touched);
|
|
1596
|
+
const isSsn = ((_a = fieldDef.sensitiveConfig) == null ? void 0 : _a.inputMask) === "ssn" || fieldDef.transform === "ssn";
|
|
1597
|
+
const handleChange = (e) => {
|
|
1598
|
+
const next = applyTextTransform(
|
|
1599
|
+
e.target.value,
|
|
1600
|
+
isSsn ? "ssn" : fieldDef.transform
|
|
1601
|
+
);
|
|
1602
|
+
helpers.setValue(next);
|
|
1603
|
+
};
|
|
1604
|
+
const borderStyle = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant)), {
|
|
1605
|
+
paddingRight: "2.75rem"
|
|
1606
|
+
});
|
|
1607
|
+
const inputType = reveal ? "text" : "password";
|
|
1608
|
+
const inputProps = {
|
|
1609
|
+
id: fieldDef.id,
|
|
1610
|
+
name: fieldDef.id,
|
|
1611
|
+
type: inputType,
|
|
1612
|
+
disabled,
|
|
1613
|
+
autoComplete: "off",
|
|
1614
|
+
inputMode: isSsn ? "numeric" : void 0,
|
|
1615
|
+
placeholder: fieldDef.placeholder || (isSsn ? "\u2022\u2022\u2022-\u2022\u2022-\u2022\u2022\u2022\u2022" : fieldDef.label),
|
|
1616
|
+
value: field.value,
|
|
1617
|
+
onChange: handleChange,
|
|
1618
|
+
onFocus: () => setFocused(true),
|
|
1619
|
+
onBlur: (e) => {
|
|
1620
|
+
setFocused(false);
|
|
1621
|
+
field.onBlur(e);
|
|
1622
|
+
},
|
|
1623
|
+
"aria-describedby": `${fieldDef.id}-secure`,
|
|
1624
|
+
"data-sensitive": "true"
|
|
1625
|
+
};
|
|
1626
|
+
const renderToggle = (wrapperClass) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1627
|
+
"span",
|
|
1628
|
+
{
|
|
1629
|
+
className: tailwindMerge.twMerge(
|
|
1630
|
+
"absolute inset-y-0 right-2 flex items-center",
|
|
1631
|
+
wrapperClass
|
|
1632
|
+
),
|
|
1633
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1634
|
+
"button",
|
|
1635
|
+
{
|
|
1636
|
+
type: "button",
|
|
1637
|
+
onClick: () => setReveal((r) => !r),
|
|
1638
|
+
className: "flex h-7 w-7 items-center justify-center rounded text-gray-600 hover:bg-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60 dark:text-zinc-400 dark:hover:bg-zinc-700",
|
|
1639
|
+
"aria-pressed": reveal,
|
|
1640
|
+
"aria-label": reveal ? "Hide value" : "Show value",
|
|
1641
|
+
children: reveal ? /* @__PURE__ */ jsxRuntime.jsx(fi.FiEyeOff, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsxRuntime.jsx(fi.FiEye, { size: 16, "aria-hidden": "true" })
|
|
1642
|
+
}
|
|
1643
|
+
)
|
|
1644
|
+
}
|
|
1645
|
+
);
|
|
1646
|
+
const renderSecureHint = (className) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1647
|
+
"p",
|
|
1648
|
+
{
|
|
1649
|
+
id: `${fieldDef.id}-secure`,
|
|
1650
|
+
className: tailwindMerge.twMerge(
|
|
1651
|
+
"flex items-center gap-1 text-xs text-gray-500 dark:text-zinc-400",
|
|
1652
|
+
className
|
|
1653
|
+
),
|
|
1654
|
+
children: [
|
|
1655
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1656
|
+
"svg",
|
|
1657
|
+
{
|
|
1658
|
+
"aria-hidden": "true",
|
|
1659
|
+
viewBox: "0 0 16 16",
|
|
1660
|
+
className: "h-3 w-3 flex-shrink-0",
|
|
1661
|
+
fill: "currentColor",
|
|
1662
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 1a3 3 0 0 0-3 3v3H4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-1V4a3 3 0 0 0-3-3Zm-2 6V4a2 2 0 1 1 4 0v3H6Z" })
|
|
1663
|
+
}
|
|
1664
|
+
),
|
|
1665
|
+
"Encrypted before submission"
|
|
1666
|
+
]
|
|
1667
|
+
}
|
|
1668
|
+
);
|
|
1669
|
+
if (styles.isStacked) {
|
|
1670
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1671
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-baseline justify-between gap-x-2", children: [
|
|
1672
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: fieldDef.id, className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label }),
|
|
1673
|
+
renderSecureHint("mb-1")
|
|
1674
|
+
] }),
|
|
1675
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
1676
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", __spreadValues({ className: styles.inputClass, style: borderStyle }, inputProps)),
|
|
1677
|
+
renderToggle()
|
|
1678
|
+
] }),
|
|
1679
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1680
|
+
"span",
|
|
1681
|
+
{
|
|
1682
|
+
className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
|
|
1683
|
+
style: styles.errorStyle,
|
|
1684
|
+
children: meta.error
|
|
1685
|
+
}
|
|
1686
|
+
)
|
|
1687
|
+
] });
|
|
1688
|
+
}
|
|
1689
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
|
|
1690
|
+
renderSecureHint("absolute right-0 top-0 leading-none"),
|
|
1691
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block w-full bg-inherit", children: [
|
|
1692
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", __spreadValues({ className: styles.inputClass, style: borderStyle }, inputProps)),
|
|
1693
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label }),
|
|
1694
|
+
renderToggle("mb-3")
|
|
1695
|
+
] }),
|
|
1696
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1697
|
+
] });
|
|
1698
|
+
};
|
|
1699
|
+
function formatBytes(bytes) {
|
|
1700
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
1701
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
1702
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
1703
|
+
}
|
|
1704
|
+
function matchesAccept(file, accept) {
|
|
1705
|
+
if (!(accept == null ? void 0 : accept.trim())) return true;
|
|
1706
|
+
const patterns = accept.split(",").map((p) => p.trim()).filter(Boolean);
|
|
1707
|
+
return patterns.some((pattern) => {
|
|
1708
|
+
if (pattern.startsWith(".")) {
|
|
1709
|
+
return file.name.toLowerCase().endsWith(pattern.toLowerCase());
|
|
1710
|
+
}
|
|
1711
|
+
if (pattern.endsWith("/*")) {
|
|
1712
|
+
return file.type.startsWith(pattern.slice(0, -1));
|
|
1713
|
+
}
|
|
1714
|
+
return file.type === pattern;
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
1718
|
+
var _a, _b, _c, _d;
|
|
1719
|
+
const [, meta, helpers] = formik.useField(fieldDef.id);
|
|
1720
|
+
const { setFieldTouched } = formik.useFormikContext();
|
|
1721
|
+
const inputRef = react.useRef(null);
|
|
1722
|
+
const [uploading, setUploading] = react.useState(false);
|
|
1723
|
+
const [uploadError, setUploadError] = react.useState(null);
|
|
1724
|
+
const [files, setFiles] = react.useState([]);
|
|
1725
|
+
const config = __spreadValues(__spreadValues({}, DEFAULT_FILE_FIELD_CONFIG), fieldDef.fileConfig);
|
|
1726
|
+
const maxSizeBytes = (_a = config.maxSizeBytes) != null ? _a : 10 * 1024 * 1024;
|
|
1727
|
+
const multiple = (_b = config.multiple) != null ? _b : false;
|
|
1728
|
+
const maxFiles = (_c = config.maxFiles) != null ? _c : 5;
|
|
1729
|
+
const handleFiles = react.useCallback(
|
|
1730
|
+
(fileList) => __async(null, null, function* () {
|
|
1731
|
+
var _a2, _b2;
|
|
1732
|
+
if (!fileList || fileList.length === 0) return;
|
|
1733
|
+
setUploadError(null);
|
|
1734
|
+
const toUpload = Array.from(fileList);
|
|
1735
|
+
if (multiple && files.length + toUpload.length > maxFiles) {
|
|
1736
|
+
setUploadError(`Maximum ${maxFiles} files allowed.`);
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
let current = files;
|
|
1740
|
+
for (const file of toUpload) {
|
|
1741
|
+
if (!matchesAccept(file, config.accept)) {
|
|
1742
|
+
setUploadError(`"${file.name}" is not an accepted file type.`);
|
|
1743
|
+
continue;
|
|
1744
|
+
}
|
|
1745
|
+
if (file.size > maxSizeBytes) {
|
|
1746
|
+
setUploadError(
|
|
1747
|
+
`"${file.name}" exceeds ${formatBytes(maxSizeBytes)} limit.`
|
|
1748
|
+
);
|
|
1749
|
+
continue;
|
|
1750
|
+
}
|
|
1751
|
+
setUploading(true);
|
|
1752
|
+
try {
|
|
1753
|
+
let result;
|
|
1754
|
+
if (onUpload) {
|
|
1755
|
+
result = yield onUpload(file, config);
|
|
1756
|
+
} else {
|
|
1757
|
+
result = {
|
|
1758
|
+
url: URL.createObjectURL(file),
|
|
1759
|
+
name: file.name,
|
|
1760
|
+
size: file.size
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
current = multiple ? [...current, result] : [result];
|
|
1764
|
+
} catch (err) {
|
|
1765
|
+
setUploadError(`Upload failed: ${err.message}`);
|
|
1766
|
+
} finally {
|
|
1767
|
+
setUploading(false);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
if (current !== files) {
|
|
1771
|
+
setFiles(current);
|
|
1772
|
+
helpers.setValue(multiple ? current.map((f) => f.url) : (_b2 = (_a2 = current[0]) == null ? void 0 : _a2.url) != null ? _b2 : "");
|
|
1773
|
+
}
|
|
1774
|
+
setFieldTouched(fieldDef.id, true);
|
|
1775
|
+
}),
|
|
1776
|
+
[
|
|
1777
|
+
files,
|
|
1778
|
+
multiple,
|
|
1779
|
+
maxFiles,
|
|
1780
|
+
maxSizeBytes,
|
|
1781
|
+
config,
|
|
1782
|
+
onUpload,
|
|
1783
|
+
helpers,
|
|
1784
|
+
fieldDef.id,
|
|
1785
|
+
setFieldTouched
|
|
1786
|
+
]
|
|
1787
|
+
);
|
|
1788
|
+
const removeFile = react.useCallback(
|
|
1789
|
+
(index) => {
|
|
1790
|
+
const next = files.filter((_, i) => i !== index);
|
|
1791
|
+
setFiles(next);
|
|
1792
|
+
helpers.setValue(multiple ? next.map((f) => f.url) : "");
|
|
1793
|
+
},
|
|
1794
|
+
[files, multiple, helpers]
|
|
1795
|
+
);
|
|
1796
|
+
const hasError = meta.touched && meta.error;
|
|
1797
|
+
const isRequired = (_d = fieldDef.validation) == null ? void 0 : _d.some((v) => v.type === "required");
|
|
1798
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1799
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1800
|
+
"label",
|
|
1801
|
+
{
|
|
1802
|
+
htmlFor: fieldDef.id,
|
|
1803
|
+
className: "mb-1 block text-sm font-medium",
|
|
1804
|
+
style: { color: "var(--form-label-color, inherit)" },
|
|
1805
|
+
children: [
|
|
1806
|
+
fieldDef.label,
|
|
1807
|
+
isRequired && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-0.5 text-red-500", children: "*" })
|
|
1808
|
+
]
|
|
1809
|
+
}
|
|
1810
|
+
),
|
|
1811
|
+
fieldDef.helpText && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1812
|
+
"p",
|
|
1813
|
+
{
|
|
1814
|
+
className: "mb-2 text-xs",
|
|
1815
|
+
style: { color: "var(--form-placeholder-color, #9ca3af)" },
|
|
1816
|
+
children: fieldDef.helpText
|
|
1817
|
+
}
|
|
1818
|
+
),
|
|
1819
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1820
|
+
"div",
|
|
1821
|
+
{
|
|
1822
|
+
className: `relative rounded-lg border-2 border-dashed p-6 text-center transition-colors ${hasError ? "border-red-400" : "border-gray-300 hover:border-gray-400 dark:border-gray-600 dark:hover:border-gray-500"}`,
|
|
1823
|
+
onDragOver: (e) => {
|
|
1824
|
+
e.preventDefault();
|
|
1825
|
+
e.stopPropagation();
|
|
1826
|
+
},
|
|
1827
|
+
onDrop: (e) => {
|
|
1828
|
+
e.preventDefault();
|
|
1829
|
+
e.stopPropagation();
|
|
1830
|
+
handleFiles(e.dataTransfer.files);
|
|
1831
|
+
},
|
|
1832
|
+
children: [
|
|
1833
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1834
|
+
"input",
|
|
1835
|
+
{
|
|
1836
|
+
ref: inputRef,
|
|
1837
|
+
id: fieldDef.id,
|
|
1838
|
+
type: "file",
|
|
1839
|
+
accept: config.accept,
|
|
1840
|
+
multiple,
|
|
1841
|
+
disabled,
|
|
1842
|
+
onChange: (e) => {
|
|
1843
|
+
handleFiles(e.target.files);
|
|
1844
|
+
e.target.value = "";
|
|
1845
|
+
},
|
|
1846
|
+
className: "hidden"
|
|
1847
|
+
}
|
|
1848
|
+
),
|
|
1849
|
+
uploading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1850
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-auto h-1.5 w-32 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-1/3 animate-pulse rounded-full bg-indigo-500" }) }),
|
|
1851
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-500", children: "Uploading\u2026" })
|
|
1852
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1853
|
+
"button",
|
|
1854
|
+
{
|
|
1855
|
+
type: "button",
|
|
1856
|
+
onClick: () => {
|
|
1857
|
+
var _a2;
|
|
1858
|
+
return (_a2 = inputRef.current) == null ? void 0 : _a2.click();
|
|
1859
|
+
},
|
|
1860
|
+
disabled,
|
|
1861
|
+
className: "cursor-pointer text-sm text-gray-500 hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-50 dark:text-gray-400 dark:hover:text-gray-200",
|
|
1862
|
+
children: [
|
|
1863
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1864
|
+
"svg",
|
|
1865
|
+
{
|
|
1866
|
+
className: "mx-auto mb-2 h-8 w-8 text-gray-400",
|
|
1867
|
+
fill: "none",
|
|
1868
|
+
viewBox: "0 0 24 24",
|
|
1869
|
+
strokeWidth: 1.5,
|
|
1870
|
+
stroke: "currentColor",
|
|
1871
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1872
|
+
"path",
|
|
1873
|
+
{
|
|
1874
|
+
strokeLinecap: "round",
|
|
1875
|
+
strokeLinejoin: "round",
|
|
1876
|
+
d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5"
|
|
1877
|
+
}
|
|
1878
|
+
)
|
|
1879
|
+
}
|
|
1880
|
+
),
|
|
1881
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: "Click to upload" }),
|
|
1882
|
+
" or drag and drop",
|
|
1883
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
1884
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-gray-400", children: [
|
|
1885
|
+
"Max ",
|
|
1886
|
+
formatBytes(maxSizeBytes),
|
|
1887
|
+
multiple && ` \xB7 Up to ${maxFiles} files`
|
|
1888
|
+
] })
|
|
1889
|
+
]
|
|
1890
|
+
}
|
|
1891
|
+
)
|
|
1892
|
+
]
|
|
1893
|
+
}
|
|
1894
|
+
),
|
|
1895
|
+
files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 space-y-2", children: files.map((f, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1896
|
+
"div",
|
|
1897
|
+
{
|
|
1898
|
+
className: "flex items-center gap-3 rounded-md border border-gray-200 bg-gray-50 px-3 py-2 dark:border-gray-700 dark:bg-gray-800",
|
|
1899
|
+
children: [
|
|
1900
|
+
f.url && f.name.match(/\.(jpg|jpeg|png|webp|gif|svg)$/i) && // eslint-disable-next-line @next/next/no-img-element
|
|
1901
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1902
|
+
"img",
|
|
1903
|
+
{
|
|
1904
|
+
src: f.url,
|
|
1905
|
+
alt: f.name,
|
|
1906
|
+
className: "h-10 w-10 rounded object-cover"
|
|
1907
|
+
}
|
|
1908
|
+
),
|
|
1909
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
1910
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-sm font-medium text-gray-900 dark:text-gray-100", children: f.name }),
|
|
1911
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-gray-500", children: formatBytes(f.size) })
|
|
1912
|
+
] }),
|
|
1913
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1914
|
+
"button",
|
|
1915
|
+
{
|
|
1916
|
+
type: "button",
|
|
1917
|
+
onClick: () => removeFile(i),
|
|
1918
|
+
className: "cursor-pointer text-gray-400 hover:text-red-500",
|
|
1919
|
+
"aria-label": `Remove ${f.name}`,
|
|
1920
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1921
|
+
"svg",
|
|
1922
|
+
{
|
|
1923
|
+
className: "h-4 w-4",
|
|
1924
|
+
fill: "none",
|
|
1925
|
+
viewBox: "0 0 24 24",
|
|
1926
|
+
strokeWidth: 2,
|
|
1927
|
+
stroke: "currentColor",
|
|
1928
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1929
|
+
"path",
|
|
1930
|
+
{
|
|
1931
|
+
strokeLinecap: "round",
|
|
1932
|
+
strokeLinejoin: "round",
|
|
1933
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
1934
|
+
}
|
|
1935
|
+
)
|
|
1936
|
+
}
|
|
1937
|
+
)
|
|
1938
|
+
}
|
|
1939
|
+
)
|
|
1940
|
+
]
|
|
1941
|
+
},
|
|
1942
|
+
`${f.name}-${i}`
|
|
1943
|
+
)) }),
|
|
1944
|
+
uploadError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-red-500", children: uploadError }),
|
|
1945
|
+
hasError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-red-500", children: meta.error })
|
|
1946
|
+
] });
|
|
1947
|
+
};
|
|
1948
|
+
var fieldComponents = {
|
|
1949
|
+
text: TextField,
|
|
1950
|
+
email: EmailField,
|
|
1951
|
+
phone: PhoneField,
|
|
1952
|
+
url: UrlField,
|
|
1953
|
+
address: AddressField,
|
|
1954
|
+
textarea: TextAreaField,
|
|
1955
|
+
select: SelectField,
|
|
1956
|
+
checkbox: CheckboxField,
|
|
1957
|
+
radio: RadioField,
|
|
1958
|
+
number: NumberField,
|
|
1959
|
+
date: DateField,
|
|
1960
|
+
datetime: DateTimeField,
|
|
1961
|
+
hidden: HiddenField,
|
|
1962
|
+
sensitive: SensitiveField,
|
|
1963
|
+
file: FileField
|
|
1964
|
+
};
|
|
1965
|
+
var DynamicFormField = ({ field, mirrored, mirrorBehavior }) => {
|
|
1966
|
+
var _a, _b;
|
|
1967
|
+
const { values } = formik.useFormikContext();
|
|
1968
|
+
const Component = fieldComponents[field.type];
|
|
1969
|
+
if (!Component) {
|
|
1970
|
+
console.warn(`Unknown field type: ${field.type}`);
|
|
1971
|
+
return null;
|
|
1972
|
+
}
|
|
1973
|
+
if (!field.id) {
|
|
1974
|
+
console.warn("Skipping form field with empty id");
|
|
1975
|
+
return null;
|
|
1976
|
+
}
|
|
1977
|
+
if (field.showWhen && !isVisibilityConditionMet(field.showWhen, values[field.showWhen.fieldId])) {
|
|
1978
|
+
return null;
|
|
1979
|
+
}
|
|
1980
|
+
if (mirrored && mirrorBehavior === "hide") {
|
|
1981
|
+
return null;
|
|
1982
|
+
}
|
|
1983
|
+
const locked = mirrored && mirrorBehavior === "lock";
|
|
1984
|
+
if (field.type === "hidden") {
|
|
1985
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { field, disabled: locked });
|
|
1986
|
+
}
|
|
1987
|
+
const widthClasses = {
|
|
1988
|
+
full: "md:col-span-6",
|
|
1989
|
+
half: "md:col-span-3",
|
|
1990
|
+
third: "md:col-span-2"
|
|
1991
|
+
};
|
|
1992
|
+
const widthClass = widthClasses[((_a = field.layout) == null ? void 0 : _a.width) || "full"] || "md:col-span-6";
|
|
1993
|
+
const description = (_b = field.description) != null ? _b : field.helpText;
|
|
1994
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: widthClass, children: [
|
|
1995
|
+
/* @__PURE__ */ jsxRuntime.jsx(Component, { field, disabled: locked }),
|
|
1996
|
+
description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: tailwindMerge.twMerge("mt-1 text-xs", "text-gray-500 dark:text-zinc-400"), children: description })
|
|
1997
|
+
] });
|
|
1998
|
+
};
|
|
1999
|
+
var spacingGap = {
|
|
2000
|
+
compact: "gap-2",
|
|
2001
|
+
normal: "gap-4",
|
|
2002
|
+
relaxed: "gap-6"
|
|
2003
|
+
};
|
|
2004
|
+
var DynamicFormSection = ({
|
|
2005
|
+
section,
|
|
2006
|
+
isLast,
|
|
2007
|
+
formDefaultTextColor,
|
|
2008
|
+
inlineSubmit
|
|
2009
|
+
}) => {
|
|
2010
|
+
var _a, _b;
|
|
2011
|
+
const style = useFormStyle();
|
|
2012
|
+
const previewOverrides = useFormPreviewOverrides();
|
|
2013
|
+
const previewTextColor = previewOverrides == null ? void 0 : previewOverrides.textColor;
|
|
2014
|
+
const { values, setFieldValue } = formik.useFormikContext();
|
|
2015
|
+
const sameAs = section.sameAs;
|
|
2016
|
+
const toggleKey = sameAs ? sameAsToggleKey(section.id) : "";
|
|
2017
|
+
const toggleOn = sameAs ? values[toggleKey] === true : false;
|
|
2018
|
+
const fieldMap = (_a = sameAs == null ? void 0 : sameAs.fieldMap) != null ? _a : {};
|
|
2019
|
+
const sourceSignature = JSON.stringify(
|
|
2020
|
+
Object.values(fieldMap).map((sourceId) => {
|
|
2021
|
+
var _a2;
|
|
2022
|
+
return (_a2 = values[sourceId]) != null ? _a2 : null;
|
|
2023
|
+
})
|
|
2024
|
+
);
|
|
2025
|
+
react.useEffect(() => {
|
|
2026
|
+
var _a2;
|
|
2027
|
+
if (!sameAs || !toggleOn) return;
|
|
2028
|
+
for (const [targetId, sourceId] of Object.entries(sameAs.fieldMap)) {
|
|
2029
|
+
setFieldValue(targetId, (_a2 = values[sourceId]) != null ? _a2 : "");
|
|
2030
|
+
}
|
|
2031
|
+
}, [toggleOn, sourceSignature]);
|
|
2032
|
+
const effectiveTextColor = (_b = previewTextColor != null ? previewTextColor : section.textColor) != null ? _b : formDefaultTextColor;
|
|
2033
|
+
const sortedFields = [...section.fields].sort(
|
|
2034
|
+
(a, b) => {
|
|
2035
|
+
var _a2, _b2, _c, _d;
|
|
2036
|
+
return ((_b2 = (_a2 = a.layout) == null ? void 0 : _a2.order) != null ? _b2 : 0) - ((_d = (_c = b.layout) == null ? void 0 : _c.order) != null ? _d : 0);
|
|
2037
|
+
}
|
|
2038
|
+
);
|
|
2039
|
+
const gap = spacingGap[style.spacing || "normal"];
|
|
2040
|
+
const divider = style.sectionDividers && !isLast;
|
|
2041
|
+
const isStacked = style.inputVariant === "stacked";
|
|
2042
|
+
const sectionWrapperClass = tailwindMerge.twMerge(
|
|
2043
|
+
isStacked ? "space-y-4" : "mb-6",
|
|
2044
|
+
divider && "border-b border-gray-200 dark:border-zinc-700 pb-6"
|
|
2045
|
+
);
|
|
2046
|
+
const titleClass = tailwindMerge.twMerge(
|
|
2047
|
+
"text-lg font-semibold",
|
|
2048
|
+
effectiveTextColor ? "" : "text-gray-800 dark:text-zinc-100",
|
|
2049
|
+
!isStacked && "mb-1"
|
|
2050
|
+
);
|
|
2051
|
+
const descriptionClass = tailwindMerge.twMerge(
|
|
2052
|
+
"text-sm",
|
|
2053
|
+
effectiveTextColor ? "" : "text-gray-500 dark:text-zinc-400",
|
|
2054
|
+
!isStacked && "mb-4"
|
|
2055
|
+
);
|
|
2056
|
+
const textStyle = effectiveTextColor ? { color: effectiveTextColor } : void 0;
|
|
2057
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: sectionWrapperClass, children: [
|
|
2058
|
+
section.title && /* @__PURE__ */ jsxRuntime.jsx("legend", { className: titleClass, style: textStyle, children: section.title }),
|
|
2059
|
+
section.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: descriptionClass, style: textStyle, children: section.description }),
|
|
2060
|
+
sameAs && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 flex items-center gap-3", children: [
|
|
2061
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2062
|
+
radixUi.Checkbox.Root,
|
|
2063
|
+
{
|
|
2064
|
+
id: toggleKey,
|
|
2065
|
+
checked: toggleOn,
|
|
2066
|
+
onCheckedChange: (checked) => setFieldValue(toggleKey, checked === true),
|
|
2067
|
+
className: "flex h-5 w-5 items-center justify-center rounded border",
|
|
2068
|
+
style: toggleOn ? { borderColor: FORM_VAR.inputFocusBorder, backgroundColor: FORM_VAR.inputFocusBorder } : { borderColor: FORM_VAR.inputBorder, backgroundColor: FORM_VAR.inputBg },
|
|
2069
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(radixUi.Checkbox.Indicator, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsCheck, { className: "text-white" }) })
|
|
2070
|
+
}
|
|
2071
|
+
),
|
|
2072
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2073
|
+
"label",
|
|
2074
|
+
{
|
|
2075
|
+
htmlFor: toggleKey,
|
|
2076
|
+
className: "cursor-pointer text-sm",
|
|
2077
|
+
style: { color: FORM_VAR.labelText },
|
|
2078
|
+
children: sameAs.toggleLabel
|
|
2079
|
+
}
|
|
2080
|
+
)
|
|
2081
|
+
] }),
|
|
2082
|
+
(() => {
|
|
2083
|
+
const fieldsGrid = /* @__PURE__ */ jsxRuntime.jsx(
|
|
2084
|
+
"div",
|
|
2085
|
+
{
|
|
2086
|
+
className: tailwindMerge.twMerge(
|
|
2087
|
+
"grid grid-cols-1 md:grid-cols-6",
|
|
2088
|
+
gap,
|
|
2089
|
+
inlineSubmit && "min-w-0 flex-auto"
|
|
2090
|
+
),
|
|
2091
|
+
children: sortedFields.map((field, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2092
|
+
DynamicFormField,
|
|
2093
|
+
{
|
|
2094
|
+
field,
|
|
2095
|
+
mirrored: toggleOn && field.id in fieldMap,
|
|
2096
|
+
mirrorBehavior: sameAs == null ? void 0 : sameAs.behavior
|
|
2097
|
+
},
|
|
2098
|
+
`${field.id}-${i}`
|
|
2099
|
+
))
|
|
2100
|
+
}
|
|
2101
|
+
);
|
|
2102
|
+
return inlineSubmit ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-3", children: [
|
|
2103
|
+
fieldsGrid,
|
|
2104
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: tailwindMerge.twMerge("flex-none", !isStacked && "pt-3"), children: inlineSubmit })
|
|
2105
|
+
] }) : fieldsGrid;
|
|
2106
|
+
})()
|
|
2107
|
+
] });
|
|
2108
|
+
};
|
|
2109
|
+
function globalTracker() {
|
|
2110
|
+
if (typeof window === "undefined") return void 0;
|
|
2111
|
+
return window.__vtTrack;
|
|
2112
|
+
}
|
|
2113
|
+
function getSensitiveFieldIds(definition) {
|
|
2114
|
+
const ids = [];
|
|
2115
|
+
for (const section of definition.sections) {
|
|
2116
|
+
for (const field of section.fields) {
|
|
2117
|
+
if (field.type === "sensitive") ids.push(field.id);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
return ids;
|
|
2121
|
+
}
|
|
2122
|
+
function getHiddenFieldIds(definition, values) {
|
|
2123
|
+
const ids = [];
|
|
2124
|
+
for (const section of definition.sections) {
|
|
2125
|
+
for (const field of section.fields) {
|
|
2126
|
+
if (field.showWhen && !isVisibilityConditionMet(field.showWhen, values[field.showWhen.fieldId])) {
|
|
2127
|
+
ids.push(field.id);
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
return ids;
|
|
2132
|
+
}
|
|
2133
|
+
function getSameAsToggleKeys(definition) {
|
|
2134
|
+
return definition.sections.filter((s) => s.sameAs).map((s) => sameAsToggleKey(s.id));
|
|
2135
|
+
}
|
|
2136
|
+
function fetchTransportKey(endpoint) {
|
|
2137
|
+
return __async(this, null, function* () {
|
|
2138
|
+
const res = yield fetch(endpoint, { method: "GET" });
|
|
2139
|
+
if (!res.ok) {
|
|
2140
|
+
throw new Error(
|
|
2141
|
+
`Failed to fetch transport key: ${res.status} ${res.statusText}`
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
const data = yield res.json();
|
|
2145
|
+
if (!(data == null ? void 0 : data.kid) || !(data == null ? void 0 : data.jwk)) {
|
|
2146
|
+
throw new Error("Transport key endpoint returned an invalid payload");
|
|
2147
|
+
}
|
|
2148
|
+
return data;
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
var presetNonBgClasses = {
|
|
2152
|
+
default: "",
|
|
2153
|
+
minimal: "",
|
|
2154
|
+
bordered: "border border-gray-200",
|
|
2155
|
+
shadow: "shadow-lg",
|
|
2156
|
+
card: "shadow-lg border border-gray-200",
|
|
2157
|
+
dark: ""
|
|
2158
|
+
};
|
|
2159
|
+
var radiusClasses = {
|
|
2160
|
+
none: "rounded-none",
|
|
2161
|
+
sm: "rounded-sm",
|
|
2162
|
+
md: "rounded-md",
|
|
2163
|
+
lg: "rounded-lg",
|
|
2164
|
+
full: "rounded-2xl"
|
|
2165
|
+
};
|
|
2166
|
+
var spacingClasses = {
|
|
2167
|
+
compact: "p-3",
|
|
2168
|
+
normal: "p-6",
|
|
2169
|
+
relaxed: "p-8"
|
|
2170
|
+
};
|
|
2171
|
+
function getButtonClasses(style) {
|
|
2172
|
+
const radius = radiusClasses[style.borderRadius] || "rounded-md";
|
|
2173
|
+
const weight = style.inputVariant === "stacked" ? "font-semibold" : "font-medium";
|
|
2174
|
+
switch (style.buttonVariant) {
|
|
2175
|
+
case "outline":
|
|
2176
|
+
return `${radius} border-2 bg-transparent ${weight} transition-colors`;
|
|
2177
|
+
case "ghost":
|
|
2178
|
+
return `${radius} bg-transparent ${weight} transition-colors`;
|
|
2179
|
+
case "filled":
|
|
2180
|
+
default:
|
|
2181
|
+
return `${radius} ${weight} transition-colors`;
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
function getButtonStyle(style) {
|
|
2185
|
+
switch (style.buttonVariant) {
|
|
2186
|
+
case "outline":
|
|
2187
|
+
return { borderColor: FORM_VAR.buttonBg, color: FORM_VAR.buttonBg };
|
|
2188
|
+
case "ghost":
|
|
2189
|
+
return { color: FORM_VAR.buttonBg };
|
|
2190
|
+
case "filled":
|
|
2191
|
+
default:
|
|
2192
|
+
return {
|
|
2193
|
+
backgroundColor: FORM_VAR.buttonBg,
|
|
2194
|
+
color: FORM_VAR.buttonText
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
function interpolateSuccessMessage(template, response) {
|
|
2199
|
+
if (!template.includes("{{") || !response) return template;
|
|
2200
|
+
return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, key) => {
|
|
2201
|
+
const value = response[key];
|
|
2202
|
+
if (value === void 0 || value === null) return "";
|
|
2203
|
+
return String(value);
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
var Spinner = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2207
|
+
"svg",
|
|
2208
|
+
{
|
|
2209
|
+
className: "-ml-1 mr-2 h-4 w-4 animate-spin",
|
|
2210
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2211
|
+
fill: "none",
|
|
2212
|
+
viewBox: "0 0 24 24",
|
|
2213
|
+
"aria-hidden": "true",
|
|
2214
|
+
children: [
|
|
2215
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2216
|
+
"circle",
|
|
2217
|
+
{
|
|
2218
|
+
className: "opacity-25",
|
|
2219
|
+
cx: "12",
|
|
2220
|
+
cy: "12",
|
|
2221
|
+
r: "10",
|
|
2222
|
+
stroke: "currentColor",
|
|
2223
|
+
strokeWidth: "4"
|
|
2224
|
+
}
|
|
2225
|
+
),
|
|
2226
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2227
|
+
"path",
|
|
2228
|
+
{
|
|
2229
|
+
className: "opacity-75",
|
|
2230
|
+
fill: "currentColor",
|
|
2231
|
+
d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z"
|
|
2232
|
+
}
|
|
2233
|
+
)
|
|
2234
|
+
]
|
|
2235
|
+
}
|
|
2236
|
+
);
|
|
2237
|
+
var SuccessBanner = ({ message }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2238
|
+
"div",
|
|
2239
|
+
{
|
|
2240
|
+
role: "status",
|
|
2241
|
+
"aria-live": "polite",
|
|
2242
|
+
className: "flex items-start gap-3 rounded-md border border-green-200 bg-green-50 px-4 py-3 text-sm text-green-800",
|
|
2243
|
+
children: [
|
|
2244
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2245
|
+
"svg",
|
|
2246
|
+
{
|
|
2247
|
+
className: "mt-0.5 h-4 w-4 flex-shrink-0",
|
|
2248
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2249
|
+
viewBox: "0 0 20 20",
|
|
2250
|
+
fill: "currentColor",
|
|
2251
|
+
"aria-hidden": "true",
|
|
2252
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2253
|
+
"path",
|
|
2254
|
+
{
|
|
2255
|
+
fillRule: "evenodd",
|
|
2256
|
+
d: "M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm3.707-9.293a1 1 0 0 0-1.414-1.414L9 10.586 7.707 9.293a1 1 0 0 0-1.414 1.414l2 2a1 1 0 0 0 1.414 0l4-4z",
|
|
2257
|
+
clipRule: "evenodd"
|
|
2258
|
+
}
|
|
2259
|
+
)
|
|
2260
|
+
}
|
|
2261
|
+
),
|
|
2262
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: message })
|
|
2263
|
+
]
|
|
2264
|
+
}
|
|
2265
|
+
);
|
|
2266
|
+
var ErrorBanner = ({
|
|
2267
|
+
message,
|
|
2268
|
+
onDismiss
|
|
2269
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2270
|
+
"div",
|
|
2271
|
+
{
|
|
2272
|
+
role: "alert",
|
|
2273
|
+
className: "flex items-start gap-3 rounded-md border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-800",
|
|
2274
|
+
children: [
|
|
2275
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2276
|
+
"svg",
|
|
2277
|
+
{
|
|
2278
|
+
className: "mt-0.5 h-4 w-4 flex-shrink-0",
|
|
2279
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2280
|
+
viewBox: "0 0 20 20",
|
|
2281
|
+
fill: "currentColor",
|
|
2282
|
+
"aria-hidden": "true",
|
|
2283
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2284
|
+
"path",
|
|
2285
|
+
{
|
|
2286
|
+
fillRule: "evenodd",
|
|
2287
|
+
d: "M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0zm-7 4a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm-1-9a1 1 0 0 0-1 1v4a1 1 0 1 0 2 0V6a1 1 0 0 0-1-1z",
|
|
2288
|
+
clipRule: "evenodd"
|
|
2289
|
+
}
|
|
2290
|
+
)
|
|
2291
|
+
}
|
|
2292
|
+
),
|
|
2293
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: message }),
|
|
2294
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2295
|
+
"button",
|
|
2296
|
+
{
|
|
2297
|
+
type: "button",
|
|
2298
|
+
onClick: onDismiss,
|
|
2299
|
+
className: "font-medium text-red-900 underline-offset-2 hover:underline",
|
|
2300
|
+
children: "Try again"
|
|
2301
|
+
}
|
|
2302
|
+
)
|
|
2303
|
+
]
|
|
2304
|
+
}
|
|
2305
|
+
);
|
|
2306
|
+
var DynamicForm = ({
|
|
2307
|
+
definition,
|
|
2308
|
+
apiRoute,
|
|
2309
|
+
onSuccess,
|
|
2310
|
+
onError,
|
|
2311
|
+
extraData,
|
|
2312
|
+
className,
|
|
2313
|
+
onFormView,
|
|
2314
|
+
onFormSubmit: onFormSubmitCallback,
|
|
2315
|
+
transportKeyEndpoint = "/api/forms/transport-key",
|
|
2316
|
+
previewState,
|
|
2317
|
+
previewTouchAllSignal,
|
|
2318
|
+
previewUntouchAllSignal,
|
|
2319
|
+
previewBg,
|
|
2320
|
+
previewTextColor
|
|
2321
|
+
}) => {
|
|
2322
|
+
var _a, _b, _c;
|
|
2323
|
+
const [submitStatus, setSubmitStatus] = react.useState("idle");
|
|
2324
|
+
const [postSuccessCooldown, setPostSuccessCooldown] = react.useState(false);
|
|
2325
|
+
react.useEffect(() => {
|
|
2326
|
+
if (submitStatus !== "success") return;
|
|
2327
|
+
setPostSuccessCooldown(true);
|
|
2328
|
+
const t = setTimeout(() => setPostSuccessCooldown(false), 2e3);
|
|
2329
|
+
return () => clearTimeout(t);
|
|
2330
|
+
}, [submitStatus]);
|
|
2331
|
+
const [responseData, setResponseData] = react.useState(
|
|
2332
|
+
null
|
|
2333
|
+
);
|
|
2334
|
+
const formikRef = react.useRef(null);
|
|
2335
|
+
react.useEffect(() => {
|
|
2336
|
+
var _a2, _b2;
|
|
2337
|
+
(_b2 = onFormView != null ? onFormView : (_a2 = globalTracker()) == null ? void 0 : _a2.trackFormView) == null ? void 0 : _b2(
|
|
2338
|
+
definition.id,
|
|
2339
|
+
definition.name
|
|
2340
|
+
);
|
|
2341
|
+
}, []);
|
|
2342
|
+
const effectiveSubmitStatus = previewState === "success" ? "success" : previewState === "error" ? "error" : previewState === "idle" ? "idle" : submitStatus;
|
|
2343
|
+
const previewSubmitting = previewState === "submitting";
|
|
2344
|
+
const spamProtection = __spreadValues(__spreadValues({}, DEFAULT_SPAM_PROTECTION), definition.submitConfig.spamProtection);
|
|
2345
|
+
const honeypotEnabled = spamProtection.honeypot !== false;
|
|
2346
|
+
const minSubmitTime = Math.max(0, (_a = spamProtection.minSubmitTime) != null ? _a : 0);
|
|
2347
|
+
const mountTimeRef = react.useRef(Date.now());
|
|
2348
|
+
react.useEffect(() => {
|
|
2349
|
+
mountTimeRef.current = Date.now();
|
|
2350
|
+
}, [definition.id]);
|
|
2351
|
+
const validationSchema = react.useMemo(() => buildYupSchema(definition), [definition]);
|
|
2352
|
+
const initialValues = react.useMemo(() => {
|
|
2353
|
+
const base = buildInitialValues(definition);
|
|
2354
|
+
if (honeypotEnabled) {
|
|
2355
|
+
base[HONEYPOT_FIELD_NAME] = "";
|
|
2356
|
+
}
|
|
2357
|
+
return base;
|
|
2358
|
+
}, [definition, honeypotEnabled]);
|
|
2359
|
+
const sortedSections = react.useMemo(
|
|
2360
|
+
() => [...definition.sections].sort((a, b) => a.order - b.order),
|
|
2361
|
+
[definition.sections]
|
|
2362
|
+
);
|
|
2363
|
+
react.useEffect(() => {
|
|
2364
|
+
if (previewTouchAllSignal === void 0 || !formikRef.current) return;
|
|
2365
|
+
const touched = {};
|
|
2366
|
+
for (const section of definition.sections) {
|
|
2367
|
+
for (const field of section.fields) {
|
|
2368
|
+
touched[field.id] = true;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
formikRef.current.setTouched(touched, true);
|
|
2372
|
+
}, [previewTouchAllSignal, definition.sections]);
|
|
2373
|
+
react.useEffect(() => {
|
|
2374
|
+
if (previewUntouchAllSignal === void 0 || !formikRef.current) return;
|
|
2375
|
+
formikRef.current.setTouched({}, false);
|
|
2376
|
+
}, [previewUntouchAllSignal]);
|
|
2377
|
+
const style = __spreadValues(__spreadValues({}, DEFAULT_FORM_STYLE), definition.style);
|
|
2378
|
+
const isStacked = style.inputVariant === "stacked";
|
|
2379
|
+
const isCard = style.preset === "card";
|
|
2380
|
+
const submittingText = (_b = definition.submitConfig.submittingText) != null ? _b : "Submitting...";
|
|
2381
|
+
const successBehavior = (_c = definition.submitConfig.successBehavior) != null ? _c : "message";
|
|
2382
|
+
const hasPreviewOverride = Boolean(previewBg || previewTextColor);
|
|
2383
|
+
const previewOverrides = hasPreviewOverride ? { backgroundColor: previewBg, textColor: previewTextColor } : null;
|
|
2384
|
+
const cssVarStyle = buildFormCssVars(style, previewBg);
|
|
2385
|
+
const effectiveFormBg = previewBg != null ? previewBg : style.formBackgroundColor;
|
|
2386
|
+
const formInlineStyle = __spreadValues(__spreadValues(__spreadValues({}, cssVarStyle), effectiveFormBg ? { backgroundColor: effectiveFormBg } : {}), previewTextColor ? { color: previewTextColor } : {});
|
|
2387
|
+
const formClasses = tailwindMerge.twMerge(
|
|
2388
|
+
presetNonBgClasses[style.preset] || "",
|
|
2389
|
+
radiusClasses[style.borderRadius] || "rounded-md",
|
|
2390
|
+
isCard ? "p-8" : spacingClasses[style.spacing] || "p-6",
|
|
2391
|
+
isStacked ? "space-y-8" : "",
|
|
2392
|
+
className
|
|
2393
|
+
);
|
|
2394
|
+
const inlineButton = style.buttonPlacement === "inline";
|
|
2395
|
+
const buttonSizeClass = inlineButton ? isStacked ? "flex-none px-6 py-3 text-base" : "flex-none px-6 py-2.5 text-sm" : isStacked ? "w-full px-6 py-3 text-base" : "mt-4 w-full px-6 py-2.5 text-sm";
|
|
2396
|
+
const bannerWrapperClass = isStacked ? "" : "mb-4";
|
|
2397
|
+
const successMessage = interpolateSuccessMessage(
|
|
2398
|
+
definition.submitConfig.successMessage,
|
|
2399
|
+
responseData
|
|
2400
|
+
);
|
|
2401
|
+
if (successBehavior === "replace" && effectiveSubmitStatus === "success") {
|
|
2402
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsxRuntime.jsx(FormPreviewOverridesProvider, { value: previewOverrides, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2403
|
+
"div",
|
|
2404
|
+
{
|
|
2405
|
+
className: formClasses,
|
|
2406
|
+
style: formInlineStyle,
|
|
2407
|
+
"data-form-version": definition.version,
|
|
2408
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SuccessBanner, { message: successMessage })
|
|
2409
|
+
}
|
|
2410
|
+
) }) });
|
|
2411
|
+
}
|
|
2412
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsxRuntime.jsx(FormPreviewOverridesProvider, { value: previewOverrides, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2413
|
+
formik.Formik,
|
|
2414
|
+
{
|
|
2415
|
+
innerRef: formikRef,
|
|
2416
|
+
initialValues,
|
|
2417
|
+
validationSchema,
|
|
2418
|
+
onSubmit: (_0, _1) => __async(null, [_0, _1], function* (values, { setSubmitting, resetForm }) {
|
|
2419
|
+
var _a2, _b2, _d, _e, _f;
|
|
2420
|
+
if (previewState) {
|
|
2421
|
+
setSubmitting(false);
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
const honeypotTriggered = honeypotEnabled && typeof values[HONEYPOT_FIELD_NAME] === "string" && values[HONEYPOT_FIELD_NAME].length > 0;
|
|
2425
|
+
const elapsedSeconds = (Date.now() - mountTimeRef.current) / 1e3;
|
|
2426
|
+
const timerTriggered = minSubmitTime > 0 && elapsedSeconds < minSubmitTime;
|
|
2427
|
+
if (honeypotTriggered || timerTriggered) {
|
|
2428
|
+
const proc = globalThis.process;
|
|
2429
|
+
if (((_a2 = proc == null ? void 0 : proc.env) == null ? void 0 : _a2.NODE_ENV) !== "production") {
|
|
2430
|
+
const reason = honeypotTriggered ? "honeypot" : "timer";
|
|
2431
|
+
console.debug(`[forms] Spam detected: ${reason}`);
|
|
2432
|
+
}
|
|
2433
|
+
setResponseData(null);
|
|
2434
|
+
setSubmitStatus("success");
|
|
2435
|
+
if (successBehavior === "reset" || successBehavior === "replace") {
|
|
2436
|
+
resetForm();
|
|
2437
|
+
}
|
|
2438
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
2439
|
+
setSubmitting(false);
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2442
|
+
setSubmitStatus("idle");
|
|
2443
|
+
try {
|
|
2444
|
+
const _c2 = values, { [_b2 = HONEYPOT_FIELD_NAME]: _hp } = _c2, cleanValues = __objRest(_c2, [__restKey(_b2)]);
|
|
2445
|
+
const payload = __spreadProps(__spreadValues(__spreadValues({}, cleanValues), extraData), {
|
|
2446
|
+
formId: definition.id
|
|
2447
|
+
});
|
|
2448
|
+
for (const hiddenId of getHiddenFieldIds(definition, cleanValues)) {
|
|
2449
|
+
delete payload[hiddenId];
|
|
2450
|
+
}
|
|
2451
|
+
for (const toggleKey of getSameAsToggleKeys(definition)) {
|
|
2452
|
+
delete payload[toggleKey];
|
|
2453
|
+
}
|
|
2454
|
+
const sensitiveIds = getSensitiveFieldIds(definition);
|
|
2455
|
+
if (sensitiveIds.length > 0) {
|
|
2456
|
+
const transportKey = yield fetchTransportKey(transportKeyEndpoint);
|
|
2457
|
+
for (const fieldId of sensitiveIds) {
|
|
2458
|
+
const plaintext = cleanValues[fieldId];
|
|
2459
|
+
if (typeof plaintext !== "string" || plaintext.length === 0) {
|
|
2460
|
+
delete payload[fieldId];
|
|
2461
|
+
continue;
|
|
2462
|
+
}
|
|
2463
|
+
payload[fieldId] = yield encryptSensitiveValue(
|
|
2464
|
+
plaintext,
|
|
2465
|
+
transportKey
|
|
2466
|
+
);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
const res = yield fetch(apiRoute, {
|
|
2470
|
+
method: "POST",
|
|
2471
|
+
headers: { "Content-Type": "application/json" },
|
|
2472
|
+
body: JSON.stringify(payload)
|
|
2473
|
+
});
|
|
2474
|
+
if (!res.ok) {
|
|
2475
|
+
const errBody = yield res.json().catch(() => null);
|
|
2476
|
+
throw new Error(
|
|
2477
|
+
(errBody == null ? void 0 : errBody.error) || `Submission failed (${res.status})`
|
|
2478
|
+
);
|
|
2479
|
+
}
|
|
2480
|
+
let body = null;
|
|
2481
|
+
try {
|
|
2482
|
+
body = yield res.json();
|
|
2483
|
+
} catch (e) {
|
|
2484
|
+
body = null;
|
|
2485
|
+
}
|
|
2486
|
+
setResponseData(body);
|
|
2487
|
+
setSubmitStatus("success");
|
|
2488
|
+
(_f = onFormSubmitCallback != null ? onFormSubmitCallback : (_d = globalTracker()) == null ? void 0 : _d.trackFormSubmit) == null ? void 0 : _f(
|
|
2489
|
+
definition.id,
|
|
2490
|
+
definition.name,
|
|
2491
|
+
(_e = extraData == null ? void 0 : extraData.submissionType) != null ? _e : "contact"
|
|
2492
|
+
);
|
|
2493
|
+
if (successBehavior === "reset" || successBehavior === "replace") {
|
|
2494
|
+
resetForm();
|
|
2495
|
+
}
|
|
2496
|
+
onSuccess == null ? void 0 : onSuccess(body != null ? body : void 0);
|
|
2497
|
+
const redirectUrl = getSafeRedirectUrl(
|
|
2498
|
+
definition.submitConfig.redirectUrl
|
|
2499
|
+
);
|
|
2500
|
+
if (redirectUrl) {
|
|
2501
|
+
window.location.assign(redirectUrl);
|
|
2502
|
+
}
|
|
2503
|
+
} catch (err) {
|
|
2504
|
+
setResponseData(null);
|
|
2505
|
+
setSubmitStatus("error");
|
|
2506
|
+
onError == null ? void 0 : onError(err instanceof Error ? err : new Error("Submission failed"));
|
|
2507
|
+
} finally {
|
|
2508
|
+
setSubmitting(false);
|
|
2509
|
+
}
|
|
2510
|
+
}),
|
|
2511
|
+
children: ({ isSubmitting, getFieldProps }) => {
|
|
2512
|
+
const showSubmitting = isSubmitting || previewSubmitting;
|
|
2513
|
+
const isDisabled = successBehavior === "disable" && effectiveSubmitStatus === "success";
|
|
2514
|
+
const submitLocked = showSubmitting || postSuccessCooldown || previewState === "success";
|
|
2515
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2516
|
+
formik.Form,
|
|
2517
|
+
{
|
|
2518
|
+
className: formClasses,
|
|
2519
|
+
style: formInlineStyle,
|
|
2520
|
+
"data-form-version": definition.version,
|
|
2521
|
+
children: [
|
|
2522
|
+
honeypotEnabled && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2523
|
+
"div",
|
|
2524
|
+
{
|
|
2525
|
+
"aria-hidden": "true",
|
|
2526
|
+
style: {
|
|
2527
|
+
position: "absolute",
|
|
2528
|
+
left: "-9999px",
|
|
2529
|
+
top: "auto",
|
|
2530
|
+
width: 0,
|
|
2531
|
+
height: 0,
|
|
2532
|
+
overflow: "hidden",
|
|
2533
|
+
opacity: 0,
|
|
2534
|
+
zIndex: -1
|
|
2535
|
+
},
|
|
2536
|
+
children: [
|
|
2537
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: HONEYPOT_FIELD_NAME, children: "Website (leave blank)" }),
|
|
2538
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2539
|
+
"input",
|
|
2540
|
+
__spreadProps(__spreadValues({
|
|
2541
|
+
type: "text",
|
|
2542
|
+
id: HONEYPOT_FIELD_NAME
|
|
2543
|
+
}, getFieldProps(HONEYPOT_FIELD_NAME)), {
|
|
2544
|
+
tabIndex: -1,
|
|
2545
|
+
autoComplete: "off"
|
|
2546
|
+
})
|
|
2547
|
+
)
|
|
2548
|
+
]
|
|
2549
|
+
}
|
|
2550
|
+
),
|
|
2551
|
+
effectiveSubmitStatus === "success" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: bannerWrapperClass, children: /* @__PURE__ */ jsxRuntime.jsx(SuccessBanner, { message: successMessage }) }),
|
|
2552
|
+
effectiveSubmitStatus === "error" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: bannerWrapperClass, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2553
|
+
ErrorBanner,
|
|
2554
|
+
{
|
|
2555
|
+
message: definition.submitConfig.errorMessage,
|
|
2556
|
+
onDismiss: () => setSubmitStatus("idle")
|
|
2557
|
+
}
|
|
2558
|
+
) }),
|
|
2559
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2560
|
+
"fieldset",
|
|
2561
|
+
{
|
|
2562
|
+
disabled: isDisabled,
|
|
2563
|
+
"aria-disabled": isDisabled,
|
|
2564
|
+
className: tailwindMerge.twMerge(
|
|
2565
|
+
"min-w-0 border-0 p-0",
|
|
2566
|
+
isStacked ? "space-y-8" : "",
|
|
2567
|
+
isDisabled ? "pointer-events-none opacity-60" : ""
|
|
2568
|
+
),
|
|
2569
|
+
children: (() => {
|
|
2570
|
+
const submitButton = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2571
|
+
"button",
|
|
2572
|
+
{
|
|
2573
|
+
type: "submit",
|
|
2574
|
+
disabled: submitLocked || isDisabled,
|
|
2575
|
+
className: tailwindMerge.twMerge(
|
|
2576
|
+
buttonSizeClass,
|
|
2577
|
+
"inline-flex cursor-pointer items-center justify-center disabled:cursor-not-allowed disabled:opacity-60",
|
|
2578
|
+
getButtonClasses(style)
|
|
2579
|
+
),
|
|
2580
|
+
style: getButtonStyle(style),
|
|
2581
|
+
"aria-busy": showSubmitting,
|
|
2582
|
+
children: [
|
|
2583
|
+
showSubmitting && /* @__PURE__ */ jsxRuntime.jsx(Spinner, {}),
|
|
2584
|
+
showSubmitting ? submittingText : definition.submitConfig.buttonText
|
|
2585
|
+
]
|
|
2586
|
+
}
|
|
2587
|
+
);
|
|
2588
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2589
|
+
sortedSections.map((section, idx) => {
|
|
2590
|
+
const isLast = idx === sortedSections.length - 1;
|
|
2591
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2592
|
+
DynamicFormSection,
|
|
2593
|
+
{
|
|
2594
|
+
section,
|
|
2595
|
+
isLast,
|
|
2596
|
+
formDefaultTextColor: definition.defaultTextColor,
|
|
2597
|
+
inlineSubmit: inlineButton && isLast ? submitButton : void 0
|
|
2598
|
+
},
|
|
2599
|
+
section.id
|
|
2600
|
+
);
|
|
2601
|
+
}),
|
|
2602
|
+
!inlineButton && submitButton
|
|
2603
|
+
] });
|
|
2604
|
+
})()
|
|
2605
|
+
}
|
|
2606
|
+
)
|
|
2607
|
+
]
|
|
2608
|
+
}
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
) }) });
|
|
2613
|
+
};
|
|
2614
|
+
function buildQueryString(opts) {
|
|
2615
|
+
const params = new URLSearchParams({
|
|
2616
|
+
projectId: opts.projectId,
|
|
2617
|
+
apiKey: opts.apiKey
|
|
2618
|
+
});
|
|
2619
|
+
if ("formId" in opts && opts.formId) params.set("formId", opts.formId);
|
|
2620
|
+
if ("formSlug" in opts && opts.formSlug) params.set("slug", opts.formSlug);
|
|
2621
|
+
return params.toString();
|
|
2622
|
+
}
|
|
2623
|
+
function useFormDefinition(opts) {
|
|
2624
|
+
const [definition, setDefinition] = react.useState(null);
|
|
2625
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
2626
|
+
const [error, setError] = react.useState(null);
|
|
2627
|
+
const { cmsUrl, projectId, apiKey } = opts;
|
|
2628
|
+
const formId = "formId" in opts ? opts.formId : void 0;
|
|
2629
|
+
const formSlug = "formSlug" in opts ? opts.formSlug : void 0;
|
|
2630
|
+
react.useEffect(() => {
|
|
2631
|
+
let cancelled = false;
|
|
2632
|
+
function fetchDefinition() {
|
|
2633
|
+
return __async(this, null, function* () {
|
|
2634
|
+
setIsLoading(true);
|
|
2635
|
+
setError(null);
|
|
2636
|
+
try {
|
|
2637
|
+
const qs = buildQueryString(opts);
|
|
2638
|
+
const res = yield fetch(`${cmsUrl}/api/forms?${qs}`);
|
|
2639
|
+
if (!res.ok) {
|
|
2640
|
+
throw new Error(`Failed to fetch form definition: ${res.statusText}`);
|
|
2641
|
+
}
|
|
2642
|
+
const data = yield res.json();
|
|
2643
|
+
if (!cancelled) {
|
|
2644
|
+
setDefinition(data);
|
|
2645
|
+
}
|
|
2646
|
+
} catch (err) {
|
|
2647
|
+
if (!cancelled) {
|
|
2648
|
+
setError(err instanceof Error ? err : new Error("Failed to fetch form"));
|
|
2649
|
+
}
|
|
2650
|
+
} finally {
|
|
2651
|
+
if (!cancelled) {
|
|
2652
|
+
setIsLoading(false);
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
fetchDefinition();
|
|
2658
|
+
return () => {
|
|
2659
|
+
cancelled = true;
|
|
2660
|
+
};
|
|
2661
|
+
}, [cmsUrl, projectId, apiKey, formId, formSlug]);
|
|
2662
|
+
return { definition, isLoading, error };
|
|
2663
|
+
}
|
|
2664
|
+
function getFormDefinition(opts) {
|
|
2665
|
+
return __async(this, null, function* () {
|
|
2666
|
+
var _a;
|
|
2667
|
+
try {
|
|
2668
|
+
const qs = buildQueryString(opts);
|
|
2669
|
+
const res = yield fetch(`${opts.cmsUrl}/api/forms?${qs}`, {
|
|
2670
|
+
next: { revalidate: (_a = opts.revalidate) != null ? _a : 3600 }
|
|
2671
|
+
});
|
|
2672
|
+
if (!res.ok) return null;
|
|
2673
|
+
return res.json();
|
|
2674
|
+
} catch (e) {
|
|
2675
|
+
return null;
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
var DEFAULT_HISTORY_LIMIT = 50;
|
|
2680
|
+
function applyUpdater(updater, current) {
|
|
2681
|
+
return typeof updater === "function" ? updater(current) : updater;
|
|
2682
|
+
}
|
|
2683
|
+
function useUndoRedo(initialState, options = {}) {
|
|
2684
|
+
var _a;
|
|
2685
|
+
const limit = (_a = options.historyLimit) != null ? _a : DEFAULT_HISTORY_LIMIT;
|
|
2686
|
+
const [history, setHistory] = react.useState(() => ({
|
|
2687
|
+
past: [],
|
|
2688
|
+
present: initialState,
|
|
2689
|
+
future: []
|
|
2690
|
+
}));
|
|
2691
|
+
const setState = react.useCallback(
|
|
2692
|
+
(updater) => {
|
|
2693
|
+
setHistory((h) => {
|
|
2694
|
+
const next = applyUpdater(updater, h.present);
|
|
2695
|
+
if (Object.is(next, h.present)) return h;
|
|
2696
|
+
const past = [...h.past, h.present];
|
|
2697
|
+
if (past.length > limit) past.splice(0, past.length - limit);
|
|
2698
|
+
return { past, present: next, future: [] };
|
|
2699
|
+
});
|
|
2700
|
+
},
|
|
2701
|
+
[limit]
|
|
2702
|
+
);
|
|
2703
|
+
const reset = react.useCallback((value) => {
|
|
2704
|
+
setHistory(
|
|
2705
|
+
(h) => Object.is(value, h.present) ? h : { past: [], present: value, future: [] }
|
|
2706
|
+
);
|
|
2707
|
+
}, []);
|
|
2708
|
+
const undo = react.useCallback(() => {
|
|
2709
|
+
setHistory((h) => {
|
|
2710
|
+
if (h.past.length === 0) return h;
|
|
2711
|
+
const previous = h.past[h.past.length - 1];
|
|
2712
|
+
const past = h.past.slice(0, -1);
|
|
2713
|
+
return { past, present: previous, future: [h.present, ...h.future] };
|
|
2714
|
+
});
|
|
2715
|
+
}, []);
|
|
2716
|
+
const redo = react.useCallback(() => {
|
|
2717
|
+
setHistory((h) => {
|
|
2718
|
+
if (h.future.length === 0) return h;
|
|
2719
|
+
const [next, ...rest] = h.future;
|
|
2720
|
+
return { past: [...h.past, h.present], present: next, future: rest };
|
|
2721
|
+
});
|
|
2722
|
+
}, []);
|
|
2723
|
+
return [
|
|
2724
|
+
history.present,
|
|
2725
|
+
setState,
|
|
2726
|
+
undo,
|
|
2727
|
+
redo,
|
|
2728
|
+
history.past.length > 0,
|
|
2729
|
+
history.future.length > 0,
|
|
2730
|
+
{ reset, historySize: history.past.length }
|
|
2731
|
+
];
|
|
2732
|
+
}
|
|
2733
|
+
function useUndoRedoShortcuts(opts) {
|
|
2734
|
+
const { undo, redo, enabled = true } = opts;
|
|
2735
|
+
react.useEffect(() => {
|
|
2736
|
+
if (!enabled || typeof window === "undefined") return;
|
|
2737
|
+
const handler = (e) => {
|
|
2738
|
+
const target = e.target;
|
|
2739
|
+
if (target) {
|
|
2740
|
+
const tag = target.tagName;
|
|
2741
|
+
const editable = target.isContentEditable;
|
|
2742
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || editable) {
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
const meta = e.metaKey || e.ctrlKey;
|
|
2747
|
+
if (!meta) return;
|
|
2748
|
+
const key = e.key.toLowerCase();
|
|
2749
|
+
if (key !== "z") return;
|
|
2750
|
+
e.preventDefault();
|
|
2751
|
+
if (e.shiftKey) {
|
|
2752
|
+
redo();
|
|
2753
|
+
} else {
|
|
2754
|
+
undo();
|
|
2755
|
+
}
|
|
2756
|
+
};
|
|
2757
|
+
window.addEventListener("keydown", handler);
|
|
2758
|
+
return () => window.removeEventListener("keydown", handler);
|
|
2759
|
+
}, [undo, redo, enabled]);
|
|
2760
|
+
}
|
|
2761
|
+
var DEFAULT_DRAG_TYPE = "application/x-vt-reorder";
|
|
2762
|
+
function useDragReorder({
|
|
2763
|
+
items,
|
|
2764
|
+
getId,
|
|
2765
|
+
onReorder,
|
|
2766
|
+
dragType = DEFAULT_DRAG_TYPE
|
|
2767
|
+
}) {
|
|
2768
|
+
const [state, setState] = react.useState({
|
|
2769
|
+
draggingId: null,
|
|
2770
|
+
dragOverId: null,
|
|
2771
|
+
dragOverPosition: null
|
|
2772
|
+
});
|
|
2773
|
+
const lastOverRef = react.useRef(null);
|
|
2774
|
+
const reset = react.useCallback(() => {
|
|
2775
|
+
lastOverRef.current = null;
|
|
2776
|
+
setState({ draggingId: null, dragOverId: null, dragOverPosition: null });
|
|
2777
|
+
}, []);
|
|
2778
|
+
const itemHandlers = react.useCallback(
|
|
2779
|
+
(id) => ({
|
|
2780
|
+
draggable: true,
|
|
2781
|
+
onDragStart: (e) => {
|
|
2782
|
+
e.stopPropagation();
|
|
2783
|
+
try {
|
|
2784
|
+
e.dataTransfer.setData(dragType, id);
|
|
2785
|
+
e.dataTransfer.setData("text/plain", id);
|
|
2786
|
+
} catch (e2) {
|
|
2787
|
+
}
|
|
2788
|
+
e.dataTransfer.effectAllowed = "move";
|
|
2789
|
+
setState({
|
|
2790
|
+
draggingId: id,
|
|
2791
|
+
dragOverId: null,
|
|
2792
|
+
dragOverPosition: null
|
|
2793
|
+
});
|
|
2794
|
+
},
|
|
2795
|
+
onDragEnd: () => {
|
|
2796
|
+
reset();
|
|
2797
|
+
},
|
|
2798
|
+
onDragOver: (e) => {
|
|
2799
|
+
const types = Array.from(e.dataTransfer.types);
|
|
2800
|
+
if (!types.includes(dragType)) return;
|
|
2801
|
+
e.preventDefault();
|
|
2802
|
+
e.stopPropagation();
|
|
2803
|
+
e.dataTransfer.dropEffect = "move";
|
|
2804
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2805
|
+
const midpoint = rect.top + rect.height / 2;
|
|
2806
|
+
const position = e.clientY < midpoint ? "before" : "after";
|
|
2807
|
+
if (lastOverRef.current !== id || state.dragOverPosition !== position) {
|
|
2808
|
+
lastOverRef.current = id;
|
|
2809
|
+
setState((s) => __spreadProps(__spreadValues({}, s), {
|
|
2810
|
+
dragOverId: id,
|
|
2811
|
+
dragOverPosition: position
|
|
2812
|
+
}));
|
|
2813
|
+
}
|
|
2814
|
+
},
|
|
2815
|
+
onDragLeave: (e) => {
|
|
2816
|
+
const related = e.relatedTarget;
|
|
2817
|
+
if (!related || !e.currentTarget.contains(related)) {
|
|
2818
|
+
if (lastOverRef.current === id) {
|
|
2819
|
+
lastOverRef.current = null;
|
|
2820
|
+
setState((s) => __spreadProps(__spreadValues({}, s), {
|
|
2821
|
+
dragOverId: null,
|
|
2822
|
+
dragOverPosition: null
|
|
2823
|
+
}));
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
},
|
|
2827
|
+
onDrop: (e) => {
|
|
2828
|
+
const draggedId = e.dataTransfer.getData(dragType);
|
|
2829
|
+
e.preventDefault();
|
|
2830
|
+
e.stopPropagation();
|
|
2831
|
+
if (!draggedId || draggedId === id) {
|
|
2832
|
+
reset();
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
const fromIdx = items.findIndex((it) => getId(it) === draggedId);
|
|
2836
|
+
const toIdx = items.findIndex((it) => getId(it) === id);
|
|
2837
|
+
if (fromIdx < 0 || toIdx < 0) {
|
|
2838
|
+
reset();
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2842
|
+
const midpoint = rect.top + rect.height / 2;
|
|
2843
|
+
const position = e.clientY < midpoint ? "before" : "after";
|
|
2844
|
+
const next = [...items];
|
|
2845
|
+
const [moved] = next.splice(fromIdx, 1);
|
|
2846
|
+
let insertIdx = next.findIndex((it) => getId(it) === id);
|
|
2847
|
+
if (insertIdx < 0) insertIdx = next.length;
|
|
2848
|
+
if (position === "after") insertIdx += 1;
|
|
2849
|
+
next.splice(insertIdx, 0, moved);
|
|
2850
|
+
onReorder(next);
|
|
2851
|
+
reset();
|
|
2852
|
+
}
|
|
2853
|
+
}),
|
|
2854
|
+
[items, getId, onReorder, dragType, reset, state.dragOverPosition]
|
|
2855
|
+
);
|
|
2856
|
+
const isDragging = react.useCallback(
|
|
2857
|
+
(id) => state.draggingId === id,
|
|
2858
|
+
[state.draggingId]
|
|
2859
|
+
);
|
|
2860
|
+
const dropIndicator = react.useCallback(
|
|
2861
|
+
(id) => {
|
|
2862
|
+
if (state.dragOverId !== id) return null;
|
|
2863
|
+
if (state.draggingId === id) return null;
|
|
2864
|
+
return state.dragOverPosition;
|
|
2865
|
+
},
|
|
2866
|
+
[state.dragOverId, state.draggingId, state.dragOverPosition]
|
|
2867
|
+
);
|
|
2868
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
2869
|
+
itemHandlers,
|
|
2870
|
+
isDragging,
|
|
2871
|
+
dropIndicator
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
exports.APPLICATION_STATUS_KEYS = APPLICATION_STATUS_KEYS;
|
|
2876
|
+
exports.CORE_EMAIL_TEMPLATE_VARIABLES = CORE_EMAIL_TEMPLATE_VARIABLES;
|
|
2877
|
+
exports.DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES = DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES;
|
|
2878
|
+
exports.DEFAULT_FILE_FIELD_CONFIG = DEFAULT_FILE_FIELD_CONFIG;
|
|
2879
|
+
exports.DEFAULT_FORM_STYLE = DEFAULT_FORM_STYLE;
|
|
2880
|
+
exports.DEFAULT_NOTIFICATION_EMAIL_HTML = DEFAULT_NOTIFICATION_EMAIL_HTML;
|
|
2881
|
+
exports.DEFAULT_NOTIFICATION_EMAIL_SUBJECT = DEFAULT_NOTIFICATION_EMAIL_SUBJECT;
|
|
2882
|
+
exports.DEFAULT_NOTIFICATION_EMAIL_TEMPLATE = DEFAULT_NOTIFICATION_EMAIL_TEMPLATE;
|
|
2883
|
+
exports.DEFAULT_SENSITIVE_FIELD_CONFIG = DEFAULT_SENSITIVE_FIELD_CONFIG;
|
|
2884
|
+
exports.DEFAULT_SPAM_PROTECTION = DEFAULT_SPAM_PROTECTION;
|
|
2885
|
+
exports.DynamicForm = DynamicForm;
|
|
2886
|
+
exports.DynamicFormField = DynamicFormField;
|
|
2887
|
+
exports.DynamicFormSection = DynamicFormSection;
|
|
2888
|
+
exports.FORM_CSS_VAR = FORM_CSS_VAR;
|
|
2889
|
+
exports.FORM_DEFAULT_COLOR = FORM_DEFAULT_COLOR;
|
|
2890
|
+
exports.FORM_VAR = FORM_VAR;
|
|
2891
|
+
exports.HONEYPOT_FIELD_NAME = HONEYPOT_FIELD_NAME;
|
|
2892
|
+
exports.NEWSLETTER_ALLOWED_FIELD_TYPES = NEWSLETTER_ALLOWED_FIELD_TYPES;
|
|
2893
|
+
exports.SAME_AS_TOGGLE_PREFIX = SAME_AS_TOGGLE_PREFIX;
|
|
2894
|
+
exports.SAMPLE_EMAIL_TEMPLATE_VARIABLES = SAMPLE_EMAIL_TEMPLATE_VARIABLES;
|
|
2895
|
+
exports.applyTextTransform = applyTextTransform;
|
|
2896
|
+
exports.applyTransform = applyTransform;
|
|
2897
|
+
exports.base64ToBuffer = base64ToBuffer;
|
|
2898
|
+
exports.bufferToBase64 = bufferToBase64;
|
|
2899
|
+
exports.buildEmailTemplateVariables = buildEmailTemplateVariables;
|
|
2900
|
+
exports.buildFormCssVars = buildFormCssVars;
|
|
2901
|
+
exports.buildInitialValues = buildInitialValues;
|
|
2902
|
+
exports.buildYupSchema = buildYupSchema;
|
|
2903
|
+
exports.deriveLast4 = deriveLast4;
|
|
2904
|
+
exports.encryptSensitiveValue = encryptSensitiveValue;
|
|
2905
|
+
exports.formatSsn = formatSsn;
|
|
2906
|
+
exports.formatUsPhone = formatUsPhone;
|
|
2907
|
+
exports.getFormDefinition = getFormDefinition;
|
|
2908
|
+
exports.getSafeRedirectUrl = getSafeRedirectUrl;
|
|
2909
|
+
exports.isVisibilityConditionMet = isVisibilityConditionMet;
|
|
2910
|
+
exports.parseFormDefinition = parseFormDefinition;
|
|
2911
|
+
exports.renderEmailTemplate = renderEmailTemplate;
|
|
2912
|
+
exports.renderNotificationEmail = renderNotificationEmail;
|
|
2913
|
+
exports.sameAsToggleKey = sameAsToggleKey;
|
|
2914
|
+
exports.useDragReorder = useDragReorder;
|
|
2915
|
+
exports.useFormDefinition = useFormDefinition;
|
|
2916
|
+
exports.useUndoRedo = useUndoRedo;
|
|
2917
|
+
exports.useUndoRedoShortcuts = useUndoRedoShortcuts;
|
|
2918
|
+
//# sourceMappingURL=index.js.map
|
|
2919
|
+
//# sourceMappingURL=index.js.map
|