@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.d.ts
ADDED
|
@@ -0,0 +1,977 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { CSSProperties, DragEvent } from 'react';
|
|
4
|
+
|
|
5
|
+
type FieldType = "text" | "email" | "phone" | "url" | "address" | "textarea" | "select" | "checkbox" | "radio" | "number" | "date" | "datetime" | "hidden" | "sensitive" | "file";
|
|
6
|
+
type TextTransform = "capitalize-sentences" | "capitalize-words" | "phone-number" | "ssn";
|
|
7
|
+
interface ValidationRule {
|
|
8
|
+
type: "required" | "min" | "max" | "minLength" | "maxLength" | "pattern" | "email" | "phone" | "notEquals";
|
|
9
|
+
value?: string | number | boolean;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
interface FieldOption {
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
type FieldWidth = "full" | "half" | "third";
|
|
17
|
+
interface DatetimeConfig {
|
|
18
|
+
showTimeSelect?: boolean;
|
|
19
|
+
timeIntervals?: number;
|
|
20
|
+
minTime?: string;
|
|
21
|
+
maxTime?: string;
|
|
22
|
+
excludeWeekends?: boolean;
|
|
23
|
+
excludePastDates?: boolean;
|
|
24
|
+
/** Block selecting today — for forms needing at least a day of lead time. */
|
|
25
|
+
excludeToday?: boolean;
|
|
26
|
+
/** Block selecting tomorrow. */
|
|
27
|
+
excludeTomorrow?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Block selecting the next business day relative to today (the first
|
|
30
|
+
* non-weekend day after today — on a Friday or Saturday that's Monday).
|
|
31
|
+
*/
|
|
32
|
+
excludeNextBusinessDay?: boolean;
|
|
33
|
+
filterPastTimes?: boolean;
|
|
34
|
+
dateFormat?: string;
|
|
35
|
+
placeholderText?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Comparison applied by a {@link FieldVisibilityCondition}. `greater-than` /
|
|
39
|
+
* `less-than` compare numerically (both sides parsed as numbers; the
|
|
40
|
+
* condition is unmet when either side isn't numeric).
|
|
41
|
+
*/
|
|
42
|
+
type VisibilityOperator = "equals" | "not-equals" | "greater-than" | "less-than";
|
|
43
|
+
interface FieldVisibilityCondition {
|
|
44
|
+
fieldId: string;
|
|
45
|
+
value: string | boolean;
|
|
46
|
+
/** Defaults to "equals" (the only behavior before operators existed). */
|
|
47
|
+
operator?: VisibilityOperator;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Per-field configuration for the `sensitive` field type. Sensitive fields
|
|
51
|
+
* are encrypted client-side before submission, re-encrypted by the server
|
|
52
|
+
* with a KMS-managed key, and stored in an isolated `sensitive_data`
|
|
53
|
+
* collection. The TTL controls automatic deletion; viewerRoles gates which
|
|
54
|
+
* authenticated users can call the decrypt Cloud Function to reveal the
|
|
55
|
+
* value.
|
|
56
|
+
*/
|
|
57
|
+
interface SensitiveFieldConfig {
|
|
58
|
+
/** Days until the encrypted record auto-deletes. Defaults to 30. */
|
|
59
|
+
ttlDays: 30 | 60 | 90;
|
|
60
|
+
/**
|
|
61
|
+
* Roles allowed to invoke the decrypt Cloud Function. The Cloud Function
|
|
62
|
+
* re-checks against the caller's user document; this list is also used to
|
|
63
|
+
* gate the Reveal button in the CMS UI.
|
|
64
|
+
*/
|
|
65
|
+
viewerRoles: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Optional input mask pattern. Currently only `ssn` is implemented
|
|
68
|
+
* (formats input as XXX-XX-XXXX, validates 9 digits). When omitted, the
|
|
69
|
+
* field accepts free-form text. The form builder keeps this in lockstep
|
|
70
|
+
* with the field-level `ssn` TextTransform — both drive the same
|
|
71
|
+
* formatter, and the renderer honors either.
|
|
72
|
+
*/
|
|
73
|
+
inputMask?: "ssn";
|
|
74
|
+
}
|
|
75
|
+
declare const DEFAULT_SENSITIVE_FIELD_CONFIG: SensitiveFieldConfig;
|
|
76
|
+
/**
|
|
77
|
+
* Configuration for the `file` field type. Files are uploaded to
|
|
78
|
+
* Firebase Storage client-side; the form submission receives the
|
|
79
|
+
* download URL(s) rather than raw file data.
|
|
80
|
+
*/
|
|
81
|
+
interface FileFieldConfig {
|
|
82
|
+
/** Accepted MIME types. Default: "image/*" */
|
|
83
|
+
accept?: string;
|
|
84
|
+
/** Max file size in bytes. Default: 10MB (10485760). */
|
|
85
|
+
maxSizeBytes?: number;
|
|
86
|
+
/** Allow multiple files. Default: false. */
|
|
87
|
+
multiple?: boolean;
|
|
88
|
+
/** Max number of files when multiple=true. Default: 5. */
|
|
89
|
+
maxFiles?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Resize images before upload. Default: true.
|
|
92
|
+
* When true, images are scaled to maxImageWidth and compressed.
|
|
93
|
+
*/
|
|
94
|
+
resizeImages?: boolean;
|
|
95
|
+
/** Max image width for resize. Default: 1600. */
|
|
96
|
+
maxImageWidth?: number;
|
|
97
|
+
}
|
|
98
|
+
declare const DEFAULT_FILE_FIELD_CONFIG: FileFieldConfig;
|
|
99
|
+
interface FormFieldDefinition {
|
|
100
|
+
id: string;
|
|
101
|
+
type: FieldType;
|
|
102
|
+
label: string;
|
|
103
|
+
placeholder?: string;
|
|
104
|
+
helpText?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
defaultValue?: string;
|
|
107
|
+
transform?: TextTransform;
|
|
108
|
+
validation: ValidationRule[];
|
|
109
|
+
options?: FieldOption[];
|
|
110
|
+
layout?: {
|
|
111
|
+
width: FieldWidth;
|
|
112
|
+
order: number;
|
|
113
|
+
};
|
|
114
|
+
characterCounter?: boolean;
|
|
115
|
+
rows?: number;
|
|
116
|
+
datetimeConfig?: DatetimeConfig;
|
|
117
|
+
showWhen?: FieldVisibilityCondition;
|
|
118
|
+
/** Required when `type === "sensitive"`. Ignored for other field types. */
|
|
119
|
+
sensitiveConfig?: SensitiveFieldConfig;
|
|
120
|
+
/** Configuration for `type === "file"`. */
|
|
121
|
+
fileConfig?: FileFieldConfig;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* "Same as another section" mirroring. A later section can copy values from
|
|
125
|
+
* an earlier one (e.g. billing address = home address) behind a checkbox.
|
|
126
|
+
*/
|
|
127
|
+
interface SectionSameAsConfig {
|
|
128
|
+
/** Section whose values are copied in. MUST have a lower `order`. */
|
|
129
|
+
sourceSectionId: string;
|
|
130
|
+
/** targetFieldId (in THIS section) -> sourceFieldId (in the source section). */
|
|
131
|
+
fieldMap: Record<string, string>;
|
|
132
|
+
/** Checkbox label, e.g. "Billing same as home address". */
|
|
133
|
+
toggleLabel: string;
|
|
134
|
+
/** Hide the target fields while mirrored, or show them locked (read-only). */
|
|
135
|
+
behavior: "hide" | "lock";
|
|
136
|
+
}
|
|
137
|
+
interface FormSection {
|
|
138
|
+
id: string;
|
|
139
|
+
title?: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
fields: FormFieldDefinition[];
|
|
142
|
+
order: number;
|
|
143
|
+
/**
|
|
144
|
+
* Optional hex color (e.g. "#ffffff") applied as inline color to the
|
|
145
|
+
* section's title and description. When unset, the section inherits its
|
|
146
|
+
* color from the form-level `defaultTextColor` or, if that's also unset,
|
|
147
|
+
* from the surrounding CSS cascade.
|
|
148
|
+
*/
|
|
149
|
+
textColor?: string;
|
|
150
|
+
/** When set, this section mirrors fields from an earlier section. */
|
|
151
|
+
sameAs?: SectionSameAsConfig;
|
|
152
|
+
}
|
|
153
|
+
type FormSuccessBehavior = "message" | "replace" | "reset" | "disable";
|
|
154
|
+
interface FormSpamProtectionConfig {
|
|
155
|
+
/** Adds an invisible honeypot field that catches bots. Defaults to true. */
|
|
156
|
+
honeypot?: boolean;
|
|
157
|
+
/** Minimum seconds between mount and submit. Set to 0 to disable. Defaults to 3. */
|
|
158
|
+
minSubmitTime?: number;
|
|
159
|
+
}
|
|
160
|
+
interface FormSubmitConfig {
|
|
161
|
+
buttonText: string;
|
|
162
|
+
submittingText?: string;
|
|
163
|
+
successMessage: string;
|
|
164
|
+
errorMessage: string;
|
|
165
|
+
successBehavior?: FormSuccessBehavior;
|
|
166
|
+
/**
|
|
167
|
+
* When set, the browser navigates here after a successful submission
|
|
168
|
+
* instead of staying on the page — typically a dedicated thank-you page
|
|
169
|
+
* used for Google Ads conversion tracking. Must be an absolute http(s)
|
|
170
|
+
* URL or a site-relative path (`/thank-you`); see `getSafeRedirectUrl`.
|
|
171
|
+
* Takes precedence over `successBehavior` on real (non-spam) submits.
|
|
172
|
+
*/
|
|
173
|
+
redirectUrl?: string;
|
|
174
|
+
spamProtection?: FormSpamProtectionConfig;
|
|
175
|
+
}
|
|
176
|
+
/** Field name used for the honeypot. Bots tend to fill anything called "website". */
|
|
177
|
+
declare const HONEYPOT_FIELD_NAME = "_hp_website";
|
|
178
|
+
/** Reserved Formik key for a section's synthetic "same as" toggle. Stripped before submit. */
|
|
179
|
+
declare const SAME_AS_TOGGLE_PREFIX = "_sameAs_";
|
|
180
|
+
declare const sameAsToggleKey: (sectionId: string) => string;
|
|
181
|
+
/** Default spam-protection settings (opt-out). */
|
|
182
|
+
declare const DEFAULT_SPAM_PROTECTION: Required<FormSpamProtectionConfig>;
|
|
183
|
+
type FormStylePreset = "default" | "minimal" | "bordered" | "shadow" | "card" | "dark";
|
|
184
|
+
type InputVariant = "outlined" | "filled" | "underlined" | "stacked";
|
|
185
|
+
/**
|
|
186
|
+
* Theme overrides for a form. Every color is OPTIONAL — when unset, the
|
|
187
|
+
* renderer falls back to a baked-in default via CSS `var()` fallbacks. This
|
|
188
|
+
* lets the form builder ship forms that adapt to any consumer site
|
|
189
|
+
* (CastleRents' warm tan, EuroComp's dark, etc.) without the package forcing
|
|
190
|
+
* its own surface color or text color when the user hasn't picked one.
|
|
191
|
+
*
|
|
192
|
+
* The non-color fields (`preset`, `borderRadius`, `spacing`, variants,
|
|
193
|
+
* `sectionDividers`) remain required structural choices and DEFAULT_FORM_STYLE
|
|
194
|
+
* supplies their defaults.
|
|
195
|
+
*/
|
|
196
|
+
interface FormStyle {
|
|
197
|
+
preset: FormStylePreset;
|
|
198
|
+
borderRadius: "none" | "sm" | "md" | "lg" | "full";
|
|
199
|
+
spacing: "compact" | "normal" | "relaxed";
|
|
200
|
+
buttonVariant: "filled" | "outline" | "ghost";
|
|
201
|
+
/**
|
|
202
|
+
* Where the submit button renders. "below" (default) spans the full form
|
|
203
|
+
* width under the fields; "inline" places it in a row beside the fields —
|
|
204
|
+
* suited to single-field forms like a newsletter email + Join button.
|
|
205
|
+
*/
|
|
206
|
+
buttonPlacement?: "below" | "inline";
|
|
207
|
+
sectionDividers: boolean;
|
|
208
|
+
inputVariant: InputVariant;
|
|
209
|
+
/** Form container background. Default: transparent (inherits from the page). */
|
|
210
|
+
formBackgroundColor?: string;
|
|
211
|
+
/** Input fill color (used by filled/stacked variants and the floating-label mask). Default: #ffffff. */
|
|
212
|
+
inputBgColor?: string;
|
|
213
|
+
/** Input border color (idle state). Default: #d1d5db. */
|
|
214
|
+
inputBorderColor?: string;
|
|
215
|
+
/** Input border color on focus. Default: #2563eb. */
|
|
216
|
+
inputFocusColor?: string;
|
|
217
|
+
/** Color of the text typed into inputs. Default: inherit from the page. */
|
|
218
|
+
inputTextColor?: string;
|
|
219
|
+
/** Placeholder text color. Default: #9ca3af. */
|
|
220
|
+
placeholderColor?: string;
|
|
221
|
+
/** Field label text color. Default: inherit from the page. */
|
|
222
|
+
labelColor?: string;
|
|
223
|
+
/** Color used for error text + error border outline. Default: #ef4444. */
|
|
224
|
+
errorColor?: string;
|
|
225
|
+
/** Submit button background (filled variant) / border + text (outline / ghost). Default: #2563eb. */
|
|
226
|
+
buttonColor?: string;
|
|
227
|
+
/** Submit button text color (filled variant only — outline/ghost use buttonColor). Default: #ffffff. */
|
|
228
|
+
buttonTextColor?: string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Structural defaults only. Colors are intentionally absent — they resolve
|
|
232
|
+
* via the renderer's CSS var fallbacks (see `cssVars.ts`) when the form
|
|
233
|
+
* definition doesn't override them.
|
|
234
|
+
*/
|
|
235
|
+
declare const DEFAULT_FORM_STYLE: FormStyle;
|
|
236
|
+
type FieldTransform = "full" | "extractFirstName" | "extractLastName" | "extractStreet" | "extractCity" | "extractState" | "extractZip";
|
|
237
|
+
interface IntegrationFieldMappingEntry {
|
|
238
|
+
/** Form field ID to read the value from */
|
|
239
|
+
field: string;
|
|
240
|
+
/** Optional transform applied to the source value before mapping */
|
|
241
|
+
transform?: FieldTransform;
|
|
242
|
+
}
|
|
243
|
+
interface FormIntegrationConfig {
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
/** Map of integration destination key (e.g. "customer.firstName") → source mapping */
|
|
246
|
+
fieldMapping: Record<string, IntegrationFieldMappingEntry>;
|
|
247
|
+
}
|
|
248
|
+
type FormIntegrations = Record<string, FormIntegrationConfig>;
|
|
249
|
+
type FormStatus = "draft" | "published" | "archived";
|
|
250
|
+
/**
|
|
251
|
+
* Where the CMS routes a submission for this form.
|
|
252
|
+
*
|
|
253
|
+
* - `contact` (default): writes to the project's `contact-forms` subcollection
|
|
254
|
+
* and surfaces in the Contacts dashboard.
|
|
255
|
+
* - `application`: writes to the project's `applications` subcollection with
|
|
256
|
+
* workflow state (`status`, `assignedTo`, notes, statusHistory) and
|
|
257
|
+
* surfaces in the Applications dashboard.
|
|
258
|
+
* - `newsletter`: writes to the project's `newsletter_subscribers` collection.
|
|
259
|
+
* Newsletter forms are restricted to `email` (required) and `checkbox`
|
|
260
|
+
* (optional, for preferences/consent) fields. Duplicate emails within a
|
|
261
|
+
* project update the existing record's preferences rather than creating
|
|
262
|
+
* a new entry.
|
|
263
|
+
*
|
|
264
|
+
* Only the routing changes — spam protection, sensitive field handling,
|
|
265
|
+
* notification emails, and integrations behave identically.
|
|
266
|
+
*/
|
|
267
|
+
type FormSubmissionType = "contact" | "application" | "newsletter";
|
|
268
|
+
/**
|
|
269
|
+
* Field types allowed on a newsletter form. Enforced by the form builder UI
|
|
270
|
+
* and (defensively) by the submission route. Keep in sync with
|
|
271
|
+
* `FormSubmissionType === "newsletter"` handling.
|
|
272
|
+
*/
|
|
273
|
+
declare const NEWSLETTER_ALLOWED_FIELD_TYPES: FieldType[];
|
|
274
|
+
/**
|
|
275
|
+
* Customizable notification email sent to project members when a submission
|
|
276
|
+
* arrives. Both `subject` and `html` support `{{variable}}` interpolation —
|
|
277
|
+
* see `renderEmailTemplate` for the rules. When omitted, the API falls back
|
|
278
|
+
* to the built-in default template.
|
|
279
|
+
*/
|
|
280
|
+
interface NotificationEmailTemplate {
|
|
281
|
+
subject: string;
|
|
282
|
+
html: string;
|
|
283
|
+
}
|
|
284
|
+
declare const DEFAULT_NOTIFICATION_EMAIL_SUBJECT = "New Contact Form: {{name}}";
|
|
285
|
+
/**
|
|
286
|
+
* Default HTML body for the notification email. Mirrors the look of
|
|
287
|
+
* `buildContactNotificationEmail` in the CMS but uses `{{variable}}`
|
|
288
|
+
* placeholders so users can edit it in the form builder.
|
|
289
|
+
*/
|
|
290
|
+
declare const DEFAULT_NOTIFICATION_EMAIL_HTML = "<!DOCTYPE html>\n<html lang=\"en\">\n<head><meta charset=\"UTF-8\" /></head>\n<body style=\"font-family: sans-serif; color: #333; max-width: 600px; margin: 0 auto;\">\n <div style=\"background: #4f46e5; color: white; padding: 20px; border-radius: 8px 8px 0 0;\">\n <h1 style=\"margin: 0; font-size: 20px;\">New {{formName}} Submission</h1>\n <p style=\"margin: 4px 0 0; opacity: 0.9; font-size: 14px;\">{{projectName}}</p>\n </div>\n <div style=\"border: 1px solid #e5e7eb; border-top: none; padding: 20px; border-radius: 0 0 8px 8px;\">\n <table style=\"width: 100%; border-collapse: collapse;\">\n <tr>\n <td style=\"padding: 8px 0; font-weight: 600; width: 120px; vertical-align: top;\">Name:</td>\n <td style=\"padding: 8px 0;\">{{name}}</td>\n </tr>\n <tr>\n <td style=\"padding: 8px 0; font-weight: 600; vertical-align: top;\">Email:</td>\n <td style=\"padding: 8px 0;\"><a href=\"mailto:{{email}}\">{{email}}</a></td>\n </tr>\n <tr>\n <td style=\"padding: 8px 0; font-weight: 600; vertical-align: top;\">Phone:</td>\n <td style=\"padding: 8px 0;\"><a href=\"tel:{{phone}}\">{{phone}}</a></td>\n </tr>\n <tr>\n <td style=\"padding: 8px 0; font-weight: 600; vertical-align: top;\">Message:</td>\n <td style=\"padding: 8px 0;\">{{message}}</td>\n </tr>\n </table>\n <hr style=\"border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;\" />\n <p style=\"font-size: 12px; color: #9ca3af; margin: 0;\">\n Sent via VulcanTech CMS · <a href=\"https://cms.vulcantech.io\">Dashboard</a>\n </p>\n </div>\n</body>\n</html>";
|
|
291
|
+
declare const DEFAULT_NOTIFICATION_EMAIL_TEMPLATE: NotificationEmailTemplate;
|
|
292
|
+
/**
|
|
293
|
+
* The set of workflow states an application can be in. Mirrors
|
|
294
|
+
* `ApplicationStatus` in apps/vulcantech-cms/src/types/APPLICATION.ts — duplicated
|
|
295
|
+
* here so the forms package (which is consumed by both the CMS server and
|
|
296
|
+
* client apps) can describe per-status email templates without importing
|
|
297
|
+
* from the CMS app.
|
|
298
|
+
*/
|
|
299
|
+
type ApplicationStatusKey = "received" | "reviewing" | "approved" | "denied" | "pending-documents" | "withdrawn";
|
|
300
|
+
declare const APPLICATION_STATUS_KEYS: ApplicationStatusKey[];
|
|
301
|
+
/**
|
|
302
|
+
* Per-status applicant-facing email template. Keyed by `ApplicationStatusKey`.
|
|
303
|
+
* Missing entries fall back to {@link DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES}.
|
|
304
|
+
*
|
|
305
|
+
* These templates are RENDERED with the same `renderEmailTemplate` engine as
|
|
306
|
+
* the admin notification template, but the available variables are
|
|
307
|
+
* application-centric: `{{referenceNumber}}`, `{{applicantName}}`,
|
|
308
|
+
* `{{status}}`, `{{requestedDocuments}}` (only when status is
|
|
309
|
+
* `pending-documents`), plus any form-field values that match the
|
|
310
|
+
* applicant's submission.
|
|
311
|
+
*/
|
|
312
|
+
type ApplicationStatusEmailTemplates = Partial<Record<ApplicationStatusKey, NotificationEmailTemplate>>;
|
|
313
|
+
declare const DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES: Record<ApplicationStatusKey, NotificationEmailTemplate>;
|
|
314
|
+
interface FormDefinition {
|
|
315
|
+
id: string;
|
|
316
|
+
/**
|
|
317
|
+
* Server-only project owner. The CMS stores this in Firestore and uses it
|
|
318
|
+
* internally (to scope writes, build cache tags, address integration
|
|
319
|
+
* configs), but it is stripped from every client-facing response by
|
|
320
|
+
* `stripSensitiveFields` before reaching consumer apps. Client code MUST
|
|
321
|
+
* NOT depend on this field — resolve projectId from a server-side env var
|
|
322
|
+
* (`VULCANTECH_PROJECT_ID`) in proxy/fetch routes instead.
|
|
323
|
+
*/
|
|
324
|
+
projectId?: string;
|
|
325
|
+
name: string;
|
|
326
|
+
slug: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
version: number;
|
|
329
|
+
status: string;
|
|
330
|
+
/**
|
|
331
|
+
* Routes submissions to the matching dashboard collection.
|
|
332
|
+
* Defaults to `"contact"` when omitted. See {@link FormSubmissionType}.
|
|
333
|
+
*/
|
|
334
|
+
submissionType?: FormSubmissionType;
|
|
335
|
+
sections: FormSection[];
|
|
336
|
+
submitConfig: FormSubmitConfig;
|
|
337
|
+
style?: FormStyle;
|
|
338
|
+
/**
|
|
339
|
+
* Optional hex color applied as the default text color for every section
|
|
340
|
+
* header and description. Per-section `textColor` overrides this. When
|
|
341
|
+
* unset, sections inherit from the surrounding CSS cascade (useful when
|
|
342
|
+
* the form is embedded on a page with its own typography).
|
|
343
|
+
*/
|
|
344
|
+
defaultTextColor?: string;
|
|
345
|
+
metadata?: {
|
|
346
|
+
trackAdReferral?: boolean;
|
|
347
|
+
customFields?: Record<string, unknown>;
|
|
348
|
+
};
|
|
349
|
+
integrations?: FormIntegrations;
|
|
350
|
+
/**
|
|
351
|
+
* Customizable email sent to project members when a submission arrives.
|
|
352
|
+
* Falls back to `DEFAULT_NOTIFICATION_EMAIL_TEMPLATE` when undefined.
|
|
353
|
+
*/
|
|
354
|
+
notificationEmailTemplate?: NotificationEmailTemplate;
|
|
355
|
+
/**
|
|
356
|
+
* Per-status applicant-facing email templates. Only consulted when
|
|
357
|
+
* `submissionType === "application"`. Missing entries fall back to
|
|
358
|
+
* `DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES[status]`. Set to an empty
|
|
359
|
+
* object to opt every status into the defaults explicitly.
|
|
360
|
+
*/
|
|
361
|
+
applicationStatusEmails?: ApplicationStatusEmailTemplates;
|
|
362
|
+
createdAt: string;
|
|
363
|
+
updatedAt: string;
|
|
364
|
+
createdBy: string;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* JSON-friendly mirror of {@link FormDefinition}.
|
|
368
|
+
*
|
|
369
|
+
* `FormDefinition` keeps narrow string-literal unions (e.g. `FieldType`,
|
|
370
|
+
* `FormStylePreset`, `FormSuccessBehavior`) for editor autocomplete and
|
|
371
|
+
* exhaustive-switch safety inside this package. But when a definition
|
|
372
|
+
* crosses a JSON boundary — `JSON.parse`, an `await res.json()` on an ISR
|
|
373
|
+
* fetch, a Firestore document, or a literal object pasted into source —
|
|
374
|
+
* TypeScript widens the string values to `string`, which fails to match
|
|
375
|
+
* the narrow unions and forces every consumer to cast.
|
|
376
|
+
*
|
|
377
|
+
* Use `FormDefinitionJSON` as the type of the raw JSON value, then call
|
|
378
|
+
* {@link parseFormDefinition} (or assert it yourself) when you need the
|
|
379
|
+
* strict shape:
|
|
380
|
+
*
|
|
381
|
+
* ```ts
|
|
382
|
+
* const json = (await res.json()) as FormDefinitionJSON;
|
|
383
|
+
* const definition = parseFormDefinition(json);
|
|
384
|
+
* ```
|
|
385
|
+
*
|
|
386
|
+
* Structurally, `FormDefinition` is assignable to `FormDefinitionJSON`,
|
|
387
|
+
* so values you've already validated flow back into JSON-typed slots
|
|
388
|
+
* without a cast.
|
|
389
|
+
*/
|
|
390
|
+
interface ValidationRuleJSON {
|
|
391
|
+
type: string;
|
|
392
|
+
value?: string | number | boolean;
|
|
393
|
+
message: string;
|
|
394
|
+
}
|
|
395
|
+
interface SensitiveFieldConfigJSON {
|
|
396
|
+
/** Days until the encrypted record auto-deletes. Defaults to 30. */
|
|
397
|
+
ttlDays: number;
|
|
398
|
+
viewerRoles: string[];
|
|
399
|
+
/** Currently only `ssn` is implemented. */
|
|
400
|
+
inputMask?: string;
|
|
401
|
+
}
|
|
402
|
+
interface FormFieldDefinitionJSON {
|
|
403
|
+
id: string;
|
|
404
|
+
type: string;
|
|
405
|
+
label: string;
|
|
406
|
+
placeholder?: string;
|
|
407
|
+
helpText?: string;
|
|
408
|
+
description?: string;
|
|
409
|
+
defaultValue?: string;
|
|
410
|
+
transform?: string;
|
|
411
|
+
validation: ValidationRuleJSON[];
|
|
412
|
+
options?: FieldOption[];
|
|
413
|
+
layout?: {
|
|
414
|
+
width: string;
|
|
415
|
+
order: number;
|
|
416
|
+
};
|
|
417
|
+
characterCounter?: boolean;
|
|
418
|
+
rows?: number;
|
|
419
|
+
datetimeConfig?: DatetimeConfig;
|
|
420
|
+
showWhen?: FieldVisibilityCondition;
|
|
421
|
+
sensitiveConfig?: SensitiveFieldConfigJSON;
|
|
422
|
+
}
|
|
423
|
+
interface FormSectionJSON {
|
|
424
|
+
id: string;
|
|
425
|
+
title?: string;
|
|
426
|
+
description?: string;
|
|
427
|
+
fields: FormFieldDefinitionJSON[];
|
|
428
|
+
order: number;
|
|
429
|
+
textColor?: string;
|
|
430
|
+
sameAs?: SectionSameAsConfig;
|
|
431
|
+
}
|
|
432
|
+
interface FormStyleJSON {
|
|
433
|
+
preset: string;
|
|
434
|
+
borderRadius: string;
|
|
435
|
+
spacing: string;
|
|
436
|
+
buttonVariant: string;
|
|
437
|
+
buttonPlacement?: string;
|
|
438
|
+
sectionDividers: boolean;
|
|
439
|
+
inputVariant: string;
|
|
440
|
+
formBackgroundColor?: string;
|
|
441
|
+
inputBgColor?: string;
|
|
442
|
+
inputBorderColor?: string;
|
|
443
|
+
inputFocusColor?: string;
|
|
444
|
+
inputTextColor?: string;
|
|
445
|
+
placeholderColor?: string;
|
|
446
|
+
labelColor?: string;
|
|
447
|
+
errorColor?: string;
|
|
448
|
+
buttonColor?: string;
|
|
449
|
+
buttonTextColor?: string;
|
|
450
|
+
}
|
|
451
|
+
interface FormSubmitConfigJSON {
|
|
452
|
+
buttonText: string;
|
|
453
|
+
submittingText?: string;
|
|
454
|
+
successMessage: string;
|
|
455
|
+
errorMessage: string;
|
|
456
|
+
successBehavior?: string;
|
|
457
|
+
redirectUrl?: string;
|
|
458
|
+
spamProtection?: FormSpamProtectionConfig;
|
|
459
|
+
}
|
|
460
|
+
interface IntegrationFieldMappingEntryJSON {
|
|
461
|
+
field: string;
|
|
462
|
+
transform?: string;
|
|
463
|
+
}
|
|
464
|
+
interface FormIntegrationConfigJSON {
|
|
465
|
+
enabled: boolean;
|
|
466
|
+
fieldMapping: Record<string, IntegrationFieldMappingEntryJSON>;
|
|
467
|
+
}
|
|
468
|
+
type FormIntegrationsJSON = Record<string, FormIntegrationConfigJSON>;
|
|
469
|
+
interface FormDefinitionJSON {
|
|
470
|
+
id: string;
|
|
471
|
+
/** See {@link FormDefinition.projectId} — server-only, optional at the JSON boundary. */
|
|
472
|
+
projectId?: string;
|
|
473
|
+
name: string;
|
|
474
|
+
slug: string;
|
|
475
|
+
description?: string;
|
|
476
|
+
version: number;
|
|
477
|
+
status: string;
|
|
478
|
+
submissionType?: string;
|
|
479
|
+
sections: FormSectionJSON[];
|
|
480
|
+
submitConfig: FormSubmitConfigJSON;
|
|
481
|
+
style?: FormStyleJSON;
|
|
482
|
+
defaultTextColor?: string;
|
|
483
|
+
metadata?: {
|
|
484
|
+
trackAdReferral?: boolean;
|
|
485
|
+
customFields?: Record<string, unknown>;
|
|
486
|
+
};
|
|
487
|
+
integrations?: FormIntegrationsJSON;
|
|
488
|
+
notificationEmailTemplate?: NotificationEmailTemplate;
|
|
489
|
+
/** See {@link FormDefinition.applicationStatusEmails}. */
|
|
490
|
+
applicationStatusEmails?: ApplicationStatusEmailTemplates;
|
|
491
|
+
createdAt: string;
|
|
492
|
+
updatedAt: string;
|
|
493
|
+
createdBy: string;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Narrow a `FormDefinitionJSON` to the strict {@link FormDefinition} type.
|
|
497
|
+
*
|
|
498
|
+
* This is a structural cast — it trusts that the JSON was produced by the
|
|
499
|
+
* CMS (or another well-formed source) and does not validate individual
|
|
500
|
+
* enum values. Use it at trust boundaries where you've already verified
|
|
501
|
+
* the source. For untrusted JSON, validate explicitly (e.g. with Yup or
|
|
502
|
+
* Zod) before treating the result as a `FormDefinition`.
|
|
503
|
+
*/
|
|
504
|
+
declare function parseFormDefinition(json: FormDefinitionJSON): FormDefinition;
|
|
505
|
+
|
|
506
|
+
declare function buildYupSchema(definition: FormDefinition): Yup.ObjectSchema<Record<string, unknown>>;
|
|
507
|
+
|
|
508
|
+
declare function buildInitialValues(definition: FormDefinition): Record<string, string | boolean | string[]>;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Evaluate a field's `showWhen` condition against the current form values.
|
|
512
|
+
*
|
|
513
|
+
* This is the single source of truth for conditional visibility — the
|
|
514
|
+
* renderer (show/hide), the Yup schema (skip validation while hidden), the
|
|
515
|
+
* submit payload (strip hidden values), and the CMS's server-side submission
|
|
516
|
+
* validation must all agree, so they all call this.
|
|
517
|
+
*
|
|
518
|
+
* Operators:
|
|
519
|
+
* - `equals` (default) / `not-equals`: strict comparison, matching the
|
|
520
|
+
* original behavior.
|
|
521
|
+
* - `greater-than` / `less-than`: numeric comparison. Both the watched value
|
|
522
|
+
* and the condition value are parsed as numbers; if either side isn't
|
|
523
|
+
* numeric (empty input, non-number text, booleans), the condition is unmet
|
|
524
|
+
* and the dependent field stays hidden.
|
|
525
|
+
*
|
|
526
|
+
* @param condition - The field's `showWhen` config.
|
|
527
|
+
* @param watchedValue - Current value of `condition.fieldId`.
|
|
528
|
+
* @returns True when the dependent field should be visible.
|
|
529
|
+
*/
|
|
530
|
+
declare function isVisibilityConditionMet(condition: FieldVisibilityCondition, watchedValue: unknown): boolean;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Apply a field transform to a string value before passing it to an
|
|
534
|
+
* integration. Used by integration adapters to derive things like
|
|
535
|
+
* "first name" from a single "Full Name" field, or to split an address
|
|
536
|
+
* into its components.
|
|
537
|
+
*
|
|
538
|
+
* @param value - The raw form field value.
|
|
539
|
+
* @param transform - The transform to apply. Falsy or "full" returns the
|
|
540
|
+
* value unchanged.
|
|
541
|
+
* @returns The transformed value, or an empty string if the transform
|
|
542
|
+
* could not produce a result.
|
|
543
|
+
*/
|
|
544
|
+
declare function applyTransform(value: string, transform?: FieldTransform): string;
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Validate a configured post-submit redirect target.
|
|
548
|
+
*
|
|
549
|
+
* Accepts absolute http(s) URLs and site-relative paths (`/thank-you`).
|
|
550
|
+
* Anything else — `javascript:`/`data:` schemes, protocol-relative
|
|
551
|
+
* `//host` values, unparseable strings — returns `null` so the caller
|
|
552
|
+
* falls back to the normal on-page success behavior. Shared by the
|
|
553
|
+
* renderer (before navigating) and the CMS save endpoint (before
|
|
554
|
+
* persisting) so both enforce the same rule.
|
|
555
|
+
*
|
|
556
|
+
* @param raw - The `submitConfig.redirectUrl` value as authored/stored.
|
|
557
|
+
* @returns The trimmed URL when it is safe to navigate to, otherwise `null`.
|
|
558
|
+
*/
|
|
559
|
+
declare function getSafeRedirectUrl(raw: string | null | undefined): string | null;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Formats raw digits as a US Social Security number (NNN-NN-NNNN).
|
|
563
|
+
* Truncates anything past 9 digits.
|
|
564
|
+
*/
|
|
565
|
+
declare function formatSsn(raw: string): string;
|
|
566
|
+
/**
|
|
567
|
+
* Formats raw digits as a US phone number: (555) 123 - 4567.
|
|
568
|
+
* Strips a leading "1" country code from 11-digit pastes like
|
|
569
|
+
* "+1 (555) 123-4567" and truncates anything past 10 digits so
|
|
570
|
+
* oversized values don't dead-end the input.
|
|
571
|
+
*/
|
|
572
|
+
declare function formatUsPhone(raw: string): string;
|
|
573
|
+
/**
|
|
574
|
+
* Apply a `TextTransform` to a field value as the user types. Shared by the
|
|
575
|
+
* free-text field renderers so every field type honors the transform picked
|
|
576
|
+
* in the builder, and so the `ssn` transform and the sensitive `ssn` input
|
|
577
|
+
* mask always produce identical output.
|
|
578
|
+
*
|
|
579
|
+
* @param value - The current input value.
|
|
580
|
+
* @param transform - The transform configured on the field definition.
|
|
581
|
+
* @returns The transformed value; unrecognized or absent transforms return
|
|
582
|
+
* the value unchanged.
|
|
583
|
+
*/
|
|
584
|
+
declare function applyTextTransform(value: string, transform?: TextTransform): string;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Variables available to a notification email template. Beyond the canonical
|
|
588
|
+
* keys here, the renderer also accepts arbitrary form-field IDs / labels
|
|
589
|
+
* looked up from the form definition (see `buildEmailTemplateVariables`).
|
|
590
|
+
*/
|
|
591
|
+
interface EmailTemplateVariables {
|
|
592
|
+
/** Project (site) display name. */
|
|
593
|
+
projectName: string;
|
|
594
|
+
/** Form display name (e.g. "Contact Form"). */
|
|
595
|
+
formName: string;
|
|
596
|
+
/** Submission timestamp as an ISO string. */
|
|
597
|
+
submittedAt: string;
|
|
598
|
+
/** Anything else the form sends — keyed by field id, label-slug, or canonical key. */
|
|
599
|
+
[key: string]: string | number | boolean | undefined;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Replace `{{key}}` placeholders in `template` with values from `variables`.
|
|
603
|
+
* Unknown keys are replaced with an empty string. Whitespace inside the
|
|
604
|
+
* braces is tolerated (`{{ name }}` works the same as `{{name}}`). Values
|
|
605
|
+
* are HTML-escaped by default; pass `{ escape: false }` to interpolate into
|
|
606
|
+
* non-HTML targets like the email subject line.
|
|
607
|
+
*/
|
|
608
|
+
declare function renderEmailTemplate(template: string, variables: EmailTemplateVariables, options?: {
|
|
609
|
+
escape?: boolean;
|
|
610
|
+
}): string;
|
|
611
|
+
/**
|
|
612
|
+
* Build the variable bag handed to `renderEmailTemplate` from a form
|
|
613
|
+
* definition + raw submission payload. Each form field is exposed under its
|
|
614
|
+
* `id` and (when distinct) under a slugified version of its `label`, so
|
|
615
|
+
* authors can reference fields with either `{{customer_name_1234}}` or
|
|
616
|
+
* `{{customer_name}}`.
|
|
617
|
+
*/
|
|
618
|
+
declare function buildEmailTemplateVariables(args: {
|
|
619
|
+
definition?: Pick<FormDefinition, "name" | "sections">;
|
|
620
|
+
projectName: string;
|
|
621
|
+
formName?: string;
|
|
622
|
+
submission: Record<string, unknown>;
|
|
623
|
+
submittedAt?: string;
|
|
624
|
+
}): EmailTemplateVariables;
|
|
625
|
+
/**
|
|
626
|
+
* Variable descriptor used by the dashboard editor to render the "Insert
|
|
627
|
+
* variable" picker. Order is informational; renderers don't depend on it.
|
|
628
|
+
*/
|
|
629
|
+
interface EmailTemplateVariableDescriptor {
|
|
630
|
+
key: string;
|
|
631
|
+
description: string;
|
|
632
|
+
example: string;
|
|
633
|
+
}
|
|
634
|
+
declare const CORE_EMAIL_TEMPLATE_VARIABLES: EmailTemplateVariableDescriptor[];
|
|
635
|
+
/**
|
|
636
|
+
* Sample submission used to populate the editor's preview pane. Mirrors the
|
|
637
|
+
* canonical keys most contact forms collect.
|
|
638
|
+
*/
|
|
639
|
+
declare const SAMPLE_EMAIL_TEMPLATE_VARIABLES: EmailTemplateVariables;
|
|
640
|
+
/** Convenience: render both subject + body of a template in one pass. */
|
|
641
|
+
declare function renderNotificationEmail(template: NotificationEmailTemplate, variables: EmailTemplateVariables): {
|
|
642
|
+
subject: string;
|
|
643
|
+
html: string;
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Client-side encryption utilities for sensitive form fields.
|
|
648
|
+
*
|
|
649
|
+
* Hybrid encryption scheme:
|
|
650
|
+
* 1. The browser fetches a transport public key (RSA-OAEP, 2048-bit) from
|
|
651
|
+
* the server. The matching private key never leaves the server.
|
|
652
|
+
* 2. For each sensitive field we generate a fresh AES-GCM-256 data key,
|
|
653
|
+
* encrypt the plaintext with it, then wrap the data key with the RSA
|
|
654
|
+
* public key. Both ciphertexts plus the IV travel to the server.
|
|
655
|
+
* 3. The server unwraps the data key with its private key, decrypts the
|
|
656
|
+
* plaintext, then re-encrypts with Google Cloud KMS for storage.
|
|
657
|
+
*
|
|
658
|
+
* The plaintext SSN (or other sensitive value) therefore never appears on
|
|
659
|
+
* the wire in cleartext beyond TLS — even an attacker with access to the
|
|
660
|
+
* Next.js request body would see only ciphertext.
|
|
661
|
+
*/
|
|
662
|
+
/** Wire-format for an encrypted sensitive field value. */
|
|
663
|
+
interface EncryptedSensitiveValue {
|
|
664
|
+
/** Schema marker. Always "v1". */
|
|
665
|
+
v: "v1";
|
|
666
|
+
/** Identifier of the transport key used (matches server kid). */
|
|
667
|
+
kid: string;
|
|
668
|
+
/** Base64 RSA-OAEP-wrapped AES key. */
|
|
669
|
+
wrappedKey: string;
|
|
670
|
+
/** Base64 AES-GCM IV (12 bytes). */
|
|
671
|
+
iv: string;
|
|
672
|
+
/** Base64 AES-GCM ciphertext + auth tag. */
|
|
673
|
+
ciphertext: string;
|
|
674
|
+
/** Plaintext last-4 digits for display. Safe to store unencrypted. */
|
|
675
|
+
last4: string;
|
|
676
|
+
}
|
|
677
|
+
/** JWK payload returned by the transport-key endpoint. */
|
|
678
|
+
interface TransportPublicKey {
|
|
679
|
+
kid: string;
|
|
680
|
+
jwk: JsonWebKey;
|
|
681
|
+
}
|
|
682
|
+
declare function bufferToBase64(buf: ArrayBuffer): string;
|
|
683
|
+
declare function base64ToBuffer(b64: string): ArrayBuffer;
|
|
684
|
+
/**
|
|
685
|
+
* Encrypt a single plaintext value using the supplied transport public key.
|
|
686
|
+
* Returns the wire-format payload that the server expects.
|
|
687
|
+
*
|
|
688
|
+
* @param plaintext The cleartext value to encrypt (e.g. a Social Security
|
|
689
|
+
* number). Must be a non-empty string.
|
|
690
|
+
* @param publicKey Transport key descriptor previously fetched from the
|
|
691
|
+
* server's transport-key endpoint.
|
|
692
|
+
*/
|
|
693
|
+
declare function encryptSensitiveValue(plaintext: string, publicKey: TransportPublicKey): Promise<EncryptedSensitiveValue>;
|
|
694
|
+
/**
|
|
695
|
+
* Strips formatting (dashes, spaces) and returns the last four digits.
|
|
696
|
+
* Used for the plaintext display marker stored alongside the ciphertext.
|
|
697
|
+
*/
|
|
698
|
+
declare function deriveLast4(plaintext: string): string;
|
|
699
|
+
|
|
700
|
+
interface DynamicFormProps {
|
|
701
|
+
definition: FormDefinition;
|
|
702
|
+
apiRoute: string;
|
|
703
|
+
/**
|
|
704
|
+
* Called after a successful submission. The argument is the parsed JSON
|
|
705
|
+
* response body, when one was returned — application submissions echo
|
|
706
|
+
* `{ success: true, referenceNumber: "APP-…" }` here so the consumer
|
|
707
|
+
* can display it on its confirmation page.
|
|
708
|
+
*/
|
|
709
|
+
onSuccess?: (data?: unknown) => void;
|
|
710
|
+
onError?: (error: Error) => void;
|
|
711
|
+
extraData?: Record<string, unknown>;
|
|
712
|
+
className?: string;
|
|
713
|
+
/**
|
|
714
|
+
* Endpoint that returns the RSA-OAEP transport public key used to wrap the
|
|
715
|
+
* per-submission AES key for sensitive fields. Defaults to
|
|
716
|
+
* `/api/forms/transport-key` (resolved against the same origin).
|
|
717
|
+
*
|
|
718
|
+
* The endpoint must respond with `{ kid: string, jwk: JsonWebKey }`.
|
|
719
|
+
*/
|
|
720
|
+
transportKeyEndpoint?: string;
|
|
721
|
+
/**
|
|
722
|
+
* When set, overrides the form's internal submit state for preview purposes.
|
|
723
|
+
* Network submissions are skipped while a previewState is active.
|
|
724
|
+
*/
|
|
725
|
+
/**
|
|
726
|
+
* Analytics callbacks. When omitted, the form falls back to the
|
|
727
|
+
* `window.__vtTrack` hooks the @vulcantech/analytics tracker
|
|
728
|
+
* registers — so form view/submit conversions track automatically on
|
|
729
|
+
* any site running the tracker, with no per-form wiring.
|
|
730
|
+
*/
|
|
731
|
+
onFormView?: (formId: string, formName: string) => void;
|
|
732
|
+
onFormSubmit?: (formId: string, formName: string, submissionType: string) => void;
|
|
733
|
+
previewState?: "idle" | "submitting" | "success" | "error";
|
|
734
|
+
/**
|
|
735
|
+
* Increment to trigger touching every field (so validation errors render).
|
|
736
|
+
* Each new value re-runs the touch action.
|
|
737
|
+
*/
|
|
738
|
+
previewTouchAllSignal?: number;
|
|
739
|
+
/**
|
|
740
|
+
* Increment to clear all touched state (so validation errors hide again).
|
|
741
|
+
* Each new value re-runs the untouch action.
|
|
742
|
+
*/
|
|
743
|
+
previewUntouchAllSignal?: number;
|
|
744
|
+
/**
|
|
745
|
+
* Editor-only background color override applied via inline style. Takes
|
|
746
|
+
* precedence over `style.formBackgroundColor` for the lifetime of the
|
|
747
|
+
* preview. Never persisted.
|
|
748
|
+
*/
|
|
749
|
+
previewBg?: string;
|
|
750
|
+
/**
|
|
751
|
+
* Editor-only foreground color override propagated to section titles and
|
|
752
|
+
* descriptions so dark backgrounds remain readable in preview. Never
|
|
753
|
+
* persisted.
|
|
754
|
+
*/
|
|
755
|
+
previewTextColor?: string;
|
|
756
|
+
}
|
|
757
|
+
declare const DynamicForm: ({ definition, apiRoute, onSuccess, onError, extraData, className, onFormView, onFormSubmit: onFormSubmitCallback, transportKeyEndpoint, previewState, previewTouchAllSignal, previewUntouchAllSignal, previewBg, previewTextColor, }: DynamicFormProps) => react_jsx_runtime.JSX.Element;
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Single source of truth for the CSS custom properties the renderer publishes
|
|
761
|
+
* on the form root.
|
|
762
|
+
*
|
|
763
|
+
* The form builder writes per-form color overrides into `FormStyle`. Every
|
|
764
|
+
* color is optional: when set, `buildFormCssVars()` emits it as an inline CSS
|
|
765
|
+
* variable on the form root; when unset, the variable is omitted and the
|
|
766
|
+
* `var(..., fallback)` references in `INPUT_VAR` / `BUTTON_VAR` etc. resolve
|
|
767
|
+
* to the baked-in default below.
|
|
768
|
+
*
|
|
769
|
+
* Field components read from these var references — they never touch the
|
|
770
|
+
* raw `FormStyle` colors — so a single picker change cascades to every
|
|
771
|
+
* field automatically.
|
|
772
|
+
*/
|
|
773
|
+
declare const FORM_CSS_VAR: {
|
|
774
|
+
readonly formBg: "--form-bg";
|
|
775
|
+
readonly inputBg: "--form-input-bg";
|
|
776
|
+
readonly inputBorder: "--form-input-border";
|
|
777
|
+
readonly inputFocusBorder: "--form-input-focus-border";
|
|
778
|
+
readonly inputText: "--form-input-text";
|
|
779
|
+
readonly placeholder: "--form-placeholder";
|
|
780
|
+
readonly labelText: "--form-label-text";
|
|
781
|
+
readonly error: "--form-error";
|
|
782
|
+
readonly buttonBg: "--form-button-bg";
|
|
783
|
+
readonly buttonText: "--form-button-text";
|
|
784
|
+
};
|
|
785
|
+
/**
|
|
786
|
+
* Baked-in defaults used when the FormStyle doesn't override a color. These
|
|
787
|
+
* are the fallbacks inside the `var(--name, fallback)` references that the
|
|
788
|
+
* renderer uses, so they apply automatically whenever the corresponding var
|
|
789
|
+
* isn't set on the form root.
|
|
790
|
+
*/
|
|
791
|
+
declare const FORM_DEFAULT_COLOR: {
|
|
792
|
+
readonly formBg: "transparent";
|
|
793
|
+
readonly inputBg: "inherit";
|
|
794
|
+
readonly inputBorder: "#d1d5db";
|
|
795
|
+
readonly inputFocusBorder: "#2563eb";
|
|
796
|
+
readonly inputText: "inherit";
|
|
797
|
+
readonly placeholder: "#9ca3af";
|
|
798
|
+
readonly labelText: "inherit";
|
|
799
|
+
readonly error: "#ef4444";
|
|
800
|
+
readonly buttonBg: "#2563eb";
|
|
801
|
+
readonly buttonText: "#ffffff";
|
|
802
|
+
};
|
|
803
|
+
/**
|
|
804
|
+
* Pre-built `var(...)` references with fallbacks. Pass these straight into
|
|
805
|
+
* inline `style` props; the form root's CSS variables override the fallback
|
|
806
|
+
* automatically wherever the user has set a color.
|
|
807
|
+
*/
|
|
808
|
+
declare const FORM_VAR: {
|
|
809
|
+
readonly formBg: string;
|
|
810
|
+
readonly inputBg: string;
|
|
811
|
+
readonly inputBorder: string;
|
|
812
|
+
readonly inputFocusBorder: string;
|
|
813
|
+
readonly inputText: string;
|
|
814
|
+
readonly placeholder: string;
|
|
815
|
+
readonly labelText: string;
|
|
816
|
+
readonly error: string;
|
|
817
|
+
readonly buttonBg: string;
|
|
818
|
+
readonly buttonText: string;
|
|
819
|
+
};
|
|
820
|
+
/**
|
|
821
|
+
* Build the inline `style` object the form root should receive: only emits
|
|
822
|
+
* a CSS variable for colors the FormStyle actually overrides, leaving the
|
|
823
|
+
* rest to fall back via `FORM_VAR.*`. Optional `previewBg` (editor-only)
|
|
824
|
+
* takes precedence over the persisted form background and is also published
|
|
825
|
+
* to the input-bg variable so floating-label masks track the live preview.
|
|
826
|
+
*/
|
|
827
|
+
declare function buildFormCssVars(style: FormStyle, previewBg?: string): CSSProperties;
|
|
828
|
+
|
|
829
|
+
interface Props$1 {
|
|
830
|
+
section: FormSection;
|
|
831
|
+
isLast?: boolean;
|
|
832
|
+
/**
|
|
833
|
+
* Form-level default header text color from `FormDefinition.defaultTextColor`.
|
|
834
|
+
* Per-section `textColor` overrides this; the editor preview text color
|
|
835
|
+
* (when set) overrides both.
|
|
836
|
+
*/
|
|
837
|
+
formDefaultTextColor?: string;
|
|
838
|
+
/**
|
|
839
|
+
* Submit button rendered beside this section's fields grid (inline
|
|
840
|
+
* `buttonPlacement`). The section title/description stay full-width above
|
|
841
|
+
* the row — only the fields share the row with the button.
|
|
842
|
+
*/
|
|
843
|
+
inlineSubmit?: React.ReactNode;
|
|
844
|
+
}
|
|
845
|
+
declare const DynamicFormSection: ({ section, isLast, formDefaultTextColor, inlineSubmit, }: Props$1) => react_jsx_runtime.JSX.Element;
|
|
846
|
+
|
|
847
|
+
interface Props {
|
|
848
|
+
field: FormFieldDefinition;
|
|
849
|
+
/** True when this field is a "same as" target and the toggle is on. */
|
|
850
|
+
mirrored?: boolean;
|
|
851
|
+
/** How a mirrored target renders while the toggle is on. */
|
|
852
|
+
mirrorBehavior?: "hide" | "lock";
|
|
853
|
+
}
|
|
854
|
+
declare const DynamicFormField: ({ field, mirrored, mirrorBehavior }: Props) => react_jsx_runtime.JSX.Element | null;
|
|
855
|
+
|
|
856
|
+
interface BaseFetchOptions {
|
|
857
|
+
cmsUrl: string;
|
|
858
|
+
projectId: string;
|
|
859
|
+
apiKey: string;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* One of `formId` or `formSlug` must be provided to identify which form to load.
|
|
863
|
+
*/
|
|
864
|
+
type FormIdentifier = {
|
|
865
|
+
formId: string;
|
|
866
|
+
formSlug?: never;
|
|
867
|
+
} | {
|
|
868
|
+
formId?: never;
|
|
869
|
+
formSlug: string;
|
|
870
|
+
};
|
|
871
|
+
type UseFormDefinitionOptions = BaseFetchOptions & FormIdentifier;
|
|
872
|
+
interface UseFormDefinitionResult {
|
|
873
|
+
definition: FormDefinition | null;
|
|
874
|
+
isLoading: boolean;
|
|
875
|
+
error: Error | null;
|
|
876
|
+
}
|
|
877
|
+
declare function useFormDefinition(opts: UseFormDefinitionOptions): UseFormDefinitionResult;
|
|
878
|
+
/**
|
|
879
|
+
* Server-side fetch for use in Next.js Server Components / RSC / getStaticProps.
|
|
880
|
+
* Returns `null` on any error or when the form does not exist.
|
|
881
|
+
*/
|
|
882
|
+
declare function getFormDefinition(opts: UseFormDefinitionOptions & {
|
|
883
|
+
revalidate?: number;
|
|
884
|
+
}): Promise<FormDefinition | null>;
|
|
885
|
+
|
|
886
|
+
type SetStateUpdater<T> = T | ((prev: T) => T);
|
|
887
|
+
interface UseUndoRedoOptions {
|
|
888
|
+
/** Maximum number of past entries to retain. Defaults to 50. */
|
|
889
|
+
historyLimit?: number;
|
|
890
|
+
}
|
|
891
|
+
interface UseUndoRedoControls<T> {
|
|
892
|
+
/** Replace the current state without recording history. Clears past+future. */
|
|
893
|
+
reset: (value: T) => void;
|
|
894
|
+
/** Number of past entries currently retained. */
|
|
895
|
+
historySize: number;
|
|
896
|
+
}
|
|
897
|
+
type UseUndoRedoReturn<T> = [
|
|
898
|
+
T,
|
|
899
|
+
(value: SetStateUpdater<T>) => void,
|
|
900
|
+
() => void,
|
|
901
|
+
() => void,
|
|
902
|
+
boolean,
|
|
903
|
+
boolean,
|
|
904
|
+
UseUndoRedoControls<T>
|
|
905
|
+
];
|
|
906
|
+
/**
|
|
907
|
+
* Generic undo/redo state hook.
|
|
908
|
+
*
|
|
909
|
+
* Returns a tuple shaped like `useState`, plus undo/redo callbacks and
|
|
910
|
+
* canUndo/canRedo flags. The 7th element exposes controls (`reset`,
|
|
911
|
+
* `historySize`) that are only needed in advanced cases — most callers can
|
|
912
|
+
* destructure just the first six.
|
|
913
|
+
*
|
|
914
|
+
* History is bounded at `historyLimit` (default 50) — the oldest past entries
|
|
915
|
+
* are dropped when the cap is reached.
|
|
916
|
+
*/
|
|
917
|
+
declare function useUndoRedo<T>(initialState: T, options?: UseUndoRedoOptions): UseUndoRedoReturn<T>;
|
|
918
|
+
/**
|
|
919
|
+
* Wires Cmd/Ctrl+Z (undo) and Cmd/Ctrl+Shift+Z (redo) keyboard shortcuts.
|
|
920
|
+
*
|
|
921
|
+
* Skips the shortcut when the user is typing in an input/textarea or
|
|
922
|
+
* contenteditable region, so the browser's native input-history undo works
|
|
923
|
+
* inside text fields without clobbering form-level history.
|
|
924
|
+
*/
|
|
925
|
+
declare function useUndoRedoShortcuts(opts: {
|
|
926
|
+
undo: () => void;
|
|
927
|
+
redo: () => void;
|
|
928
|
+
enabled?: boolean;
|
|
929
|
+
}): void;
|
|
930
|
+
|
|
931
|
+
type DropPosition = "before" | "after";
|
|
932
|
+
interface DragReorderState {
|
|
933
|
+
draggingId: string | null;
|
|
934
|
+
dragOverId: string | null;
|
|
935
|
+
dragOverPosition: DropPosition | null;
|
|
936
|
+
}
|
|
937
|
+
interface DragReorderItemHandlers {
|
|
938
|
+
draggable: true;
|
|
939
|
+
onDragStart: (e: DragEvent<HTMLElement>) => void;
|
|
940
|
+
onDragEnd: (e: DragEvent<HTMLElement>) => void;
|
|
941
|
+
onDragOver: (e: DragEvent<HTMLElement>) => void;
|
|
942
|
+
onDragLeave: (e: DragEvent<HTMLElement>) => void;
|
|
943
|
+
onDrop: (e: DragEvent<HTMLElement>) => void;
|
|
944
|
+
}
|
|
945
|
+
interface UseDragReorderOptions<T> {
|
|
946
|
+
items: T[];
|
|
947
|
+
getId: (item: T) => string;
|
|
948
|
+
onReorder: (newOrder: T[]) => void;
|
|
949
|
+
/**
|
|
950
|
+
* MIME type for the drag payload. Different reorder zones (e.g. sections vs.
|
|
951
|
+
* fields) should use different types so a section drag can't be dropped on a
|
|
952
|
+
* field row by accident.
|
|
953
|
+
*/
|
|
954
|
+
dragType?: string;
|
|
955
|
+
}
|
|
956
|
+
interface UseDragReorderResult extends DragReorderState {
|
|
957
|
+
itemHandlers: (id: string) => DragReorderItemHandlers;
|
|
958
|
+
/** True when this item is being dragged. Useful for opacity styling. */
|
|
959
|
+
isDragging: (id: string) => boolean;
|
|
960
|
+
/**
|
|
961
|
+
* Returns the drop indicator position for `id` ("before" / "after" / null).
|
|
962
|
+
* Render a 2px blue line at the matching edge.
|
|
963
|
+
*/
|
|
964
|
+
dropIndicator: (id: string) => DropPosition | null;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* HTML5 drag-and-drop reordering for a flat list of items.
|
|
968
|
+
*
|
|
969
|
+
* Each item should spread the handlers returned by `itemHandlers(id)` onto
|
|
970
|
+
* its root element, and render a drop indicator using `dropIndicator(id)`.
|
|
971
|
+
*
|
|
972
|
+
* The hook computes drop position from the cursor position relative to the
|
|
973
|
+
* hovered item — top half means "drop before", bottom half means "drop after".
|
|
974
|
+
*/
|
|
975
|
+
declare function useDragReorder<T>({ items, getId, onReorder, dragType, }: UseDragReorderOptions<T>): UseDragReorderResult;
|
|
976
|
+
|
|
977
|
+
export { APPLICATION_STATUS_KEYS, type ApplicationStatusEmailTemplates, type ApplicationStatusKey, CORE_EMAIL_TEMPLATE_VARIABLES, DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES, DEFAULT_FILE_FIELD_CONFIG, DEFAULT_FORM_STYLE, DEFAULT_NOTIFICATION_EMAIL_HTML, DEFAULT_NOTIFICATION_EMAIL_SUBJECT, DEFAULT_NOTIFICATION_EMAIL_TEMPLATE, DEFAULT_SENSITIVE_FIELD_CONFIG, DEFAULT_SPAM_PROTECTION, type DatetimeConfig, type DragReorderItemHandlers, type DragReorderState, type DropPosition, DynamicForm, DynamicFormField, DynamicFormSection, type EmailTemplateVariableDescriptor, type EmailTemplateVariables, type EncryptedSensitiveValue, FORM_CSS_VAR, FORM_DEFAULT_COLOR, FORM_VAR, type FieldOption, type FieldTransform, type FieldType, type FieldVisibilityCondition, type FieldWidth, type FileFieldConfig, type FormDefinition, type FormDefinitionJSON, type FormFieldDefinition, type FormFieldDefinitionJSON, type FormIdentifier, type FormIntegrationConfig, type FormIntegrationConfigJSON, type FormIntegrations, type FormIntegrationsJSON, type FormSection, type FormSectionJSON, type FormSpamProtectionConfig, type FormStatus, type FormStyle, type FormStyleJSON, type FormStylePreset, type FormSubmissionType, type FormSubmitConfig, type FormSubmitConfigJSON, type FormSuccessBehavior, HONEYPOT_FIELD_NAME, type InputVariant, type IntegrationFieldMappingEntry, type IntegrationFieldMappingEntryJSON, NEWSLETTER_ALLOWED_FIELD_TYPES, type NotificationEmailTemplate, SAME_AS_TOGGLE_PREFIX, SAMPLE_EMAIL_TEMPLATE_VARIABLES, type SectionSameAsConfig, type SensitiveFieldConfig, type SensitiveFieldConfigJSON, type SetStateUpdater, type TextTransform, type TransportPublicKey, type UseDragReorderOptions, type UseDragReorderResult, type UseFormDefinitionOptions, type UseUndoRedoControls, type UseUndoRedoOptions, type UseUndoRedoReturn, type ValidationRule, type ValidationRuleJSON, type VisibilityOperator, applyTextTransform, applyTransform, base64ToBuffer, bufferToBase64, buildEmailTemplateVariables, buildFormCssVars, buildInitialValues, buildYupSchema, deriveLast4, encryptSensitiveValue, formatSsn, formatUsPhone, getFormDefinition, getSafeRedirectUrl, isVisibilityConditionMet, parseFormDefinition, renderEmailTemplate, renderNotificationEmail, sameAsToggleKey, useDragReorder, useFormDefinition, useUndoRedo, useUndoRedoShortcuts };
|