@vulcantech/forms 0.2.0 → 0.4.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 +132 -6
- package/dist/index.d.mts +870 -35
- package/dist/index.d.ts +870 -35
- package/dist/index.js +1055 -229
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1016 -233
- package/dist/index.mjs.map +1 -1
- package/fingerprint.json +4 -0
- package/package.json +12 -4
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as Yup from 'yup';
|
|
2
|
-
import { useFormikContext, Formik, Form
|
|
3
|
-
import { createContext,
|
|
2
|
+
import { useField, useFormikContext, Formik, Form } from 'formik';
|
|
3
|
+
import { createContext, useContext, useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
4
4
|
import { twMerge } from 'tailwind-merge';
|
|
5
5
|
import { Checkbox, RadioGroup, Select } from 'radix-ui';
|
|
6
6
|
import { BsCheck, BsChevronDown } from 'react-icons/bs';
|
|
7
|
-
import {
|
|
7
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import DatePicker from 'react-datepicker';
|
|
9
9
|
import { set, parse, isValid, isWeekend, isSameDay, addDays, format } from 'date-fns';
|
|
10
10
|
import 'react-datepicker/dist/react-datepicker.css';
|
|
@@ -84,6 +84,18 @@ var DEFAULT_SPAM_PROTECTION = {
|
|
|
84
84
|
honeypot: true,
|
|
85
85
|
minSubmitTime: 3
|
|
86
86
|
};
|
|
87
|
+
var FORM_STYLE_COLOR_KEYS = [
|
|
88
|
+
"formBackgroundColor",
|
|
89
|
+
"inputBgColor",
|
|
90
|
+
"inputBorderColor",
|
|
91
|
+
"inputFocusColor",
|
|
92
|
+
"inputTextColor",
|
|
93
|
+
"placeholderColor",
|
|
94
|
+
"labelColor",
|
|
95
|
+
"errorColor",
|
|
96
|
+
"buttonColor",
|
|
97
|
+
"buttonTextColor"
|
|
98
|
+
];
|
|
87
99
|
var DEFAULT_FORM_STYLE = {
|
|
88
100
|
preset: "default",
|
|
89
101
|
borderRadius: "md",
|
|
@@ -439,6 +451,105 @@ function getSafeRedirectUrl(raw) {
|
|
|
439
451
|
return null;
|
|
440
452
|
}
|
|
441
453
|
|
|
454
|
+
// src/utils/conversion.ts
|
|
455
|
+
var FORM_SUBMIT_SUCCESS_EVENT = "form_submit_success";
|
|
456
|
+
var FORM_CONVERSION_SEND_TO_GLOBAL = "__vtFormConversionSendTo";
|
|
457
|
+
var ENHANCED_CONVERSIONS_GLOBAL = "__vtEnhancedConversions";
|
|
458
|
+
function toE164(raw) {
|
|
459
|
+
if (typeof raw !== "string" && typeof raw !== "number") return void 0;
|
|
460
|
+
const digits = String(raw).replace(/\D/g, "");
|
|
461
|
+
if (digits.length === 10) return `+1${digits}`;
|
|
462
|
+
if (digits.length === 11 && digits[0] === "1") return `+${digits}`;
|
|
463
|
+
return void 0;
|
|
464
|
+
}
|
|
465
|
+
function buildUserData(input) {
|
|
466
|
+
if (!input) return void 0;
|
|
467
|
+
const email = typeof input.email === "string" ? input.email.trim().toLowerCase() : "";
|
|
468
|
+
const phone = toE164(input.phone);
|
|
469
|
+
if (!email && !phone) return void 0;
|
|
470
|
+
return __spreadValues(__spreadValues({}, email ? { email } : {}), phone ? { phone_number: phone } : {});
|
|
471
|
+
}
|
|
472
|
+
function newTransactionId() {
|
|
473
|
+
try {
|
|
474
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
475
|
+
return crypto.randomUUID();
|
|
476
|
+
}
|
|
477
|
+
} catch (e) {
|
|
478
|
+
}
|
|
479
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
480
|
+
}
|
|
481
|
+
function googleWindow() {
|
|
482
|
+
if (typeof window === "undefined") return void 0;
|
|
483
|
+
return window;
|
|
484
|
+
}
|
|
485
|
+
function pushFormSubmitSuccess(context) {
|
|
486
|
+
const win = googleWindow();
|
|
487
|
+
if (!win) return false;
|
|
488
|
+
try {
|
|
489
|
+
if (!Array.isArray(win.dataLayer)) {
|
|
490
|
+
if (win.dataLayer !== void 0) return false;
|
|
491
|
+
win.dataLayer = [];
|
|
492
|
+
}
|
|
493
|
+
win.dataLayer.push({
|
|
494
|
+
event: FORM_SUBMIT_SUCCESS_EVENT,
|
|
495
|
+
formId: context.formId,
|
|
496
|
+
formName: context.formName,
|
|
497
|
+
formType: context.formType
|
|
498
|
+
});
|
|
499
|
+
return true;
|
|
500
|
+
} catch (e) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function fireAdsConversion(sendTo, extras = {}) {
|
|
505
|
+
if (typeof sendTo !== "string" || sendTo.trim() === "") return false;
|
|
506
|
+
const win = googleWindow();
|
|
507
|
+
if (!win || typeof win.gtag !== "function") return false;
|
|
508
|
+
try {
|
|
509
|
+
if (win[ENHANCED_CONVERSIONS_GLOBAL] === true) {
|
|
510
|
+
const userData = buildUserData(extras.userData);
|
|
511
|
+
if (userData) win.gtag("set", "user_data", userData);
|
|
512
|
+
}
|
|
513
|
+
win.gtag("event", "conversion", __spreadValues({
|
|
514
|
+
send_to: sendTo.trim()
|
|
515
|
+
}, extras.transactionId ? { transaction_id: extras.transactionId } : {}));
|
|
516
|
+
return true;
|
|
517
|
+
} catch (e) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function fireGenerateLead(context) {
|
|
522
|
+
const win = googleWindow();
|
|
523
|
+
if (!win || typeof win.gtag !== "function") return false;
|
|
524
|
+
try {
|
|
525
|
+
win.gtag("event", "generate_lead", {
|
|
526
|
+
form_id: context.formId,
|
|
527
|
+
form_type: context.formType
|
|
528
|
+
});
|
|
529
|
+
return true;
|
|
530
|
+
} catch (e) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function resolveConversionSendTo(formSendTo) {
|
|
535
|
+
var _a;
|
|
536
|
+
if (typeof formSendTo === "string" && formSendTo.trim() !== "") {
|
|
537
|
+
return formSendTo.trim();
|
|
538
|
+
}
|
|
539
|
+
const global = (_a = googleWindow()) == null ? void 0 : _a[FORM_CONVERSION_SEND_TO_GLOBAL];
|
|
540
|
+
if (typeof global === "string" && global.trim() !== "") return global.trim();
|
|
541
|
+
return void 0;
|
|
542
|
+
}
|
|
543
|
+
function trackFormConversion(context, formSendTo, extras = {}) {
|
|
544
|
+
const pushed = pushFormSubmitSuccess(context);
|
|
545
|
+
const conversionFired = fireAdsConversion(
|
|
546
|
+
resolveConversionSendTo(formSendTo),
|
|
547
|
+
extras
|
|
548
|
+
);
|
|
549
|
+
const leadFired = fireGenerateLead(context);
|
|
550
|
+
return { pushed, conversionFired, leadFired };
|
|
551
|
+
}
|
|
552
|
+
|
|
442
553
|
// src/utils/textTransforms.ts
|
|
443
554
|
function formatSsn(raw) {
|
|
444
555
|
const digits = raw.replace(/\D/g, "").slice(0, 9);
|
|
@@ -587,6 +698,48 @@ function renderNotificationEmail(template, variables) {
|
|
|
587
698
|
};
|
|
588
699
|
}
|
|
589
700
|
|
|
701
|
+
// src/utils/resizeImage.ts
|
|
702
|
+
var RESIZABLE_TYPES = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
703
|
+
var ENCODE_QUALITY = 0.85;
|
|
704
|
+
var MAX_DECODE_BYTES = 50 * 1024 * 1024;
|
|
705
|
+
function canResize() {
|
|
706
|
+
return typeof createImageBitmap === "function" && typeof document !== "undefined" && typeof document.createElement === "function";
|
|
707
|
+
}
|
|
708
|
+
function canvasToBlob(canvas, type, quality) {
|
|
709
|
+
return new Promise((resolve) => canvas.toBlob(resolve, type, quality));
|
|
710
|
+
}
|
|
711
|
+
function resizeImageFile(file, maxWidth) {
|
|
712
|
+
return __async(this, null, function* () {
|
|
713
|
+
if (!Number.isFinite(maxWidth) || maxWidth <= 0) return file;
|
|
714
|
+
if (!RESIZABLE_TYPES.has(file.type)) return file;
|
|
715
|
+
if (file.size > MAX_DECODE_BYTES) return file;
|
|
716
|
+
if (!canResize()) return file;
|
|
717
|
+
let bitmap;
|
|
718
|
+
try {
|
|
719
|
+
bitmap = yield createImageBitmap(file, { imageOrientation: "from-image" });
|
|
720
|
+
if (bitmap.width <= maxWidth) return file;
|
|
721
|
+
const width = Math.round(maxWidth);
|
|
722
|
+
const height = Math.max(1, Math.round(bitmap.height * width / bitmap.width));
|
|
723
|
+
const canvas = document.createElement("canvas");
|
|
724
|
+
canvas.width = width;
|
|
725
|
+
canvas.height = height;
|
|
726
|
+
const ctx = canvas.getContext("2d");
|
|
727
|
+
if (!ctx) return file;
|
|
728
|
+
ctx.drawImage(bitmap, 0, 0, width, height);
|
|
729
|
+
const blob = yield canvasToBlob(canvas, file.type, ENCODE_QUALITY);
|
|
730
|
+
if (!blob || blob.size >= file.size) return file;
|
|
731
|
+
return new File([blob], file.name, {
|
|
732
|
+
type: file.type,
|
|
733
|
+
lastModified: file.lastModified
|
|
734
|
+
});
|
|
735
|
+
} catch (e) {
|
|
736
|
+
return file;
|
|
737
|
+
} finally {
|
|
738
|
+
bitmap == null ? void 0 : bitmap.close();
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
|
|
590
743
|
// src/crypto/sensitive.ts
|
|
591
744
|
function bufferToBase64(buf) {
|
|
592
745
|
const bytes = new Uint8Array(buf);
|
|
@@ -655,14 +808,161 @@ function deriveLast4(plaintext) {
|
|
|
655
808
|
const digits = plaintext.replace(/\D/g, "");
|
|
656
809
|
return digits.slice(-4).padStart(4, "\u2022");
|
|
657
810
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
var
|
|
661
|
-
var
|
|
662
|
-
|
|
663
|
-
)
|
|
664
|
-
|
|
665
|
-
|
|
811
|
+
|
|
812
|
+
// src/tracking/adReferral.ts
|
|
813
|
+
var AD_REFERRAL_COOKIE = "vt_ad_ref";
|
|
814
|
+
var AD_REFERRAL_TTL_DAYS = 30;
|
|
815
|
+
var LANDING_PAGE_MAX = 200;
|
|
816
|
+
function cleanLandingPage(pathname) {
|
|
817
|
+
if (typeof pathname !== "string" || !pathname.startsWith("/")) return void 0;
|
|
818
|
+
return pathname.slice(0, LANDING_PAGE_MAX);
|
|
819
|
+
}
|
|
820
|
+
var CLICK_ID_PARAMS = ["gclid", "gbraid", "wbraid"];
|
|
821
|
+
function isClickIdType(value) {
|
|
822
|
+
return CLICK_ID_PARAMS.includes(value);
|
|
823
|
+
}
|
|
824
|
+
var GOOGLE_AD_PARAMS = ["gad_source", "gad_campaignid"];
|
|
825
|
+
var UTM_PARAMS = [
|
|
826
|
+
["utm_source", "source"],
|
|
827
|
+
["utm_medium", "medium"],
|
|
828
|
+
["utm_campaign", "campaign"],
|
|
829
|
+
["utm_term", "term"],
|
|
830
|
+
["utm_content", "content"]
|
|
831
|
+
];
|
|
832
|
+
function captureAdReferral(search, fallback, now = /* @__PURE__ */ new Date(), pathname) {
|
|
833
|
+
var _a, _b, _c, _d;
|
|
834
|
+
const landingPage = cleanLandingPage(pathname);
|
|
835
|
+
const params = new URLSearchParams(search);
|
|
836
|
+
const utm = {};
|
|
837
|
+
for (const [param, key] of UTM_PARAMS) {
|
|
838
|
+
const value = params.get(param);
|
|
839
|
+
if (value) utm[key] = value;
|
|
840
|
+
}
|
|
841
|
+
let clickId;
|
|
842
|
+
let clickIdType;
|
|
843
|
+
for (const param of CLICK_ID_PARAMS) {
|
|
844
|
+
const value = params.get(param);
|
|
845
|
+
if (value) {
|
|
846
|
+
clickId = value;
|
|
847
|
+
clickIdType = param;
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
const adCampaignId = params.get("gad_campaignid") || void 0;
|
|
852
|
+
const googleAdClick = clickId !== void 0 || GOOGLE_AD_PARAMS.some((p) => params.get(p));
|
|
853
|
+
const hasSignal = Object.keys(utm).length > 0 || googleAdClick;
|
|
854
|
+
if (!hasSignal) {
|
|
855
|
+
if (!fallback) return null;
|
|
856
|
+
return __spreadProps(__spreadValues({
|
|
857
|
+
source: fallback.source,
|
|
858
|
+
medium: fallback.medium,
|
|
859
|
+
campaign: fallback.campaign
|
|
860
|
+
}, landingPage ? { landingPage } : {}), {
|
|
861
|
+
landedAt: now.toISOString()
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
return __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
865
|
+
// An auto-tagged click with no UTMs is a Google paid click. Inferring
|
|
866
|
+
// this is what makes `classifySource` bucket it as "paid" rather than
|
|
867
|
+
// leaving the lead unattributed.
|
|
868
|
+
//
|
|
869
|
+
// Tagging that sets only `utm_campaign` (or only term/content) leaves
|
|
870
|
+
// BOTH of these empty, and that is deliberate: the CMS's
|
|
871
|
+
// `deriveLeadSource` only classifies when one of them is non-empty and
|
|
872
|
+
// otherwise returns undefined, so such a lead reads as "unknown". Do not
|
|
873
|
+
// "fix" this by defaulting to "direct" — an honest unknown beats a
|
|
874
|
+
// fabricated bucket, and the campaign still rides along for inspection.
|
|
875
|
+
source: (_a = utm.source) != null ? _a : googleAdClick ? "google" : "",
|
|
876
|
+
medium: (_b = utm.medium) != null ? _b : googleAdClick ? "cpc" : "",
|
|
877
|
+
campaign: (_d = (_c = utm.campaign) != null ? _c : adCampaignId) != null ? _d : googleAdClick ? "(not set)" : ""
|
|
878
|
+
}, utm.term ? { term: utm.term } : {}), utm.content ? { content: utm.content } : {}), clickId ? { clickId, clickIdType } : {}), landingPage ? { landingPage } : {}), {
|
|
879
|
+
landedAt: now.toISOString()
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
function readAdReferral(cookieName = AD_REFERRAL_COOKIE) {
|
|
883
|
+
if (typeof document === "undefined") return null;
|
|
884
|
+
for (const cookie of document.cookie.split(";")) {
|
|
885
|
+
const separator = cookie.indexOf("=");
|
|
886
|
+
if (separator === -1) continue;
|
|
887
|
+
if (cookie.slice(0, separator).trim() !== cookieName) continue;
|
|
888
|
+
try {
|
|
889
|
+
const parsed = JSON.parse(
|
|
890
|
+
decodeURIComponent(cookie.slice(separator + 1))
|
|
891
|
+
);
|
|
892
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
const _a = parsed, { source, medium, campaign, landedAt, clickIdType } = _a, rest = __objRest(_a, ["source", "medium", "campaign", "landedAt", "clickIdType"]);
|
|
896
|
+
if (typeof source !== "string" || typeof medium !== "string") return null;
|
|
897
|
+
return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, rest), {
|
|
898
|
+
source,
|
|
899
|
+
medium,
|
|
900
|
+
campaign: typeof campaign === "string" ? campaign : ""
|
|
901
|
+
}), isClickIdType(clickIdType) ? { clickIdType } : {}), {
|
|
902
|
+
landedAt: typeof landedAt === "string" ? landedAt : ""
|
|
903
|
+
});
|
|
904
|
+
} catch (e) {
|
|
905
|
+
return null;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
function isSameAdReferralTouch(a, b) {
|
|
911
|
+
return [...Object.keys(a), ...Object.keys(b)].every(
|
|
912
|
+
(key) => key === "landedAt" || a[key] === b[key]
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
function writeAdReferral(referral, cookieName = AD_REFERRAL_COOKIE, ttlDays = AD_REFERRAL_TTL_DAYS) {
|
|
916
|
+
if (typeof document === "undefined") return;
|
|
917
|
+
const expires = /* @__PURE__ */ new Date();
|
|
918
|
+
expires.setDate(expires.getDate() + ttlDays);
|
|
919
|
+
const value = encodeURIComponent(JSON.stringify(referral));
|
|
920
|
+
document.cookie = `${cookieName}=${value}; expires=${expires.toUTCString()}; path=/; SameSite=Lax`;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// src/tracking/analyticsSession.ts
|
|
924
|
+
var ANALYTICS_SESSION_KEY = "__vt_sid";
|
|
925
|
+
function readAnalyticsSessionId() {
|
|
926
|
+
if (typeof window === "undefined") return void 0;
|
|
927
|
+
try {
|
|
928
|
+
const sid = window.sessionStorage.getItem(ANALYTICS_SESSION_KEY);
|
|
929
|
+
return sid && /^[a-z0-9]{6,64}$/i.test(sid) ? sid : void 0;
|
|
930
|
+
} catch (e) {
|
|
931
|
+
return void 0;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// src/utils/colorScheme.ts
|
|
936
|
+
function hasDarkColors(style) {
|
|
937
|
+
const dark = style == null ? void 0 : style.dark;
|
|
938
|
+
if (!dark) return false;
|
|
939
|
+
return FORM_STYLE_COLOR_KEYS.some((key) => Boolean(dark[key]));
|
|
940
|
+
}
|
|
941
|
+
function definitionHasDarkColors(definition) {
|
|
942
|
+
if (hasDarkColors(definition.style)) return true;
|
|
943
|
+
if (definition.defaultTextColorDark) return true;
|
|
944
|
+
return definition.sections.some((section) => Boolean(section.textColorDark));
|
|
945
|
+
}
|
|
946
|
+
function resolveSchemeColors(style, scheme) {
|
|
947
|
+
const dark = scheme === "dark" ? style.dark : void 0;
|
|
948
|
+
const out = {};
|
|
949
|
+
for (const key of FORM_STYLE_COLOR_KEYS) {
|
|
950
|
+
const value = (dark == null ? void 0 : dark[key]) || style[key];
|
|
951
|
+
if (value) out[key] = value;
|
|
952
|
+
}
|
|
953
|
+
return out;
|
|
954
|
+
}
|
|
955
|
+
function resolveSchemeStyle(style, scheme) {
|
|
956
|
+
const structural = __spreadValues({}, style);
|
|
957
|
+
delete structural.dark;
|
|
958
|
+
for (const key of FORM_STYLE_COLOR_KEYS) delete structural[key];
|
|
959
|
+
return __spreadValues(__spreadValues({}, structural), resolveSchemeColors(style, scheme));
|
|
960
|
+
}
|
|
961
|
+
function resolveSectionTextColor(section, formDefaults, scheme) {
|
|
962
|
+
const light = section.textColor || formDefaults.light || void 0;
|
|
963
|
+
if (scheme === "light") return light;
|
|
964
|
+
return section.textColorDark || formDefaults.dark || light;
|
|
965
|
+
}
|
|
666
966
|
|
|
667
967
|
// src/renderer/cssVars.ts
|
|
668
968
|
var FORM_CSS_VAR = {
|
|
@@ -677,6 +977,31 @@ var FORM_CSS_VAR = {
|
|
|
677
977
|
buttonBg: "--form-button-bg",
|
|
678
978
|
buttonText: "--form-button-text"
|
|
679
979
|
};
|
|
980
|
+
var FORM_STRUCT_VAR = {
|
|
981
|
+
radius: "--form-radius",
|
|
982
|
+
gap: "--form-gap",
|
|
983
|
+
focusBorderWidth: "--form-focus-border-width"
|
|
984
|
+
};
|
|
985
|
+
var FORM_DEFAULT_RADIUS = "0.375rem";
|
|
986
|
+
var FORM_RADIUS_VAR = `var(${FORM_STRUCT_VAR.radius}, ${FORM_DEFAULT_RADIUS})`;
|
|
987
|
+
var FORM_GAP_VAR = `var(${FORM_STRUCT_VAR.gap}, 1rem)`;
|
|
988
|
+
var FORM_DEFAULT_FOCUS_BORDER_WIDTH = "2px";
|
|
989
|
+
var FORM_FOCUS_BORDER_WIDTH_VAR = `var(${FORM_STRUCT_VAR.focusBorderWidth}, ${FORM_DEFAULT_FOCUS_BORDER_WIDTH})`;
|
|
990
|
+
function resolveCustomGap(style) {
|
|
991
|
+
var _a;
|
|
992
|
+
const raw = (_a = style.fieldGapValue) == null ? void 0 : _a.trim();
|
|
993
|
+
return raw ? raw : null;
|
|
994
|
+
}
|
|
995
|
+
function resolveCustomRadius(style) {
|
|
996
|
+
var _a;
|
|
997
|
+
const raw = (_a = style.borderRadiusValue) == null ? void 0 : _a.trim();
|
|
998
|
+
return raw ? raw : null;
|
|
999
|
+
}
|
|
1000
|
+
function resolveCustomFocusBorderWidth(style) {
|
|
1001
|
+
var _a;
|
|
1002
|
+
const raw = (_a = style.inputFocusBorderWidth) == null ? void 0 : _a.trim();
|
|
1003
|
+
return raw ? raw : null;
|
|
1004
|
+
}
|
|
680
1005
|
var FORM_DEFAULT_COLOR = {
|
|
681
1006
|
formBg: "transparent",
|
|
682
1007
|
inputBg: "inherit",
|
|
@@ -707,29 +1032,76 @@ var FORM_VAR = {
|
|
|
707
1032
|
buttonBg: ref(FORM_CSS_VAR.buttonBg, FORM_DEFAULT_COLOR.buttonBg),
|
|
708
1033
|
buttonText: ref(FORM_CSS_VAR.buttonText, FORM_DEFAULT_COLOR.buttonText)
|
|
709
1034
|
};
|
|
1035
|
+
var COLOR_VAR_BY_KEY = {
|
|
1036
|
+
formBackgroundColor: FORM_CSS_VAR.formBg,
|
|
1037
|
+
inputBgColor: FORM_CSS_VAR.inputBg,
|
|
1038
|
+
inputBorderColor: FORM_CSS_VAR.inputBorder,
|
|
1039
|
+
inputFocusColor: FORM_CSS_VAR.inputFocusBorder,
|
|
1040
|
+
inputTextColor: FORM_CSS_VAR.inputText,
|
|
1041
|
+
placeholderColor: FORM_CSS_VAR.placeholder,
|
|
1042
|
+
labelColor: FORM_CSS_VAR.labelText,
|
|
1043
|
+
errorColor: FORM_CSS_VAR.error,
|
|
1044
|
+
buttonColor: FORM_CSS_VAR.buttonBg,
|
|
1045
|
+
buttonTextColor: FORM_CSS_VAR.buttonText
|
|
1046
|
+
};
|
|
1047
|
+
var FORM_DARK_SCOPE_ATTR = "data-vt-form-dark";
|
|
1048
|
+
var FORM_DARK_TEXT_ATTR = "data-vt-text-dark";
|
|
1049
|
+
var FORM_DARK_TEXT_VAR = "--form-text-dark";
|
|
1050
|
+
var FORM_DEFAULT_DARK_SELECTOR = ".dark";
|
|
1051
|
+
var FORM_ROOT_BG_VAR = `var(${FORM_CSS_VAR.formBg}, inherit)`;
|
|
1052
|
+
function darkVarName(name) {
|
|
1053
|
+
return `${name}-dark`;
|
|
1054
|
+
}
|
|
1055
|
+
function buildColorVars(style, scheme, keys = FORM_STYLE_COLOR_KEYS) {
|
|
1056
|
+
const colors = resolveSchemeColors(style, scheme);
|
|
1057
|
+
const out = {};
|
|
1058
|
+
for (const key of keys) {
|
|
1059
|
+
const value = colors[key];
|
|
1060
|
+
if (!value) continue;
|
|
1061
|
+
const name = COLOR_VAR_BY_KEY[key];
|
|
1062
|
+
out[scheme === "dark" ? darkVarName(name) : name] = value;
|
|
1063
|
+
}
|
|
1064
|
+
return out;
|
|
1065
|
+
}
|
|
710
1066
|
function buildFormCssVars(style, previewBg) {
|
|
1067
|
+
var _a;
|
|
1068
|
+
const light = buildColorVars(style, "light");
|
|
711
1069
|
const out = {};
|
|
712
|
-
const
|
|
713
|
-
if (
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (
|
|
719
|
-
|
|
720
|
-
if (
|
|
721
|
-
|
|
722
|
-
if (
|
|
723
|
-
out[
|
|
724
|
-
if (style.labelColor) out[FORM_CSS_VAR.labelText] = style.labelColor;
|
|
725
|
-
if (style.errorColor) out[FORM_CSS_VAR.error] = style.errorColor;
|
|
726
|
-
if (style.buttonColor) out[FORM_CSS_VAR.buttonBg] = style.buttonColor;
|
|
727
|
-
if (style.buttonTextColor)
|
|
728
|
-
out[FORM_CSS_VAR.buttonText] = style.buttonTextColor;
|
|
1070
|
+
const formBg = (_a = light[FORM_CSS_VAR.formBg]) != null ? _a : previewBg;
|
|
1071
|
+
if (formBg) out[FORM_CSS_VAR.formBg] = formBg;
|
|
1072
|
+
for (const [name, value] of Object.entries(light)) {
|
|
1073
|
+
if (name !== FORM_CSS_VAR.formBg) out[name] = value;
|
|
1074
|
+
}
|
|
1075
|
+
const customRadius = resolveCustomRadius(style);
|
|
1076
|
+
if (customRadius) out[FORM_STRUCT_VAR.radius] = customRadius;
|
|
1077
|
+
const customGap = resolveCustomGap(style);
|
|
1078
|
+
if (customGap) out[FORM_STRUCT_VAR.gap] = customGap;
|
|
1079
|
+
const customFocusBorderWidth = resolveCustomFocusBorderWidth(style);
|
|
1080
|
+
if (customFocusBorderWidth)
|
|
1081
|
+
out[FORM_STRUCT_VAR.focusBorderWidth] = customFocusBorderWidth;
|
|
729
1082
|
return out;
|
|
730
1083
|
}
|
|
731
|
-
|
|
732
|
-
|
|
1084
|
+
function buildFormDarkCssVars(style, keys) {
|
|
1085
|
+
return buildColorVars(style, "dark", keys);
|
|
1086
|
+
}
|
|
1087
|
+
function buildDarkSchemeCss(darkSelector = FORM_DEFAULT_DARK_SELECTOR) {
|
|
1088
|
+
const swaps = Object.values(FORM_CSS_VAR).map((name) => `${name}:var(${darkVarName(name)})!important`).join(";");
|
|
1089
|
+
const scope = `${darkSelector} [${FORM_DARK_SCOPE_ATTR}]`;
|
|
1090
|
+
return `${scope}{${swaps}}${scope} [${FORM_DARK_TEXT_ATTR}]{color:var(${FORM_DARK_TEXT_VAR})!important}`;
|
|
1091
|
+
}
|
|
1092
|
+
var FORM_MUTED_TEXT_CLASS = "text-current/65";
|
|
1093
|
+
var FORM_FAINT_TEXT_CLASS = "text-current/45";
|
|
1094
|
+
var FORM_SUBTLE_BORDER_CLASS = "border-current/20";
|
|
1095
|
+
var FORM_SUBTLE_FILL_CLASS = "bg-current/10";
|
|
1096
|
+
var FORM_SUBTLE_HOVER_FILL_CLASS = "hover:bg-current/10";
|
|
1097
|
+
var FormStyleContext = createContext(DEFAULT_FORM_STYLE);
|
|
1098
|
+
var useFormStyle = () => useContext(FormStyleContext);
|
|
1099
|
+
var FormStyleProvider = FormStyleContext.Provider;
|
|
1100
|
+
var FormColorSchemeContext = createContext({
|
|
1101
|
+
darkEnabled: false
|
|
1102
|
+
});
|
|
1103
|
+
var useFormColorScheme = () => useContext(FormColorSchemeContext);
|
|
1104
|
+
var FormColorSchemeProvider = FormColorSchemeContext.Provider;
|
|
733
1105
|
var placeholderClass = "placeholder:[color:var(--form-placeholder,#9ca3af)]";
|
|
734
1106
|
var textClass = "text-[color:var(--form-input-text,inherit)]";
|
|
735
1107
|
function getVariantClasses(style) {
|
|
@@ -766,7 +1138,7 @@ function getVariantClasses(style) {
|
|
|
766
1138
|
case "underlined":
|
|
767
1139
|
return {
|
|
768
1140
|
inputClass: twMerge(
|
|
769
|
-
"rounded-none bg-
|
|
1141
|
+
"rounded-none bg-inherit 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",
|
|
770
1142
|
textClass,
|
|
771
1143
|
placeholderClass
|
|
772
1144
|
),
|
|
@@ -782,7 +1154,7 @@ function getVariantClasses(style) {
|
|
|
782
1154
|
default:
|
|
783
1155
|
return {
|
|
784
1156
|
inputClass: twMerge(
|
|
785
|
-
"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-
|
|
1157
|
+
"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-inherit",
|
|
786
1158
|
textClass,
|
|
787
1159
|
placeholderClass
|
|
788
1160
|
),
|
|
@@ -791,19 +1163,23 @@ function getVariantClasses(style) {
|
|
|
791
1163
|
borderWidth: 1,
|
|
792
1164
|
borderColor: FORM_VAR.inputBorder
|
|
793
1165
|
},
|
|
794
|
-
// Label must paint a solid bg on top of the input border.
|
|
795
|
-
//
|
|
796
|
-
//
|
|
797
|
-
//
|
|
798
|
-
//
|
|
799
|
-
//
|
|
1166
|
+
// Label must paint a solid bg on top of the input border. It reads
|
|
1167
|
+
// `--form-input-bg`, which DynamicForm publishes on the form root
|
|
1168
|
+
// from the resolved input background (or the editor preview
|
|
1169
|
+
// override). The fallback is `inherit`, and it now resolves to a
|
|
1170
|
+
// real color: every element from the form root down to this span
|
|
1171
|
+
// carries `bg-inherit`, so an unstyled form picks up whatever
|
|
1172
|
+
// background the consumer's container paints. See the chain note in
|
|
1173
|
+
// DynamicForm.
|
|
800
1174
|
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]"
|
|
801
1175
|
};
|
|
802
1176
|
}
|
|
803
1177
|
}
|
|
804
1178
|
function getFocusStyle(style) {
|
|
805
1179
|
if (style.inputVariant === "filled" || style.inputVariant === "underlined") {
|
|
806
|
-
return {
|
|
1180
|
+
return __spreadValues({
|
|
1181
|
+
borderBottomColor: FORM_VAR.inputFocusBorder
|
|
1182
|
+
}, resolveCustomFocusBorderWidth(style) ? { borderBottomWidth: FORM_FOCUS_BORDER_WIDTH_VAR } : {});
|
|
807
1183
|
}
|
|
808
1184
|
if (style.inputVariant === "stacked") {
|
|
809
1185
|
return {
|
|
@@ -817,13 +1193,19 @@ function useInputStyles() {
|
|
|
817
1193
|
const style = useFormStyle();
|
|
818
1194
|
const variant = getVariantClasses(style);
|
|
819
1195
|
const isStacked = style.inputVariant === "stacked";
|
|
1196
|
+
const customRadius = resolveCustomRadius(style);
|
|
1197
|
+
const radiusStyle = customRadius ? { borderRadius: FORM_RADIUS_VAR } : {};
|
|
1198
|
+
const radiusClass = customRadius ? "rounded-none" : "";
|
|
820
1199
|
return {
|
|
821
|
-
|
|
822
|
-
|
|
1200
|
+
// `bg-inherit` keeps the form root's background flowing down to the
|
|
1201
|
+
// inputs and floating labels, which resolve theirs with `inherit`.
|
|
1202
|
+
wrapperClass: isStacked ? "flex w-full flex-col bg-inherit" : "group relative flex w-full flex-col pt-3 bg-inherit",
|
|
1203
|
+
inputClass: isStacked ? twMerge("block w-full", variant.inputClass, radiusClass) : twMerge(
|
|
823
1204
|
"peer m-0 mb-3 block min-h-8 w-full overflow-hidden",
|
|
824
|
-
variant.inputClass
|
|
1205
|
+
variant.inputClass,
|
|
1206
|
+
radiusClass
|
|
825
1207
|
),
|
|
826
|
-
inputStyle: variant.inputStyle,
|
|
1208
|
+
inputStyle: __spreadValues(__spreadValues({}, variant.inputStyle), radiusStyle),
|
|
827
1209
|
inputFocusStyle: getFocusStyle(style),
|
|
828
1210
|
labelClass: variant.labelClass,
|
|
829
1211
|
labelStyle: { color: FORM_VAR.labelText },
|
|
@@ -832,8 +1214,9 @@ function useInputStyles() {
|
|
|
832
1214
|
isStacked
|
|
833
1215
|
};
|
|
834
1216
|
}
|
|
835
|
-
function getErrorOutlineStyle(hasError,
|
|
1217
|
+
function getErrorOutlineStyle(hasError, style) {
|
|
836
1218
|
if (!hasError) return {};
|
|
1219
|
+
const variant = style.inputVariant;
|
|
837
1220
|
if (variant === "stacked") {
|
|
838
1221
|
return {
|
|
839
1222
|
outline: `2px solid ${FORM_VAR.error}`,
|
|
@@ -847,9 +1230,9 @@ function getErrorOutlineStyle(hasError, variant) {
|
|
|
847
1230
|
borderColor: FORM_VAR.error
|
|
848
1231
|
};
|
|
849
1232
|
}
|
|
850
|
-
return {
|
|
1233
|
+
return __spreadValues({
|
|
851
1234
|
borderBottomColor: FORM_VAR.error
|
|
852
|
-
};
|
|
1235
|
+
}, resolveCustomFocusBorderWidth(style) ? { borderBottomWidth: FORM_FOCUS_BORDER_WIDTH_VAR } : {});
|
|
853
1236
|
}
|
|
854
1237
|
var StyledInput = ({
|
|
855
1238
|
id,
|
|
@@ -867,7 +1250,7 @@ var StyledInput = ({
|
|
|
867
1250
|
const style = useFormStyle();
|
|
868
1251
|
const styles = useInputStyles();
|
|
869
1252
|
const hasError = !!(error && touched);
|
|
870
|
-
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, style
|
|
1253
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, style));
|
|
871
1254
|
if (styles.isStacked) {
|
|
872
1255
|
return /* @__PURE__ */ jsxs("div", { className: styles.wrapperClass, children: [
|
|
873
1256
|
/* @__PURE__ */ jsx("label", { htmlFor: id, className: styles.labelClass, style: styles.labelStyle, children: label }),
|
|
@@ -893,7 +1276,7 @@ var StyledInput = ({
|
|
|
893
1276
|
hasError && /* @__PURE__ */ jsx(
|
|
894
1277
|
"span",
|
|
895
1278
|
{
|
|
896
|
-
className:
|
|
1279
|
+
className: "mt-1 text-xs",
|
|
897
1280
|
style: styles.errorStyle,
|
|
898
1281
|
children: error
|
|
899
1282
|
}
|
|
@@ -901,7 +1284,7 @@ var StyledInput = ({
|
|
|
901
1284
|
] });
|
|
902
1285
|
}
|
|
903
1286
|
return /* @__PURE__ */ jsxs("div", { className: styles.wrapperClass, children: [
|
|
904
|
-
/* @__PURE__ */ jsxs("label", { htmlFor: id, className: "relative inline-block", children: [
|
|
1287
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: id, className: "relative inline-block bg-inherit", children: [
|
|
905
1288
|
/* @__PURE__ */ jsx(
|
|
906
1289
|
"input",
|
|
907
1290
|
{
|
|
@@ -923,7 +1306,7 @@ var StyledInput = ({
|
|
|
923
1306
|
),
|
|
924
1307
|
/* @__PURE__ */ jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: label })
|
|
925
1308
|
] }),
|
|
926
|
-
hasError && /* @__PURE__ */ jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: error })
|
|
1309
|
+
hasError && /* @__PURE__ */ jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: error })
|
|
927
1310
|
] });
|
|
928
1311
|
};
|
|
929
1312
|
var TextField = ({ field: fieldDef, disabled }) => {
|
|
@@ -972,7 +1355,7 @@ var PhoneField = ({ field: fieldDef, disabled }) => {
|
|
|
972
1355
|
const formStyle = useFormStyle();
|
|
973
1356
|
const styles = useInputStyles();
|
|
974
1357
|
const hasError = !!(meta.error && meta.touched);
|
|
975
|
-
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle
|
|
1358
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
|
|
976
1359
|
const handleChange = (e) => {
|
|
977
1360
|
helpers.setValue(formatUsPhone(e.target.value));
|
|
978
1361
|
};
|
|
@@ -1009,7 +1392,7 @@ var PhoneField = ({ field: fieldDef, disabled }) => {
|
|
|
1009
1392
|
hasError && /* @__PURE__ */ jsx(
|
|
1010
1393
|
"span",
|
|
1011
1394
|
{
|
|
1012
|
-
className:
|
|
1395
|
+
className: "mt-1 text-xs",
|
|
1013
1396
|
style: styles.errorStyle,
|
|
1014
1397
|
children: meta.error
|
|
1015
1398
|
}
|
|
@@ -1038,7 +1421,7 @@ var PhoneField = ({ field: fieldDef, disabled }) => {
|
|
|
1038
1421
|
),
|
|
1039
1422
|
/* @__PURE__ */ jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
|
|
1040
1423
|
] }),
|
|
1041
|
-
hasError && /* @__PURE__ */ jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1424
|
+
hasError && /* @__PURE__ */ jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1042
1425
|
] });
|
|
1043
1426
|
};
|
|
1044
1427
|
var UrlField = ({ field: fieldDef, disabled }) => {
|
|
@@ -1070,7 +1453,7 @@ var AddressField = ({ field: fieldDef, disabled }) => {
|
|
|
1070
1453
|
const formStyle = useFormStyle();
|
|
1071
1454
|
const styles = useInputStyles();
|
|
1072
1455
|
const hasError = !!(meta.error && meta.touched);
|
|
1073
|
-
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle
|
|
1456
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
|
|
1074
1457
|
const placeholder = fieldDef.placeholder || "123 Main St, City, State 12345";
|
|
1075
1458
|
return /* @__PURE__ */ jsxs("div", { className: `${styles.wrapperClass} pb-5 lg:pb-0`, children: [
|
|
1076
1459
|
/* @__PURE__ */ jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
|
|
@@ -1111,7 +1494,7 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
|
|
|
1111
1494
|
const styles = useInputStyles();
|
|
1112
1495
|
const hasError = !!(meta.error && meta.touched);
|
|
1113
1496
|
const value = (_a = field.value) != null ? _a : "";
|
|
1114
|
-
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle
|
|
1497
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
|
|
1115
1498
|
if (styles.isStacked) {
|
|
1116
1499
|
return /* @__PURE__ */ jsxs("div", { className: twMerge(styles.wrapperClass, "relative"), children: [
|
|
1117
1500
|
/* @__PURE__ */ jsx(
|
|
@@ -1142,11 +1525,20 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
|
|
|
1142
1525
|
}
|
|
1143
1526
|
}
|
|
1144
1527
|
),
|
|
1145
|
-
fieldDef.characterCounter && /* @__PURE__ */ jsx(
|
|
1528
|
+
fieldDef.characterCounter && /* @__PURE__ */ jsx(
|
|
1529
|
+
"span",
|
|
1530
|
+
{
|
|
1531
|
+
className: twMerge(
|
|
1532
|
+
"mt-1 text-right text-xs",
|
|
1533
|
+
FORM_MUTED_TEXT_CLASS
|
|
1534
|
+
),
|
|
1535
|
+
children: value.length
|
|
1536
|
+
}
|
|
1537
|
+
),
|
|
1146
1538
|
hasError && /* @__PURE__ */ jsx(
|
|
1147
1539
|
"span",
|
|
1148
1540
|
{
|
|
1149
|
-
className:
|
|
1541
|
+
className: "mt-1 text-xs",
|
|
1150
1542
|
style: styles.errorStyle,
|
|
1151
1543
|
children: meta.error
|
|
1152
1544
|
}
|
|
@@ -1154,7 +1546,7 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
|
|
|
1154
1546
|
] });
|
|
1155
1547
|
}
|
|
1156
1548
|
return /* @__PURE__ */ jsxs("div", { className: twMerge(styles.wrapperClass, "pb-5 lg:pb-0"), children: [
|
|
1157
|
-
/* @__PURE__ */ jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block", children: [
|
|
1549
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
|
|
1158
1550
|
/* @__PURE__ */ jsx(
|
|
1159
1551
|
"textarea",
|
|
1160
1552
|
{
|
|
@@ -1180,20 +1572,29 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
|
|
|
1180
1572
|
hasError && /* @__PURE__ */ jsx("span", { className: "text-xs", style: styles.errorStyle, children: meta.error })
|
|
1181
1573
|
] });
|
|
1182
1574
|
};
|
|
1575
|
+
var POPOVER_COLOR_KEYS = [
|
|
1576
|
+
"inputBgColor",
|
|
1577
|
+
"inputBorderColor",
|
|
1578
|
+
"inputTextColor",
|
|
1579
|
+
"inputFocusColor"
|
|
1580
|
+
];
|
|
1183
1581
|
var SelectField = ({ field: fieldDef, disabled }) => {
|
|
1184
1582
|
var _a;
|
|
1185
1583
|
const [field, meta, helpers] = useField(fieldDef.id);
|
|
1186
1584
|
const [focused, setFocused] = useState(false);
|
|
1187
1585
|
const formStyle = useFormStyle();
|
|
1586
|
+
const { darkEnabled } = useFormColorScheme();
|
|
1188
1587
|
const styles = useInputStyles();
|
|
1189
1588
|
const hasError = !!(meta.error && meta.touched);
|
|
1589
|
+
const popoverVars = __spreadValues(__spreadValues({}, buildColorVars(formStyle, "light", POPOVER_COLOR_KEYS)), darkEnabled ? buildColorVars(formStyle, "dark", POPOVER_COLOR_KEYS) : {});
|
|
1590
|
+
const popoverScopeAttr = darkEnabled ? { [FORM_DARK_SCOPE_ATTR]: "" } : {};
|
|
1190
1591
|
const [currentValue, setCurrentValue] = useState(field.value || "");
|
|
1191
1592
|
useEffect(() => {
|
|
1192
1593
|
setCurrentValue(field.value || "");
|
|
1193
1594
|
}, [field.value]);
|
|
1194
1595
|
const options = (fieldDef.options || []).filter((opt) => opt.value !== "");
|
|
1195
1596
|
const displayName = ((_a = options.find((opt) => opt.value === currentValue)) == null ? void 0 : _a.label) || "";
|
|
1196
|
-
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle
|
|
1597
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
|
|
1197
1598
|
return /* @__PURE__ */ jsxs("div", { className: styles.wrapperClass, children: [
|
|
1198
1599
|
/* @__PURE__ */ jsxs(
|
|
1199
1600
|
Select.Root,
|
|
@@ -1205,43 +1606,43 @@ var SelectField = ({ field: fieldDef, disabled }) => {
|
|
|
1205
1606
|
},
|
|
1206
1607
|
value: currentValue,
|
|
1207
1608
|
children: [
|
|
1208
|
-
/* @__PURE__ */
|
|
1609
|
+
/* @__PURE__ */ jsxs(
|
|
1209
1610
|
"label",
|
|
1210
1611
|
{
|
|
1211
1612
|
htmlFor: fieldDef.id,
|
|
1212
1613
|
className: "relative block bg-inherit",
|
|
1213
|
-
children:
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1614
|
+
children: [
|
|
1615
|
+
/* @__PURE__ */ jsxs(
|
|
1616
|
+
Select.Trigger,
|
|
1617
|
+
{
|
|
1618
|
+
className: `${styles.inputClass} relative cursor-pointer text-left`,
|
|
1619
|
+
style: borderStyle,
|
|
1620
|
+
"aria-label": fieldDef.label,
|
|
1621
|
+
onFocus: () => setFocused(true),
|
|
1622
|
+
onBlur: () => {
|
|
1623
|
+
setFocused(false);
|
|
1624
|
+
helpers.setTouched(true);
|
|
1625
|
+
},
|
|
1626
|
+
children: [
|
|
1627
|
+
/* @__PURE__ */ jsx(Select.Value, { placeholder: "Choose an option", children: /* @__PURE__ */ jsx("span", { className: "block truncate", children: displayName }) }),
|
|
1628
|
+
/* @__PURE__ */ jsx(Select.Icon, { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsx(BsChevronDown, { style: { color: FORM_VAR.placeholder } }) })
|
|
1629
|
+
]
|
|
1630
|
+
}
|
|
1631
|
+
),
|
|
1632
|
+
/* @__PURE__ */ jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
|
|
1633
|
+
]
|
|
1231
1634
|
}
|
|
1232
1635
|
),
|
|
1233
1636
|
/* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsxs(
|
|
1234
1637
|
Select.Content,
|
|
1235
|
-
{
|
|
1638
|
+
__spreadProps(__spreadValues({
|
|
1236
1639
|
className: "z-20 rounded-md border p-3 shadow-lg",
|
|
1237
|
-
style: {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
color: formStyle.inputTextColor || "#1f2937"
|
|
1244
|
-
},
|
|
1640
|
+
style: __spreadProps(__spreadValues({}, popoverVars), {
|
|
1641
|
+
backgroundColor: `var(${FORM_CSS_VAR.inputBg}, #ffffff)`,
|
|
1642
|
+
borderColor: `var(${FORM_CSS_VAR.inputBorder}, #e5e7eb)`,
|
|
1643
|
+
color: `var(${FORM_CSS_VAR.inputText}, #1f2937)`
|
|
1644
|
+
})
|
|
1645
|
+
}, popoverScopeAttr), {
|
|
1245
1646
|
children: [
|
|
1246
1647
|
/* @__PURE__ */ jsx(Select.ScrollUpButton, { children: /* @__PURE__ */ jsx(BsChevronDown, { className: "rotate-180" }) }),
|
|
1247
1648
|
/* @__PURE__ */ jsx(Select.Viewport, { children: /* @__PURE__ */ jsx(Select.Group, { children: options.map((opt) => /* @__PURE__ */ jsxs(
|
|
@@ -1249,7 +1650,7 @@ var SelectField = ({ field: fieldDef, disabled }) => {
|
|
|
1249
1650
|
{
|
|
1250
1651
|
className: "relative m-1 flex cursor-pointer select-none justify-between rounded p-1 pr-8 hover:ring-1 focus:ring-1",
|
|
1251
1652
|
style: {
|
|
1252
|
-
"--tw-ring-color":
|
|
1653
|
+
"--tw-ring-color": `var(${FORM_CSS_VAR.inputFocusBorder}, #2563eb)`
|
|
1253
1654
|
},
|
|
1254
1655
|
value: opt.value,
|
|
1255
1656
|
children: [
|
|
@@ -1261,7 +1662,7 @@ var SelectField = ({ field: fieldDef, disabled }) => {
|
|
|
1261
1662
|
)) }) }),
|
|
1262
1663
|
/* @__PURE__ */ jsx(Select.ScrollDownButton, { children: /* @__PURE__ */ jsx(BsChevronDown, {}) })
|
|
1263
1664
|
]
|
|
1264
|
-
}
|
|
1665
|
+
})
|
|
1265
1666
|
) })
|
|
1266
1667
|
]
|
|
1267
1668
|
}
|
|
@@ -1274,11 +1675,19 @@ var CheckboxField = ({ field: fieldDef }) => {
|
|
|
1274
1675
|
const formStyle = useFormStyle();
|
|
1275
1676
|
const isChecked = field.value === true;
|
|
1276
1677
|
const isStacked = formStyle.inputVariant === "stacked";
|
|
1277
|
-
const
|
|
1678
|
+
const radiusStyle = resolveCustomRadius(formStyle) ? { borderRadius: FORM_RADIUS_VAR } : {};
|
|
1679
|
+
const checkboxStyle = isChecked ? __spreadProps(__spreadValues({}, radiusStyle), {
|
|
1680
|
+
borderColor: FORM_VAR.inputFocusBorder,
|
|
1681
|
+
backgroundColor: FORM_VAR.inputFocusBorder
|
|
1682
|
+
}) : __spreadProps(__spreadValues({}, radiusStyle), {
|
|
1683
|
+
borderColor: FORM_VAR.inputBorder,
|
|
1684
|
+
backgroundColor: FORM_VAR.inputBg
|
|
1685
|
+
});
|
|
1278
1686
|
return /* @__PURE__ */ jsxs(
|
|
1279
1687
|
"div",
|
|
1280
1688
|
{
|
|
1281
1689
|
className: twMerge(
|
|
1690
|
+
"bg-inherit",
|
|
1282
1691
|
isStacked ? "flex items-start gap-3" : "flex items-center gap-3 pt-3"
|
|
1283
1692
|
),
|
|
1284
1693
|
children: [
|
|
@@ -1292,8 +1701,8 @@ var CheckboxField = ({ field: fieldDef }) => {
|
|
|
1292
1701
|
helpers.setTouched(true, false);
|
|
1293
1702
|
},
|
|
1294
1703
|
className: twMerge(
|
|
1295
|
-
"flex h-5 w-5 items-center justify-center rounded border",
|
|
1296
|
-
isStacked && "mt-0.5
|
|
1704
|
+
"flex h-5 w-5 shrink-0 items-center justify-center rounded border",
|
|
1705
|
+
isStacked && "mt-0.5"
|
|
1297
1706
|
),
|
|
1298
1707
|
style: checkboxStyle,
|
|
1299
1708
|
children: /* @__PURE__ */ jsx(Checkbox.Indicator, { children: /* @__PURE__ */ jsx(BsCheck, { className: "text-white" }) })
|
|
@@ -1303,7 +1712,7 @@ var CheckboxField = ({ field: fieldDef }) => {
|
|
|
1303
1712
|
"label",
|
|
1304
1713
|
{
|
|
1305
1714
|
htmlFor: fieldDef.id,
|
|
1306
|
-
className: "cursor-pointer text-sm",
|
|
1715
|
+
className: "min-w-0 cursor-pointer text-sm",
|
|
1307
1716
|
style: { color: FORM_VAR.labelText },
|
|
1308
1717
|
children: fieldDef.label
|
|
1309
1718
|
}
|
|
@@ -1315,7 +1724,7 @@ var CheckboxField = ({ field: fieldDef }) => {
|
|
|
1315
1724
|
};
|
|
1316
1725
|
var RadioField = ({ field: fieldDef, disabled }) => {
|
|
1317
1726
|
const [field, meta, helpers] = useField(fieldDef.id);
|
|
1318
|
-
return /* @__PURE__ */ jsxs("div", { className: "pt-3", children: [
|
|
1727
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-inherit pt-3", children: [
|
|
1319
1728
|
/* @__PURE__ */ jsx(
|
|
1320
1729
|
"span",
|
|
1321
1730
|
{
|
|
@@ -1333,10 +1742,10 @@ var RadioField = ({ field: fieldDef, disabled }) => {
|
|
|
1333
1742
|
helpers.setValue(value);
|
|
1334
1743
|
helpers.setTouched(true, false);
|
|
1335
1744
|
},
|
|
1336
|
-
className: "flex flex-col gap-2",
|
|
1745
|
+
className: "flex flex-col gap-2 bg-inherit",
|
|
1337
1746
|
children: (fieldDef.options || []).map((opt) => {
|
|
1338
1747
|
const isSelected = field.value === opt.value;
|
|
1339
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1748
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 bg-inherit", children: [
|
|
1340
1749
|
/* @__PURE__ */ jsx(
|
|
1341
1750
|
RadioGroup.Item,
|
|
1342
1751
|
{
|
|
@@ -1395,13 +1804,126 @@ function nextBusinessDay(from) {
|
|
|
1395
1804
|
while (isWeekend(d)) d = addDays(d, 1);
|
|
1396
1805
|
return d;
|
|
1397
1806
|
}
|
|
1398
|
-
function
|
|
1807
|
+
function timeOnDay(value, onDay) {
|
|
1808
|
+
const parsed = parse(value, "HH:mm", onDay);
|
|
1809
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
1810
|
+
}
|
|
1811
|
+
function minutesOfDay(d) {
|
|
1812
|
+
return d.getHours() * 60 + d.getMinutes();
|
|
1813
|
+
}
|
|
1814
|
+
function minutesOfString(value) {
|
|
1815
|
+
const m = /^(\d{2}):(\d{2})$/.exec(value);
|
|
1816
|
+
if (!m) return null;
|
|
1817
|
+
const mins = Number(m[1]) * 60 + Number(m[2]);
|
|
1818
|
+
return Number.isFinite(mins) ? mins : null;
|
|
1819
|
+
}
|
|
1820
|
+
function windowOnDay(config, day) {
|
|
1821
|
+
const base = set(day, { seconds: 0, milliseconds: 0 });
|
|
1822
|
+
const min = (config == null ? void 0 : config.minTime) ? timeOnDay(config.minTime, base) : set(base, { hours: 0, minutes: 0 });
|
|
1823
|
+
const max = (config == null ? void 0 : config.maxTime) ? timeOnDay(config.maxTime, base) : set(base, { hours: 23, minutes: 59 });
|
|
1824
|
+
if (!min || !max || max < min) return null;
|
|
1825
|
+
return { min, max };
|
|
1826
|
+
}
|
|
1827
|
+
function lastSlotOnDay(config, day) {
|
|
1828
|
+
var _a;
|
|
1829
|
+
const bounds = windowOnDay(config, day);
|
|
1830
|
+
if (!bounds) return null;
|
|
1831
|
+
const intervalMs = Math.max(1, (_a = config == null ? void 0 : config.timeIntervals) != null ? _a : 30) * 6e4;
|
|
1832
|
+
const steps = Math.floor(
|
|
1833
|
+
(bounds.max.getTime() - bounds.min.getTime()) / intervalMs
|
|
1834
|
+
);
|
|
1835
|
+
return new Date(bounds.min.getTime() + steps * intervalMs);
|
|
1836
|
+
}
|
|
1837
|
+
function rangesOnDay(config, day) {
|
|
1838
|
+
const ranges = config == null ? void 0 : config.excludeTimeRanges;
|
|
1839
|
+
if (!ranges || ranges.length === 0) return [];
|
|
1840
|
+
const key = format(day, "yyyy-MM-dd");
|
|
1841
|
+
return ranges.filter((r) => r && r.date === key);
|
|
1842
|
+
}
|
|
1843
|
+
function isTimeExcluded(config, slot) {
|
|
1844
|
+
const ranges = rangesOnDay(config, slot);
|
|
1845
|
+
if (ranges.length === 0) return false;
|
|
1846
|
+
const at = minutesOfDay(slot);
|
|
1847
|
+
return ranges.some((r) => {
|
|
1848
|
+
const from = minutesOfString(r.from);
|
|
1849
|
+
const to = minutesOfString(r.to);
|
|
1850
|
+
if (from === null || to === null || to <= from) return false;
|
|
1851
|
+
return at >= from && at < to;
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
function hasSelectableSlot(config, day, options = {}, now = /* @__PURE__ */ new Date()) {
|
|
1855
|
+
var _a, _b, _c;
|
|
1856
|
+
const bounds = windowOnDay(config, day);
|
|
1857
|
+
if (!bounds) return true;
|
|
1858
|
+
const filterPast = (_b = (_a = options.filterPastTimes) != null ? _a : config == null ? void 0 : config.filterPastTimes) != null ? _b : true;
|
|
1859
|
+
const intervalMs = Math.max(1, (_c = config == null ? void 0 : config.timeIntervals) != null ? _c : 30) * 6e4;
|
|
1860
|
+
const last = lastSlotOnDay(config, day);
|
|
1861
|
+
if (!last) return true;
|
|
1862
|
+
for (let t = bounds.min.getTime(); t <= last.getTime(); t += intervalMs) {
|
|
1863
|
+
const slot = new Date(t);
|
|
1864
|
+
if (filterPast && slot.getTime() < now.getTime()) continue;
|
|
1865
|
+
if (isTimeExcluded(config, slot)) continue;
|
|
1866
|
+
return true;
|
|
1867
|
+
}
|
|
1868
|
+
return false;
|
|
1869
|
+
}
|
|
1870
|
+
function isDayExcluded(config, date, now = /* @__PURE__ */ new Date()) {
|
|
1399
1871
|
var _a, _b, _c, _d;
|
|
1872
|
+
if (((_a = config == null ? void 0 : config.excludeWeekends) != null ? _a : false) && isWeekend(date)) return true;
|
|
1873
|
+
if (((_b = config == null ? void 0 : config.excludeToday) != null ? _b : false) && isSameDay(date, now)) return true;
|
|
1874
|
+
if (((_c = config == null ? void 0 : config.excludeTomorrow) != null ? _c : false) && isSameDay(date, addDays(now, 1))) {
|
|
1875
|
+
return true;
|
|
1876
|
+
}
|
|
1877
|
+
if (((_d = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _d : false) && isSameDay(date, nextBusinessDay(now))) {
|
|
1878
|
+
return true;
|
|
1879
|
+
}
|
|
1880
|
+
const named = config == null ? void 0 : config.excludeDates;
|
|
1881
|
+
if (named && named.length > 0) {
|
|
1882
|
+
const key = format(date, "yyyy-MM-dd");
|
|
1883
|
+
if (named.some((d) => d === key)) return true;
|
|
1884
|
+
}
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1887
|
+
function buildTimeFilter(config, options = {}) {
|
|
1888
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1889
|
+
if (!((_b = (_a = options.showTimeSelect) != null ? _a : config == null ? void 0 : config.showTimeSelect) != null ? _b : true)) return void 0;
|
|
1890
|
+
const filterPast = (_d = (_c = options.filterPastTimes) != null ? _c : config == null ? void 0 : config.filterPastTimes) != null ? _d : true;
|
|
1891
|
+
const hasRanges = ((_f = (_e = config == null ? void 0 : config.excludeTimeRanges) == null ? void 0 : _e.length) != null ? _f : 0) > 0;
|
|
1892
|
+
const hasDayRules = ((_g = config == null ? void 0 : config.excludeWeekends) != null ? _g : false) || ((_h = config == null ? void 0 : config.excludeToday) != null ? _h : false) || ((_i = config == null ? void 0 : config.excludeTomorrow) != null ? _i : false) || ((_j = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _j : false) || ((_l = (_k = config == null ? void 0 : config.excludeDates) == null ? void 0 : _k.length) != null ? _l : 0) > 0;
|
|
1893
|
+
if (!filterPast && !hasRanges && !hasDayRules) return void 0;
|
|
1894
|
+
return (time) => {
|
|
1895
|
+
const now = /* @__PURE__ */ new Date();
|
|
1896
|
+
if (filterPast && time.getTime() < now.getTime()) return false;
|
|
1897
|
+
if (hasDayRules && isDayExcluded(config, time, now)) return false;
|
|
1898
|
+
if (hasRanges && isTimeExcluded(config, time)) return false;
|
|
1899
|
+
return true;
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
function firstSelectableDay(config, options = {}, from = /* @__PURE__ */ new Date(), limit = 370) {
|
|
1903
|
+
const filter = buildDateFilter(config, options);
|
|
1904
|
+
let day = new Date(from.getFullYear(), from.getMonth(), from.getDate());
|
|
1905
|
+
for (let i = 0; i < limit; i += 1) {
|
|
1906
|
+
if (!filter || filter(day)) return day;
|
|
1907
|
+
day = addDays(day, 1);
|
|
1908
|
+
}
|
|
1909
|
+
return null;
|
|
1910
|
+
}
|
|
1911
|
+
function buildDateFilter(config, options = {}) {
|
|
1912
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1400
1913
|
const excludeWeekends = (_a = config == null ? void 0 : config.excludeWeekends) != null ? _a : false;
|
|
1401
1914
|
const excludeToday = (_b = config == null ? void 0 : config.excludeToday) != null ? _b : false;
|
|
1402
1915
|
const excludeTomorrow = (_c = config == null ? void 0 : config.excludeTomorrow) != null ? _c : false;
|
|
1403
1916
|
const excludeNext = (_d = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _d : false;
|
|
1404
|
-
|
|
1917
|
+
const excludedDays = new Set(
|
|
1918
|
+
((_e = config == null ? void 0 : config.excludeDates) != null ? _e : []).filter(
|
|
1919
|
+
(d) => typeof d === "string" && d.length === 10
|
|
1920
|
+
)
|
|
1921
|
+
);
|
|
1922
|
+
const timeSelect = (_g = (_f = options.showTimeSelect) != null ? _f : config == null ? void 0 : config.showTimeSelect) != null ? _g : true;
|
|
1923
|
+
const filterPast = (_i = (_h = options.filterPastTimes) != null ? _h : config == null ? void 0 : config.filterPastTimes) != null ? _i : true;
|
|
1924
|
+
const hasRanges = ((_k = (_j = config == null ? void 0 : config.excludeTimeRanges) == null ? void 0 : _j.length) != null ? _k : 0) > 0;
|
|
1925
|
+
const checkSlots = timeSelect && (filterPast || hasRanges);
|
|
1926
|
+
if (!excludeWeekends && !excludeToday && !excludeTomorrow && !excludeNext && !checkSlots && excludedDays.size === 0) {
|
|
1405
1927
|
return void 0;
|
|
1406
1928
|
}
|
|
1407
1929
|
return (date) => {
|
|
@@ -1410,6 +1932,15 @@ function buildDateFilter(config) {
|
|
|
1410
1932
|
if (excludeToday && isSameDay(date, now)) return false;
|
|
1411
1933
|
if (excludeTomorrow && isSameDay(date, addDays(now, 1))) return false;
|
|
1412
1934
|
if (excludeNext && isSameDay(date, nextBusinessDay(now))) return false;
|
|
1935
|
+
if (excludedDays.size > 0 && excludedDays.has(format(date, "yyyy-MM-dd"))) {
|
|
1936
|
+
return false;
|
|
1937
|
+
}
|
|
1938
|
+
if (checkSlots) {
|
|
1939
|
+
const needsCheck = filterPast && isSameDay(date, now) || hasRanges && rangesOnDay(config, date).length > 0;
|
|
1940
|
+
if (needsCheck && !hasSelectableSlot(config, date, options, now)) {
|
|
1941
|
+
return false;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1413
1944
|
return true;
|
|
1414
1945
|
};
|
|
1415
1946
|
}
|
|
@@ -1433,7 +1964,7 @@ var DateTimeField = ({
|
|
|
1433
1964
|
dateOnly = false,
|
|
1434
1965
|
disabled
|
|
1435
1966
|
}) => {
|
|
1436
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1967
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1437
1968
|
const [field, meta, helpers] = useField(fieldDef.id);
|
|
1438
1969
|
const [focused, setFocused] = useState(false);
|
|
1439
1970
|
const formStyle = useFormStyle();
|
|
@@ -1450,11 +1981,15 @@ var DateTimeField = ({
|
|
|
1450
1981
|
const maxTime = showTimeSelect ? parseTimeString(config.maxTime, 23, 59) : void 0;
|
|
1451
1982
|
const minDate = excludePastDates ? /* @__PURE__ */ new Date() : void 0;
|
|
1452
1983
|
const selected = parseStoredValue(field.value);
|
|
1453
|
-
const filterDate = buildDateFilter(config
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1984
|
+
const filterDate = buildDateFilter(config, {
|
|
1985
|
+
showTimeSelect,
|
|
1986
|
+
filterPastTimes
|
|
1987
|
+
});
|
|
1988
|
+
const filterTime = buildTimeFilter(config, {
|
|
1989
|
+
showTimeSelect,
|
|
1990
|
+
filterPastTimes
|
|
1991
|
+
});
|
|
1992
|
+
const openToDate = selected || !filterDate ? void 0 : (_i = firstSelectableDay(config, { showTimeSelect, filterPastTimes })) != null ? _i : void 0;
|
|
1458
1993
|
const handleChange = (date) => {
|
|
1459
1994
|
if (!date) {
|
|
1460
1995
|
helpers.setValue("");
|
|
@@ -1462,11 +1997,15 @@ var DateTimeField = ({
|
|
|
1462
1997
|
}
|
|
1463
1998
|
helpers.setValue(dateOnly ? format(date, "yyyy-MM-dd") : date.toISOString());
|
|
1464
1999
|
};
|
|
1465
|
-
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle
|
|
1466
|
-
const pickerProps = {
|
|
2000
|
+
const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
|
|
2001
|
+
const pickerProps = __spreadProps(__spreadValues({
|
|
1467
2002
|
id: fieldDef.id,
|
|
1468
2003
|
name: fieldDef.id,
|
|
1469
2004
|
wrapperClassName: "block w-full",
|
|
2005
|
+
// react-datepicker's stylesheet pins the popper at z-index 1, below the
|
|
2006
|
+
// z-10 floating labels in useInputStyles — neighboring fields' labels
|
|
2007
|
+
// would paint over the open calendar.
|
|
2008
|
+
popperClassName: "!z-50",
|
|
1470
2009
|
disabled,
|
|
1471
2010
|
selected,
|
|
1472
2011
|
onChange: handleChange,
|
|
@@ -1477,15 +2016,16 @@ var DateTimeField = ({
|
|
|
1477
2016
|
},
|
|
1478
2017
|
showTimeSelect,
|
|
1479
2018
|
timeIntervals,
|
|
1480
|
-
minDate
|
|
2019
|
+
minDate
|
|
2020
|
+
}, openToDate ? { openToDate } : {}), {
|
|
1481
2021
|
minTime,
|
|
1482
2022
|
maxTime,
|
|
1483
2023
|
filterDate,
|
|
1484
|
-
filterTime
|
|
2024
|
+
filterTime,
|
|
1485
2025
|
dateFormat,
|
|
1486
2026
|
placeholderText,
|
|
1487
2027
|
autoComplete: "off"
|
|
1488
|
-
};
|
|
2028
|
+
});
|
|
1489
2029
|
if (styles.isStacked) {
|
|
1490
2030
|
return /* @__PURE__ */ jsxs("div", { className: styles.wrapperClass, children: [
|
|
1491
2031
|
/* @__PURE__ */ jsx(
|
|
@@ -1512,7 +2052,7 @@ var DateTimeField = ({
|
|
|
1512
2052
|
hasError && /* @__PURE__ */ jsx(
|
|
1513
2053
|
"span",
|
|
1514
2054
|
{
|
|
1515
|
-
className:
|
|
2055
|
+
className: "mt-1 text-xs",
|
|
1516
2056
|
style: styles.errorStyle,
|
|
1517
2057
|
children: meta.error
|
|
1518
2058
|
}
|
|
@@ -1550,7 +2090,7 @@ var DateTimeField = ({
|
|
|
1550
2090
|
}
|
|
1551
2091
|
)
|
|
1552
2092
|
] }),
|
|
1553
|
-
hasError && /* @__PURE__ */ jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
2093
|
+
hasError && /* @__PURE__ */ jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1554
2094
|
] });
|
|
1555
2095
|
};
|
|
1556
2096
|
var DateField = ({ field, disabled }) => {
|
|
@@ -1576,13 +2116,12 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
|
1576
2116
|
);
|
|
1577
2117
|
helpers.setValue(next);
|
|
1578
2118
|
};
|
|
1579
|
-
const borderStyle = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle
|
|
2119
|
+
const borderStyle = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle)), {
|
|
1580
2120
|
paddingRight: "2.75rem"
|
|
1581
2121
|
});
|
|
1582
2122
|
const inputType = reveal ? "text" : "password";
|
|
1583
2123
|
const inputProps = {
|
|
1584
2124
|
id: fieldDef.id,
|
|
1585
|
-
name: fieldDef.id,
|
|
1586
2125
|
type: inputType,
|
|
1587
2126
|
disabled,
|
|
1588
2127
|
autoComplete: "off",
|
|
@@ -1591,9 +2130,9 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
|
1591
2130
|
value: field.value,
|
|
1592
2131
|
onChange: handleChange,
|
|
1593
2132
|
onFocus: () => setFocused(true),
|
|
1594
|
-
onBlur: (
|
|
2133
|
+
onBlur: () => {
|
|
1595
2134
|
setFocused(false);
|
|
1596
|
-
|
|
2135
|
+
helpers.setTouched(true);
|
|
1597
2136
|
},
|
|
1598
2137
|
"aria-describedby": `${fieldDef.id}-secure`,
|
|
1599
2138
|
"data-sensitive": "true"
|
|
@@ -1610,7 +2149,11 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
|
1610
2149
|
{
|
|
1611
2150
|
type: "button",
|
|
1612
2151
|
onClick: () => setReveal((r) => !r),
|
|
1613
|
-
className:
|
|
2152
|
+
className: twMerge(
|
|
2153
|
+
"flex h-7 w-7 items-center justify-center rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60",
|
|
2154
|
+
FORM_MUTED_TEXT_CLASS,
|
|
2155
|
+
FORM_SUBTLE_HOVER_FILL_CLASS
|
|
2156
|
+
),
|
|
1614
2157
|
"aria-pressed": reveal,
|
|
1615
2158
|
"aria-label": reveal ? "Hide value" : "Show value",
|
|
1616
2159
|
children: reveal ? /* @__PURE__ */ jsx(FiEyeOff, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsx(FiEye, { size: 16, "aria-hidden": "true" })
|
|
@@ -1623,7 +2166,8 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
|
1623
2166
|
{
|
|
1624
2167
|
id: `${fieldDef.id}-secure`,
|
|
1625
2168
|
className: twMerge(
|
|
1626
|
-
"flex items-center gap-1 text-xs
|
|
2169
|
+
"flex items-center gap-1 text-xs",
|
|
2170
|
+
FORM_MUTED_TEXT_CLASS,
|
|
1627
2171
|
className
|
|
1628
2172
|
),
|
|
1629
2173
|
children: [
|
|
@@ -1647,14 +2191,14 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
|
1647
2191
|
/* @__PURE__ */ jsx("label", { htmlFor: fieldDef.id, className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label }),
|
|
1648
2192
|
renderSecureHint("mb-1")
|
|
1649
2193
|
] }),
|
|
1650
|
-
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
2194
|
+
/* @__PURE__ */ jsxs("div", { className: "relative bg-inherit", children: [
|
|
1651
2195
|
/* @__PURE__ */ jsx("input", __spreadValues({ className: styles.inputClass, style: borderStyle }, inputProps)),
|
|
1652
2196
|
renderToggle()
|
|
1653
2197
|
] }),
|
|
1654
2198
|
hasError && /* @__PURE__ */ jsx(
|
|
1655
2199
|
"span",
|
|
1656
2200
|
{
|
|
1657
|
-
className:
|
|
2201
|
+
className: "mt-1 text-xs",
|
|
1658
2202
|
style: styles.errorStyle,
|
|
1659
2203
|
children: meta.error
|
|
1660
2204
|
}
|
|
@@ -1668,9 +2212,13 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
|
|
|
1668
2212
|
/* @__PURE__ */ jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label }),
|
|
1669
2213
|
renderToggle("mb-3")
|
|
1670
2214
|
] }),
|
|
1671
|
-
hasError && /* @__PURE__ */ jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
2215
|
+
hasError && /* @__PURE__ */ jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
|
|
1672
2216
|
] });
|
|
1673
2217
|
};
|
|
2218
|
+
var FormFileUploadContext = createContext({});
|
|
2219
|
+
var useFormFileUpload = () => useContext(FormFileUploadContext);
|
|
2220
|
+
var FormFileUploadProvider = FormFileUploadContext.Provider;
|
|
2221
|
+
var NO_UPLOADER_MESSAGE = "File uploads aren't configured for this form.";
|
|
1674
2222
|
function formatBytes(bytes) {
|
|
1675
2223
|
if (bytes < 1024) return `${bytes} B`;
|
|
1676
2224
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
@@ -1690,21 +2238,36 @@ function matchesAccept(file, accept) {
|
|
|
1690
2238
|
});
|
|
1691
2239
|
}
|
|
1692
2240
|
var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
1693
|
-
var _a, _b, _c, _d;
|
|
2241
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1694
2242
|
const [, meta, helpers] = useField(fieldDef.id);
|
|
1695
2243
|
const { setFieldTouched } = useFormikContext();
|
|
2244
|
+
const { upload: contextUpload, allowObjectUrlFallback } = useFormFileUpload();
|
|
1696
2245
|
const inputRef = useRef(null);
|
|
1697
2246
|
const [uploading, setUploading] = useState(false);
|
|
1698
2247
|
const [uploadError, setUploadError] = useState(null);
|
|
1699
2248
|
const [files, setFiles] = useState([]);
|
|
2249
|
+
const uploader = onUpload != null ? onUpload : contextUpload;
|
|
2250
|
+
const uploadsUnavailable = !uploader && !allowObjectUrlFallback;
|
|
2251
|
+
useEffect(() => {
|
|
2252
|
+
if (!uploadsUnavailable) return;
|
|
2253
|
+
console.warn(
|
|
2254
|
+
`[forms] Field "${fieldDef.id}" is a file field but no upload path is configured. Pass onFileUpload or fileUploadRoute to <DynamicForm> (or onUpload to <FileField>) to enable it.`
|
|
2255
|
+
);
|
|
2256
|
+
}, [uploadsUnavailable, fieldDef.id]);
|
|
1700
2257
|
const config = __spreadValues(__spreadValues({}, DEFAULT_FILE_FIELD_CONFIG), fieldDef.fileConfig);
|
|
1701
2258
|
const maxSizeBytes = (_a = config.maxSizeBytes) != null ? _a : 10 * 1024 * 1024;
|
|
1702
2259
|
const multiple = (_b = config.multiple) != null ? _b : false;
|
|
1703
2260
|
const maxFiles = (_c = config.maxFiles) != null ? _c : 5;
|
|
2261
|
+
const resizeImages = (_d = config.resizeImages) != null ? _d : true;
|
|
2262
|
+
const maxImageWidth = (_e = config.maxImageWidth) != null ? _e : 1600;
|
|
1704
2263
|
const handleFiles = useCallback(
|
|
1705
2264
|
(fileList) => __async(null, null, function* () {
|
|
1706
2265
|
var _a2, _b2;
|
|
1707
2266
|
if (!fileList || fileList.length === 0) return;
|
|
2267
|
+
if (uploadsUnavailable) {
|
|
2268
|
+
setUploadError(NO_UPLOADER_MESSAGE);
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
1708
2271
|
setUploadError(null);
|
|
1709
2272
|
const toUpload = Array.from(fileList);
|
|
1710
2273
|
if (multiple && files.length + toUpload.length > maxFiles) {
|
|
@@ -1717,24 +2280,20 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1717
2280
|
setUploadError(`"${file.name}" is not an accepted file type.`);
|
|
1718
2281
|
continue;
|
|
1719
2282
|
}
|
|
1720
|
-
if (file.size > maxSizeBytes) {
|
|
1721
|
-
setUploadError(
|
|
1722
|
-
`"${file.name}" exceeds ${formatBytes(maxSizeBytes)} limit.`
|
|
1723
|
-
);
|
|
1724
|
-
continue;
|
|
1725
|
-
}
|
|
1726
2283
|
setUploading(true);
|
|
1727
2284
|
try {
|
|
1728
|
-
|
|
1729
|
-
if (
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
name: file.name,
|
|
1735
|
-
size: file.size
|
|
1736
|
-
};
|
|
2285
|
+
const prepared = resizeImages ? yield resizeImageFile(file, maxImageWidth) : file;
|
|
2286
|
+
if (prepared.size > maxSizeBytes) {
|
|
2287
|
+
setUploadError(
|
|
2288
|
+
`"${file.name}" exceeds ${formatBytes(maxSizeBytes)} limit.`
|
|
2289
|
+
);
|
|
2290
|
+
continue;
|
|
1737
2291
|
}
|
|
2292
|
+
const result = uploader ? yield uploader(prepared, config) : {
|
|
2293
|
+
url: URL.createObjectURL(prepared),
|
|
2294
|
+
name: prepared.name,
|
|
2295
|
+
size: prepared.size
|
|
2296
|
+
};
|
|
1738
2297
|
current = multiple ? [...current, result] : [result];
|
|
1739
2298
|
} catch (err) {
|
|
1740
2299
|
setUploadError(`Upload failed: ${err.message}`);
|
|
@@ -1753,8 +2312,11 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1753
2312
|
multiple,
|
|
1754
2313
|
maxFiles,
|
|
1755
2314
|
maxSizeBytes,
|
|
2315
|
+
resizeImages,
|
|
2316
|
+
maxImageWidth,
|
|
1756
2317
|
config,
|
|
1757
|
-
|
|
2318
|
+
uploader,
|
|
2319
|
+
uploadsUnavailable,
|
|
1758
2320
|
helpers,
|
|
1759
2321
|
fieldDef.id,
|
|
1760
2322
|
setFieldTouched
|
|
@@ -1769,7 +2331,8 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1769
2331
|
[files, multiple, helpers]
|
|
1770
2332
|
);
|
|
1771
2333
|
const hasError = meta.touched && meta.error;
|
|
1772
|
-
const isRequired = (
|
|
2334
|
+
const isRequired = (_f = fieldDef.validation) == null ? void 0 : _f.some((v) => v.type === "required");
|
|
2335
|
+
const pickerDisabled = disabled || uploadsUnavailable;
|
|
1773
2336
|
return /* @__PURE__ */ jsxs("div", { children: [
|
|
1774
2337
|
/* @__PURE__ */ jsxs(
|
|
1775
2338
|
"label",
|
|
@@ -1787,19 +2350,21 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1787
2350
|
"p",
|
|
1788
2351
|
{
|
|
1789
2352
|
className: "mb-2 text-xs",
|
|
1790
|
-
style: { color:
|
|
2353
|
+
style: { color: FORM_VAR.placeholder },
|
|
1791
2354
|
children: fieldDef.helpText
|
|
1792
2355
|
}
|
|
1793
2356
|
),
|
|
1794
2357
|
/* @__PURE__ */ jsxs(
|
|
1795
2358
|
"div",
|
|
1796
2359
|
{
|
|
1797
|
-
className: `relative rounded-lg border-2 border-dashed p-6 text-center transition-colors ${hasError ? "border-red-400" : "border-
|
|
2360
|
+
className: `relative rounded-lg border-2 border-dashed p-6 text-center transition-colors ${hasError ? "border-red-400" : pickerDisabled ? "border-current/10" : "border-current/25 hover:border-current/40"}`,
|
|
1798
2361
|
onDragOver: (e) => {
|
|
2362
|
+
if (pickerDisabled) return;
|
|
1799
2363
|
e.preventDefault();
|
|
1800
2364
|
e.stopPropagation();
|
|
1801
2365
|
},
|
|
1802
2366
|
onDrop: (e) => {
|
|
2367
|
+
if (pickerDisabled) return;
|
|
1803
2368
|
e.preventDefault();
|
|
1804
2369
|
e.stopPropagation();
|
|
1805
2370
|
handleFiles(e.dataTransfer.files);
|
|
@@ -1813,7 +2378,7 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1813
2378
|
type: "file",
|
|
1814
2379
|
accept: config.accept,
|
|
1815
2380
|
multiple,
|
|
1816
|
-
disabled,
|
|
2381
|
+
disabled: pickerDisabled,
|
|
1817
2382
|
onChange: (e) => {
|
|
1818
2383
|
handleFiles(e.target.files);
|
|
1819
2384
|
e.target.value = "";
|
|
@@ -1822,9 +2387,15 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1822
2387
|
}
|
|
1823
2388
|
),
|
|
1824
2389
|
uploading ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
1825
|
-
/* @__PURE__ */ jsx(
|
|
1826
|
-
|
|
1827
|
-
|
|
2390
|
+
/* @__PURE__ */ jsx(
|
|
2391
|
+
"div",
|
|
2392
|
+
{
|
|
2393
|
+
className: `mx-auto h-1.5 w-32 overflow-hidden rounded-full ${FORM_SUBTLE_FILL_CLASS}`,
|
|
2394
|
+
children: /* @__PURE__ */ jsx("div", { className: "h-full w-1/3 animate-pulse rounded-full bg-indigo-500" })
|
|
2395
|
+
}
|
|
2396
|
+
),
|
|
2397
|
+
/* @__PURE__ */ jsx("p", { className: `text-sm ${FORM_MUTED_TEXT_CLASS}`, children: "Uploading\u2026" })
|
|
2398
|
+
] }) : uploadsUnavailable ? /* @__PURE__ */ jsx("p", { className: `text-sm ${FORM_MUTED_TEXT_CLASS}`, children: NO_UPLOADER_MESSAGE }) : /* @__PURE__ */ jsxs(
|
|
1828
2399
|
"button",
|
|
1829
2400
|
{
|
|
1830
2401
|
type: "button",
|
|
@@ -1833,12 +2404,12 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1833
2404
|
return (_a2 = inputRef.current) == null ? void 0 : _a2.click();
|
|
1834
2405
|
},
|
|
1835
2406
|
disabled,
|
|
1836
|
-
className:
|
|
2407
|
+
className: `cursor-pointer text-sm ${FORM_MUTED_TEXT_CLASS} hover:text-current disabled:cursor-not-allowed disabled:opacity-50`,
|
|
1837
2408
|
children: [
|
|
1838
2409
|
/* @__PURE__ */ jsx(
|
|
1839
2410
|
"svg",
|
|
1840
2411
|
{
|
|
1841
|
-
className:
|
|
2412
|
+
className: `mx-auto mb-2 h-8 w-8 ${FORM_FAINT_TEXT_CLASS}`,
|
|
1842
2413
|
fill: "none",
|
|
1843
2414
|
viewBox: "0 0 24 24",
|
|
1844
2415
|
strokeWidth: 1.5,
|
|
@@ -1856,7 +2427,7 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1856
2427
|
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "Click to upload" }),
|
|
1857
2428
|
" or drag and drop",
|
|
1858
2429
|
/* @__PURE__ */ jsx("br", {}),
|
|
1859
|
-
/* @__PURE__ */ jsxs("span", { className:
|
|
2430
|
+
/* @__PURE__ */ jsxs("span", { className: `text-xs ${FORM_FAINT_TEXT_CLASS}`, children: [
|
|
1860
2431
|
"Max ",
|
|
1861
2432
|
formatBytes(maxSizeBytes),
|
|
1862
2433
|
multiple && ` \xB7 Up to ${maxFiles} files`
|
|
@@ -1870,7 +2441,7 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1870
2441
|
files.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-3 space-y-2", children: files.map((f, i) => /* @__PURE__ */ jsxs(
|
|
1871
2442
|
"div",
|
|
1872
2443
|
{
|
|
1873
|
-
className:
|
|
2444
|
+
className: `flex items-center gap-3 rounded-md border ${FORM_SUBTLE_BORDER_CLASS} ${FORM_SUBTLE_FILL_CLASS} px-3 py-2`,
|
|
1874
2445
|
children: [
|
|
1875
2446
|
f.url && f.name.match(/\.(jpg|jpeg|png|webp|gif|svg)$/i) && // eslint-disable-next-line @next/next/no-img-element
|
|
1876
2447
|
/* @__PURE__ */ jsx(
|
|
@@ -1882,15 +2453,15 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
|
|
|
1882
2453
|
}
|
|
1883
2454
|
),
|
|
1884
2455
|
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
1885
|
-
/* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium
|
|
1886
|
-
/* @__PURE__ */ jsx("p", { className:
|
|
2456
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium", children: f.name }),
|
|
2457
|
+
/* @__PURE__ */ jsx("p", { className: `text-xs ${FORM_MUTED_TEXT_CLASS}`, children: formatBytes(f.size) })
|
|
1887
2458
|
] }),
|
|
1888
2459
|
/* @__PURE__ */ jsx(
|
|
1889
2460
|
"button",
|
|
1890
2461
|
{
|
|
1891
2462
|
type: "button",
|
|
1892
2463
|
onClick: () => removeFile(i),
|
|
1893
|
-
className:
|
|
2464
|
+
className: `cursor-pointer ${FORM_FAINT_TEXT_CLASS} hover:text-red-500`,
|
|
1894
2465
|
"aria-label": `Remove ${f.name}`,
|
|
1895
2466
|
children: /* @__PURE__ */ jsx(
|
|
1896
2467
|
"svg",
|
|
@@ -1935,6 +2506,8 @@ var fieldComponents = {
|
|
|
1935
2506
|
datetime: DateTimeField,
|
|
1936
2507
|
hidden: HiddenField,
|
|
1937
2508
|
sensitive: SensitiveField,
|
|
2509
|
+
// Its `onUpload`/`projectId` props are optional and normally arrive by
|
|
2510
|
+
// context (see FileUploadContext), so it fits the shared signature.
|
|
1938
2511
|
file: FileField
|
|
1939
2512
|
};
|
|
1940
2513
|
var DynamicFormField = ({ field, mirrored, mirrorBehavior }) => {
|
|
@@ -1966,12 +2539,13 @@ var DynamicFormField = ({ field, mirrored, mirrorBehavior }) => {
|
|
|
1966
2539
|
};
|
|
1967
2540
|
const widthClass = widthClasses[((_a = field.layout) == null ? void 0 : _a.width) || "full"] || "md:col-span-6";
|
|
1968
2541
|
const description = (_b = field.description) != null ? _b : field.helpText;
|
|
1969
|
-
return /* @__PURE__ */ jsxs("div", { className: widthClass, children: [
|
|
2542
|
+
return /* @__PURE__ */ jsxs("div", { className: twMerge(widthClass, "bg-inherit"), children: [
|
|
1970
2543
|
/* @__PURE__ */ jsx(Component, { field, disabled: locked }),
|
|
1971
|
-
description && /* @__PURE__ */ jsx("p", { className: twMerge("mt-1 text-xs",
|
|
2544
|
+
description && /* @__PURE__ */ jsx("p", { className: twMerge("mt-1 text-xs", FORM_MUTED_TEXT_CLASS), children: description })
|
|
1972
2545
|
] });
|
|
1973
2546
|
};
|
|
1974
2547
|
var spacingGap = {
|
|
2548
|
+
none: "gap-4",
|
|
1975
2549
|
compact: "gap-2",
|
|
1976
2550
|
normal: "gap-4",
|
|
1977
2551
|
relaxed: "gap-6"
|
|
@@ -1980,12 +2554,12 @@ var DynamicFormSection = ({
|
|
|
1980
2554
|
section,
|
|
1981
2555
|
isLast,
|
|
1982
2556
|
formDefaultTextColor,
|
|
2557
|
+
formDefaultTextColorDark,
|
|
1983
2558
|
inlineSubmit
|
|
1984
2559
|
}) => {
|
|
1985
|
-
var _a
|
|
2560
|
+
var _a;
|
|
1986
2561
|
const style = useFormStyle();
|
|
1987
|
-
const
|
|
1988
|
-
const previewTextColor = previewOverrides == null ? void 0 : previewOverrides.textColor;
|
|
2562
|
+
const { forced, darkEnabled } = useFormColorScheme();
|
|
1989
2563
|
const { values, setFieldValue } = useFormikContext();
|
|
1990
2564
|
const sameAs = section.sameAs;
|
|
1991
2565
|
const toggleKey = sameAs ? sameAsToggleKey(section.id) : "";
|
|
@@ -2004,35 +2578,44 @@ var DynamicFormSection = ({
|
|
|
2004
2578
|
setFieldValue(targetId, (_a2 = values[sourceId]) != null ? _a2 : "");
|
|
2005
2579
|
}
|
|
2006
2580
|
}, [toggleOn, sourceSignature]);
|
|
2007
|
-
const
|
|
2581
|
+
const formDefaults = {
|
|
2582
|
+
light: formDefaultTextColor,
|
|
2583
|
+
dark: formDefaultTextColorDark
|
|
2584
|
+
};
|
|
2585
|
+
const effectiveTextColor = resolveSectionTextColor(
|
|
2586
|
+
section,
|
|
2587
|
+
formDefaults,
|
|
2588
|
+
forced != null ? forced : "light"
|
|
2589
|
+
);
|
|
2590
|
+
const darkTextColor = darkEnabled && (section.textColorDark || formDefaultTextColorDark) ? resolveSectionTextColor(section, formDefaults, "dark") : void 0;
|
|
2008
2591
|
const sortedFields = [...section.fields].sort(
|
|
2009
2592
|
(a, b) => {
|
|
2010
|
-
var _a2,
|
|
2011
|
-
return ((
|
|
2593
|
+
var _a2, _b, _c, _d;
|
|
2594
|
+
return ((_b = (_a2 = a.layout) == null ? void 0 : _a2.order) != null ? _b : 0) - ((_d = (_c = b.layout) == null ? void 0 : _c.order) != null ? _d : 0);
|
|
2012
2595
|
}
|
|
2013
2596
|
);
|
|
2014
|
-
const
|
|
2597
|
+
const customGap = resolveCustomGap(style);
|
|
2598
|
+
const gap = customGap ? "gap-0" : spacingGap[style.spacing || "normal"];
|
|
2599
|
+
const gapStyle = customGap ? { gap: FORM_GAP_VAR } : {};
|
|
2015
2600
|
const divider = style.sectionDividers && !isLast;
|
|
2016
2601
|
const isStacked = style.inputVariant === "stacked";
|
|
2017
2602
|
const sectionWrapperClass = twMerge(
|
|
2603
|
+
"bg-inherit",
|
|
2018
2604
|
isStacked ? "space-y-4" : "mb-6",
|
|
2019
|
-
divider &&
|
|
2020
|
-
);
|
|
2021
|
-
const titleClass = twMerge(
|
|
2022
|
-
"text-lg font-semibold",
|
|
2023
|
-
effectiveTextColor ? "" : "text-gray-800 dark:text-zinc-100",
|
|
2024
|
-
!isStacked && "mb-1"
|
|
2605
|
+
divider && `border-b ${FORM_SUBTLE_BORDER_CLASS} pb-6`
|
|
2025
2606
|
);
|
|
2607
|
+
const titleClass = twMerge("text-lg font-semibold", !isStacked && "mb-1");
|
|
2026
2608
|
const descriptionClass = twMerge(
|
|
2027
2609
|
"text-sm",
|
|
2028
|
-
effectiveTextColor ? "" :
|
|
2610
|
+
effectiveTextColor ? "" : FORM_MUTED_TEXT_CLASS,
|
|
2029
2611
|
!isStacked && "mb-4"
|
|
2030
2612
|
);
|
|
2031
|
-
const textStyle = effectiveTextColor ? { color: effectiveTextColor } : void 0;
|
|
2613
|
+
const textStyle = effectiveTextColor || darkTextColor ? __spreadValues(__spreadValues({}, effectiveTextColor ? { color: effectiveTextColor } : {}), darkTextColor ? { [FORM_DARK_TEXT_VAR]: darkTextColor } : {}) : void 0;
|
|
2614
|
+
const darkTextAttr = darkTextColor ? { [FORM_DARK_TEXT_ATTR]: "" } : {};
|
|
2032
2615
|
return /* @__PURE__ */ jsxs("fieldset", { className: sectionWrapperClass, children: [
|
|
2033
|
-
section.title && /* @__PURE__ */ jsx("legend", { className: titleClass, style: textStyle, children: section.title }),
|
|
2034
|
-
section.description && /* @__PURE__ */ jsx("p", { className: descriptionClass, style: textStyle, children: section.description }),
|
|
2035
|
-
sameAs && /* @__PURE__ */ jsxs("div", { className: "mb-4 flex items-center gap-3", children: [
|
|
2616
|
+
section.title && /* @__PURE__ */ jsx("legend", __spreadProps(__spreadValues({ className: titleClass, style: textStyle }, darkTextAttr), { children: section.title })),
|
|
2617
|
+
section.description && /* @__PURE__ */ jsx("p", __spreadProps(__spreadValues({ className: descriptionClass, style: textStyle }, darkTextAttr), { children: section.description })),
|
|
2618
|
+
sameAs && /* @__PURE__ */ jsxs("div", { className: "mb-4 flex items-center gap-3 bg-inherit", children: [
|
|
2036
2619
|
/* @__PURE__ */ jsx(
|
|
2037
2620
|
Checkbox.Root,
|
|
2038
2621
|
{
|
|
@@ -2059,10 +2642,11 @@ var DynamicFormSection = ({
|
|
|
2059
2642
|
"div",
|
|
2060
2643
|
{
|
|
2061
2644
|
className: twMerge(
|
|
2062
|
-
"grid grid-cols-1 md:grid-cols-6",
|
|
2645
|
+
"grid grid-cols-1 bg-inherit md:grid-cols-6",
|
|
2063
2646
|
gap,
|
|
2064
2647
|
inlineSubmit && "min-w-0 flex-auto"
|
|
2065
2648
|
),
|
|
2649
|
+
style: gapStyle,
|
|
2066
2650
|
children: sortedFields.map((field, i) => /* @__PURE__ */ jsx(
|
|
2067
2651
|
DynamicFormField,
|
|
2068
2652
|
{
|
|
@@ -2074,17 +2658,108 @@ var DynamicFormSection = ({
|
|
|
2074
2658
|
))
|
|
2075
2659
|
}
|
|
2076
2660
|
);
|
|
2077
|
-
return inlineSubmit ? /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
2661
|
+
return inlineSubmit ? /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3 bg-inherit", children: [
|
|
2078
2662
|
fieldsGrid,
|
|
2079
|
-
/* @__PURE__ */ jsx("div", { className: twMerge("flex-none", !isStacked && "pt-3"), children: inlineSubmit })
|
|
2663
|
+
/* @__PURE__ */ jsx("div", { className: twMerge("flex-none bg-inherit", !isStacked && "pt-3"), children: inlineSubmit })
|
|
2080
2664
|
] }) : fieldsGrid;
|
|
2081
2665
|
})()
|
|
2082
2666
|
] });
|
|
2083
2667
|
};
|
|
2668
|
+
var COOLDOWN_MS = 2e3;
|
|
2669
|
+
function useSuccessFeedback(isSuccess) {
|
|
2670
|
+
const bannerRef = useRef(null);
|
|
2671
|
+
const [cooldown, setCooldown] = useState(false);
|
|
2672
|
+
const [submittedSnapshot, setSubmittedSnapshot] = useState(null);
|
|
2673
|
+
useEffect(() => {
|
|
2674
|
+
if (!isSuccess) return;
|
|
2675
|
+
setCooldown(true);
|
|
2676
|
+
const timer = setTimeout(() => setCooldown(false), COOLDOWN_MS);
|
|
2677
|
+
const node = bannerRef.current;
|
|
2678
|
+
if (node && typeof node.scrollIntoView === "function") {
|
|
2679
|
+
const reduceMotion = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
2680
|
+
node.scrollIntoView({
|
|
2681
|
+
behavior: reduceMotion ? "auto" : "smooth",
|
|
2682
|
+
block: "center"
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
return () => clearTimeout(timer);
|
|
2686
|
+
}, [isSuccess]);
|
|
2687
|
+
return {
|
|
2688
|
+
bannerRef,
|
|
2689
|
+
cooldown,
|
|
2690
|
+
submittedSnapshot,
|
|
2691
|
+
markSubmitted: (values) => setSubmittedSnapshot(JSON.stringify(values)),
|
|
2692
|
+
clearSubmitted: () => setSubmittedSnapshot(null)
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
function ValuesObserver({ onChange }) {
|
|
2696
|
+
const { values } = useFormikContext();
|
|
2697
|
+
const mounted = useRef(false);
|
|
2698
|
+
useEffect(() => {
|
|
2699
|
+
if (!mounted.current) {
|
|
2700
|
+
mounted.current = true;
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
onChange(values);
|
|
2704
|
+
}, [values, onChange]);
|
|
2705
|
+
return null;
|
|
2706
|
+
}
|
|
2084
2707
|
function globalTracker() {
|
|
2085
2708
|
if (typeof window === "undefined") return void 0;
|
|
2086
2709
|
return window.__vtTrack;
|
|
2087
2710
|
}
|
|
2711
|
+
function createRouteFileUploader(route, formId) {
|
|
2712
|
+
return (file) => __async(null, null, function* () {
|
|
2713
|
+
const body = new FormData();
|
|
2714
|
+
body.append("file", file);
|
|
2715
|
+
body.append("formId", formId);
|
|
2716
|
+
const res = yield fetch(route, { method: "POST", body });
|
|
2717
|
+
if (!res.ok) {
|
|
2718
|
+
const errBody = yield res.json().catch(() => null);
|
|
2719
|
+
throw new Error((errBody == null ? void 0 : errBody.error) || `Upload failed (${res.status})`);
|
|
2720
|
+
}
|
|
2721
|
+
const data = yield res.json().catch(() => null);
|
|
2722
|
+
if (!data || typeof data.url !== "string" || data.url.length === 0) {
|
|
2723
|
+
throw new Error("Upload route did not return a url");
|
|
2724
|
+
}
|
|
2725
|
+
if (isUnresolvedUploadUrl(data.url)) {
|
|
2726
|
+
throw new Error("Upload route returned a temporary, non-durable url");
|
|
2727
|
+
}
|
|
2728
|
+
return {
|
|
2729
|
+
url: data.url,
|
|
2730
|
+
name: typeof data.name === "string" ? data.name : file.name,
|
|
2731
|
+
size: typeof data.size === "number" ? data.size : file.size
|
|
2732
|
+
};
|
|
2733
|
+
});
|
|
2734
|
+
}
|
|
2735
|
+
function isUnresolvedUploadUrl(value) {
|
|
2736
|
+
return typeof value === "string" && (value.startsWith("blob:") || value.startsWith("data:"));
|
|
2737
|
+
}
|
|
2738
|
+
function findUnresolvedUploads(payload) {
|
|
2739
|
+
const ids = [];
|
|
2740
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
2741
|
+
if (Array.isArray(value)) {
|
|
2742
|
+
if (value.some(isUnresolvedUploadUrl)) ids.push(key);
|
|
2743
|
+
} else if (isUnresolvedUploadUrl(value)) {
|
|
2744
|
+
ids.push(key);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
return ids;
|
|
2748
|
+
}
|
|
2749
|
+
function getConversionUserData(definition, values) {
|
|
2750
|
+
const out = {};
|
|
2751
|
+
for (const section of definition.sections) {
|
|
2752
|
+
for (const field of section.fields) {
|
|
2753
|
+
if (field.type === "email" && out.email === void 0 && values[field.id]) {
|
|
2754
|
+
out.email = values[field.id];
|
|
2755
|
+
}
|
|
2756
|
+
if (field.type === "phone" && out.phone === void 0 && values[field.id]) {
|
|
2757
|
+
out.phone = values[field.id];
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
return out;
|
|
2762
|
+
}
|
|
2088
2763
|
function getSensitiveFieldIds(definition) {
|
|
2089
2764
|
const ids = [];
|
|
2090
2765
|
for (const section of definition.sections) {
|
|
@@ -2126,9 +2801,9 @@ function fetchTransportKey(endpoint) {
|
|
|
2126
2801
|
var presetNonBgClasses = {
|
|
2127
2802
|
default: "",
|
|
2128
2803
|
minimal: "",
|
|
2129
|
-
bordered: "border border-
|
|
2804
|
+
bordered: "border border-current/15",
|
|
2130
2805
|
shadow: "shadow-lg",
|
|
2131
|
-
card: "shadow-lg border border-
|
|
2806
|
+
card: "shadow-lg border border-current/15",
|
|
2132
2807
|
dark: ""
|
|
2133
2808
|
};
|
|
2134
2809
|
var radiusClasses = {
|
|
@@ -2139,12 +2814,23 @@ var radiusClasses = {
|
|
|
2139
2814
|
full: "rounded-2xl"
|
|
2140
2815
|
};
|
|
2141
2816
|
var spacingClasses = {
|
|
2817
|
+
// "none" exists for forms dropped into a page that owns its own layout —
|
|
2818
|
+
// without it a consumer had to neutralise the padding with a `p-0` class
|
|
2819
|
+
// override from the outside.
|
|
2820
|
+
none: "p-0",
|
|
2142
2821
|
compact: "p-3",
|
|
2143
2822
|
normal: "p-6",
|
|
2144
2823
|
relaxed: "p-8"
|
|
2145
2824
|
};
|
|
2825
|
+
function getRadiusClass(style, fallback = "rounded-md") {
|
|
2826
|
+
if (resolveCustomRadius(style)) return "rounded-none";
|
|
2827
|
+
return radiusClasses[style.borderRadius] || fallback;
|
|
2828
|
+
}
|
|
2829
|
+
function getRadiusStyle(style) {
|
|
2830
|
+
return resolveCustomRadius(style) ? { borderRadius: FORM_RADIUS_VAR } : {};
|
|
2831
|
+
}
|
|
2146
2832
|
function getButtonClasses(style) {
|
|
2147
|
-
const radius =
|
|
2833
|
+
const radius = getRadiusClass(style);
|
|
2148
2834
|
const weight = style.inputVariant === "stacked" ? "font-semibold" : "font-medium";
|
|
2149
2835
|
switch (style.buttonVariant) {
|
|
2150
2836
|
case "outline":
|
|
@@ -2157,17 +2843,18 @@ function getButtonClasses(style) {
|
|
|
2157
2843
|
}
|
|
2158
2844
|
}
|
|
2159
2845
|
function getButtonStyle(style) {
|
|
2846
|
+
const radius = getRadiusStyle(style);
|
|
2160
2847
|
switch (style.buttonVariant) {
|
|
2161
2848
|
case "outline":
|
|
2162
|
-
return { borderColor: FORM_VAR.buttonBg, color: FORM_VAR.buttonBg };
|
|
2849
|
+
return __spreadProps(__spreadValues({}, radius), { borderColor: FORM_VAR.buttonBg, color: FORM_VAR.buttonBg });
|
|
2163
2850
|
case "ghost":
|
|
2164
|
-
return { color: FORM_VAR.buttonBg };
|
|
2851
|
+
return __spreadProps(__spreadValues({}, radius), { color: FORM_VAR.buttonBg });
|
|
2165
2852
|
case "filled":
|
|
2166
2853
|
default:
|
|
2167
|
-
return {
|
|
2854
|
+
return __spreadProps(__spreadValues({}, radius), {
|
|
2168
2855
|
backgroundColor: FORM_VAR.buttonBg,
|
|
2169
2856
|
color: FORM_VAR.buttonText
|
|
2170
|
-
};
|
|
2857
|
+
});
|
|
2171
2858
|
}
|
|
2172
2859
|
}
|
|
2173
2860
|
function interpolateSuccessMessage(template, response) {
|
|
@@ -2281,9 +2968,14 @@ var ErrorBanner = ({
|
|
|
2281
2968
|
var DynamicForm = ({
|
|
2282
2969
|
definition,
|
|
2283
2970
|
apiRoute,
|
|
2971
|
+
submit,
|
|
2972
|
+
initialValues: initialValueOverrides,
|
|
2973
|
+
onValuesChange,
|
|
2284
2974
|
onSuccess,
|
|
2285
2975
|
onError,
|
|
2286
2976
|
extraData,
|
|
2977
|
+
onFileUpload,
|
|
2978
|
+
fileUploadRoute,
|
|
2287
2979
|
className,
|
|
2288
2980
|
onFormView,
|
|
2289
2981
|
onFormSubmit: onFormSubmitCallback,
|
|
@@ -2292,17 +2984,19 @@ var DynamicForm = ({
|
|
|
2292
2984
|
previewTouchAllSignal,
|
|
2293
2985
|
previewUntouchAllSignal,
|
|
2294
2986
|
previewBg,
|
|
2295
|
-
previewTextColor
|
|
2987
|
+
previewTextColor,
|
|
2988
|
+
previewColorScheme,
|
|
2989
|
+
darkModeSelector = FORM_DEFAULT_DARK_SELECTOR
|
|
2296
2990
|
}) => {
|
|
2297
|
-
var _a, _b, _c;
|
|
2991
|
+
var _a, _b, _c, _d;
|
|
2298
2992
|
const [submitStatus, setSubmitStatus] = useState("idle");
|
|
2299
|
-
const
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
}
|
|
2993
|
+
const {
|
|
2994
|
+
bannerRef,
|
|
2995
|
+
cooldown: postSuccessCooldown,
|
|
2996
|
+
submittedSnapshot,
|
|
2997
|
+
markSubmitted,
|
|
2998
|
+
clearSubmitted
|
|
2999
|
+
} = useSuccessFeedback(submitStatus === "success");
|
|
2306
3000
|
const [responseData, setResponseData] = useState(
|
|
2307
3001
|
null
|
|
2308
3002
|
);
|
|
@@ -2324,8 +3018,15 @@ var DynamicForm = ({
|
|
|
2324
3018
|
mountTimeRef.current = Date.now();
|
|
2325
3019
|
}, [definition.id]);
|
|
2326
3020
|
const validationSchema = useMemo(() => buildYupSchema(definition), [definition]);
|
|
3021
|
+
useEffect(() => {
|
|
3022
|
+
var _a2;
|
|
3023
|
+
void ((_a2 = formikRef.current) == null ? void 0 : _a2.validateForm());
|
|
3024
|
+
}, [validationSchema]);
|
|
2327
3025
|
const initialValues = useMemo(() => {
|
|
2328
3026
|
const base = buildInitialValues(definition);
|
|
3027
|
+
for (const [key, value] of Object.entries(initialValueOverrides != null ? initialValueOverrides : {})) {
|
|
3028
|
+
if (key in base && value !== void 0) base[key] = value;
|
|
3029
|
+
}
|
|
2329
3030
|
if (honeypotEnabled) {
|
|
2330
3031
|
base[HONEYPOT_FIELD_NAME] = "";
|
|
2331
3032
|
}
|
|
@@ -2335,6 +3036,13 @@ var DynamicForm = ({
|
|
|
2335
3036
|
() => [...definition.sections].sort((a, b) => a.order - b.order),
|
|
2336
3037
|
[definition.sections]
|
|
2337
3038
|
);
|
|
3039
|
+
const fileUploadValue = useMemo(
|
|
3040
|
+
() => ({
|
|
3041
|
+
upload: onFileUpload != null ? onFileUpload : fileUploadRoute ? createRouteFileUploader(fileUploadRoute, definition.id) : void 0,
|
|
3042
|
+
allowObjectUrlFallback: Boolean(previewState)
|
|
3043
|
+
}),
|
|
3044
|
+
[onFileUpload, fileUploadRoute, definition.id, previewState]
|
|
3045
|
+
);
|
|
2338
3046
|
useEffect(() => {
|
|
2339
3047
|
if (previewTouchAllSignal === void 0 || !formikRef.current) return;
|
|
2340
3048
|
const touched = {};
|
|
@@ -2349,19 +3057,34 @@ var DynamicForm = ({
|
|
|
2349
3057
|
if (previewUntouchAllSignal === void 0 || !formikRef.current) return;
|
|
2350
3058
|
formikRef.current.setTouched({}, false);
|
|
2351
3059
|
}, [previewUntouchAllSignal]);
|
|
2352
|
-
const
|
|
3060
|
+
const rawStyle = __spreadValues(__spreadValues({}, DEFAULT_FORM_STYLE), definition.style);
|
|
3061
|
+
const style = previewColorScheme ? resolveSchemeStyle(rawStyle, previewColorScheme) : rawStyle;
|
|
3062
|
+
const darkEnabled = !previewColorScheme && definitionHasDarkColors(definition);
|
|
3063
|
+
const colorSchemeState = {
|
|
3064
|
+
forced: previewColorScheme,
|
|
3065
|
+
darkEnabled
|
|
3066
|
+
};
|
|
2353
3067
|
const isStacked = style.inputVariant === "stacked";
|
|
2354
3068
|
const isCard = style.preset === "card";
|
|
2355
3069
|
const submittingText = (_b = definition.submitConfig.submittingText) != null ? _b : "Submitting...";
|
|
2356
|
-
const
|
|
2357
|
-
const
|
|
2358
|
-
const
|
|
2359
|
-
const
|
|
2360
|
-
const
|
|
2361
|
-
const formInlineStyle = __spreadValues(__spreadValues(__spreadValues({}, cssVarStyle),
|
|
3070
|
+
const submittedText = (_c = definition.submitConfig.submittedText) != null ? _c : "Sent";
|
|
3071
|
+
const successBehavior = (_d = definition.submitConfig.successBehavior) != null ? _d : "message";
|
|
3072
|
+
const cssVarStyle = __spreadValues(__spreadValues({}, buildFormCssVars(style, previewBg)), darkEnabled ? buildFormDarkCssVars(style) : {});
|
|
3073
|
+
const effectiveFormBg = style.formBackgroundColor || previewBg;
|
|
3074
|
+
const rootBgStyle = darkEnabled ? { backgroundColor: FORM_ROOT_BG_VAR } : effectiveFormBg ? { backgroundColor: effectiveFormBg } : {};
|
|
3075
|
+
const formInlineStyle = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, cssVarStyle), getRadiusStyle(style)), rootBgStyle), previewTextColor ? { color: previewTextColor } : {});
|
|
3076
|
+
const darkScopeAttr = darkEnabled ? { [FORM_DARK_SCOPE_ATTR]: "" } : {};
|
|
3077
|
+
const darkStyleSheet = darkEnabled ? /* @__PURE__ */ jsx(
|
|
3078
|
+
"style",
|
|
3079
|
+
{
|
|
3080
|
+
"data-vt-forms-dark": "",
|
|
3081
|
+
dangerouslySetInnerHTML: { __html: buildDarkSchemeCss(darkModeSelector) }
|
|
3082
|
+
}
|
|
3083
|
+
) : null;
|
|
2362
3084
|
const formClasses = twMerge(
|
|
3085
|
+
"bg-inherit",
|
|
2363
3086
|
presetNonBgClasses[style.preset] || "",
|
|
2364
|
-
|
|
3087
|
+
getRadiusClass(style),
|
|
2365
3088
|
isCard ? "p-8" : spacingClasses[style.spacing] || "p-6",
|
|
2366
3089
|
isStacked ? "space-y-8" : "",
|
|
2367
3090
|
className
|
|
@@ -2374,24 +3097,29 @@ var DynamicForm = ({
|
|
|
2374
3097
|
responseData
|
|
2375
3098
|
);
|
|
2376
3099
|
if (successBehavior === "replace" && effectiveSubmitStatus === "success") {
|
|
2377
|
-
return /* @__PURE__ */ jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsx(
|
|
3100
|
+
return /* @__PURE__ */ jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsx(FormColorSchemeProvider, { value: colorSchemeState, children: /* @__PURE__ */ jsxs(
|
|
2378
3101
|
"div",
|
|
2379
|
-
{
|
|
3102
|
+
__spreadProps(__spreadValues({
|
|
3103
|
+
ref: bannerRef,
|
|
2380
3104
|
className: formClasses,
|
|
2381
3105
|
style: formInlineStyle,
|
|
2382
|
-
"data-form-version": definition.version
|
|
2383
|
-
|
|
2384
|
-
|
|
3106
|
+
"data-form-version": definition.version
|
|
3107
|
+
}, darkScopeAttr), {
|
|
3108
|
+
children: [
|
|
3109
|
+
darkStyleSheet,
|
|
3110
|
+
/* @__PURE__ */ jsx(SuccessBanner, { message: successMessage })
|
|
3111
|
+
]
|
|
3112
|
+
})
|
|
2385
3113
|
) }) });
|
|
2386
3114
|
}
|
|
2387
|
-
return /* @__PURE__ */ jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsx(
|
|
3115
|
+
return /* @__PURE__ */ jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsx(FormColorSchemeProvider, { value: colorSchemeState, children: /* @__PURE__ */ jsx(FormFileUploadProvider, { value: fileUploadValue, children: /* @__PURE__ */ jsx(
|
|
2388
3116
|
Formik,
|
|
2389
3117
|
{
|
|
2390
3118
|
innerRef: formikRef,
|
|
2391
3119
|
initialValues,
|
|
2392
3120
|
validationSchema,
|
|
2393
3121
|
onSubmit: (_0, _1) => __async(null, [_0, _1], function* (values, { setSubmitting, resetForm }) {
|
|
2394
|
-
var _a2, _b2,
|
|
3122
|
+
var _a2, _b2, _d2, _e, _f, _g;
|
|
2395
3123
|
if (previewState) {
|
|
2396
3124
|
setSubmitting(false);
|
|
2397
3125
|
return;
|
|
@@ -2406,6 +3134,7 @@ var DynamicForm = ({
|
|
|
2406
3134
|
console.debug(`[forms] Spam detected: ${reason}`);
|
|
2407
3135
|
}
|
|
2408
3136
|
setResponseData(null);
|
|
3137
|
+
markSubmitted(values);
|
|
2409
3138
|
setSubmitStatus("success");
|
|
2410
3139
|
if (successBehavior === "reset" || successBehavior === "replace") {
|
|
2411
3140
|
resetForm();
|
|
@@ -2417,7 +3146,9 @@ var DynamicForm = ({
|
|
|
2417
3146
|
setSubmitStatus("idle");
|
|
2418
3147
|
try {
|
|
2419
3148
|
const _c2 = values, { [_b2 = HONEYPOT_FIELD_NAME]: _hp } = _c2, cleanValues = __objRest(_c2, [__restKey(_b2)]);
|
|
2420
|
-
const
|
|
3149
|
+
const adReferral = readAdReferral();
|
|
3150
|
+
const analyticsSessionId = readAnalyticsSessionId();
|
|
3151
|
+
const payload = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, cleanValues), adReferral ? { adReferral } : {}), analyticsSessionId ? { analyticsSessionId } : {}), extraData), {
|
|
2421
3152
|
formId: definition.id
|
|
2422
3153
|
});
|
|
2423
3154
|
for (const hiddenId of getHiddenFieldIds(definition, cleanValues)) {
|
|
@@ -2426,6 +3157,12 @@ var DynamicForm = ({
|
|
|
2426
3157
|
for (const toggleKey of getSameAsToggleKeys(definition)) {
|
|
2427
3158
|
delete payload[toggleKey];
|
|
2428
3159
|
}
|
|
3160
|
+
const unresolved = findUnresolvedUploads(payload);
|
|
3161
|
+
if (unresolved.length > 0) {
|
|
3162
|
+
throw new Error(
|
|
3163
|
+
`File upload did not complete for: ${unresolved.join(", ")}. Remove the file and add it again.`
|
|
3164
|
+
);
|
|
3165
|
+
}
|
|
2429
3166
|
const sensitiveIds = getSensitiveFieldIds(definition);
|
|
2430
3167
|
if (sensitiveIds.length > 0) {
|
|
2431
3168
|
const transportKey = yield fetchTransportKey(transportKeyEndpoint);
|
|
@@ -2441,29 +3178,49 @@ var DynamicForm = ({
|
|
|
2441
3178
|
);
|
|
2442
3179
|
}
|
|
2443
3180
|
}
|
|
2444
|
-
const res = yield fetch(apiRoute, {
|
|
2445
|
-
method: "POST",
|
|
2446
|
-
headers: { "Content-Type": "application/json" },
|
|
2447
|
-
body: JSON.stringify(payload)
|
|
2448
|
-
});
|
|
2449
|
-
if (!res.ok) {
|
|
2450
|
-
const errBody = yield res.json().catch(() => null);
|
|
2451
|
-
throw new Error(
|
|
2452
|
-
(errBody == null ? void 0 : errBody.error) || `Submission failed (${res.status})`
|
|
2453
|
-
);
|
|
2454
|
-
}
|
|
2455
3181
|
let body = null;
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
3182
|
+
if (submit) {
|
|
3183
|
+
const result = yield submit(payload);
|
|
3184
|
+
body = result && typeof result === "object" ? result : null;
|
|
3185
|
+
} else {
|
|
3186
|
+
const res = yield fetch(apiRoute, {
|
|
3187
|
+
method: "POST",
|
|
3188
|
+
headers: { "Content-Type": "application/json" },
|
|
3189
|
+
body: JSON.stringify(payload)
|
|
3190
|
+
});
|
|
3191
|
+
if (!res.ok) {
|
|
3192
|
+
const errBody = yield res.json().catch(() => null);
|
|
3193
|
+
throw new Error(
|
|
3194
|
+
(errBody == null ? void 0 : errBody.error) || `Submission failed (${res.status})`
|
|
3195
|
+
);
|
|
3196
|
+
}
|
|
3197
|
+
try {
|
|
3198
|
+
body = yield res.json();
|
|
3199
|
+
} catch (e) {
|
|
3200
|
+
body = null;
|
|
3201
|
+
}
|
|
2460
3202
|
}
|
|
2461
3203
|
setResponseData(body);
|
|
3204
|
+
const submissionType = (_d2 = extraData == null ? void 0 : extraData.submissionType) != null ? _d2 : "contact";
|
|
3205
|
+
const serverId = body == null ? void 0 : body.submissionId;
|
|
3206
|
+
trackFormConversion(
|
|
3207
|
+
{
|
|
3208
|
+
formId: definition.id,
|
|
3209
|
+
formName: definition.name,
|
|
3210
|
+
formType: submissionType
|
|
3211
|
+
},
|
|
3212
|
+
(_e = definition.submitConfig.conversion) == null ? void 0 : _e.sendTo,
|
|
3213
|
+
{
|
|
3214
|
+
transactionId: typeof serverId === "string" && serverId ? serverId : newTransactionId(),
|
|
3215
|
+
userData: getConversionUserData(definition, values)
|
|
3216
|
+
}
|
|
3217
|
+
);
|
|
3218
|
+
markSubmitted(values);
|
|
2462
3219
|
setSubmitStatus("success");
|
|
2463
|
-
(
|
|
3220
|
+
(_g = onFormSubmitCallback != null ? onFormSubmitCallback : (_f = globalTracker()) == null ? void 0 : _f.trackFormSubmit) == null ? void 0 : _g(
|
|
2464
3221
|
definition.id,
|
|
2465
3222
|
definition.name,
|
|
2466
|
-
|
|
3223
|
+
submissionType
|
|
2467
3224
|
);
|
|
2468
3225
|
if (successBehavior === "reset" || successBehavior === "replace") {
|
|
2469
3226
|
resetForm();
|
|
@@ -2477,23 +3234,29 @@ var DynamicForm = ({
|
|
|
2477
3234
|
}
|
|
2478
3235
|
} catch (err) {
|
|
2479
3236
|
setResponseData(null);
|
|
3237
|
+
clearSubmitted();
|
|
2480
3238
|
setSubmitStatus("error");
|
|
2481
3239
|
onError == null ? void 0 : onError(err instanceof Error ? err : new Error("Submission failed"));
|
|
2482
3240
|
} finally {
|
|
2483
3241
|
setSubmitting(false);
|
|
2484
3242
|
}
|
|
2485
3243
|
}),
|
|
2486
|
-
children: ({ isSubmitting, getFieldProps }) => {
|
|
3244
|
+
children: ({ isSubmitting, getFieldProps, values }) => {
|
|
2487
3245
|
const showSubmitting = isSubmitting || previewSubmitting;
|
|
2488
3246
|
const isDisabled = successBehavior === "disable" && effectiveSubmitStatus === "success";
|
|
2489
|
-
const
|
|
3247
|
+
const unchangedSinceSuccess = effectiveSubmitStatus === "success" && submittedSnapshot !== null && JSON.stringify(values) === submittedSnapshot;
|
|
3248
|
+
const submitLocked = showSubmitting || postSuccessCooldown || unchangedSinceSuccess || previewState === "success";
|
|
2490
3249
|
return /* @__PURE__ */ jsxs(
|
|
2491
3250
|
Form,
|
|
2492
|
-
{
|
|
3251
|
+
__spreadProps(__spreadValues({
|
|
3252
|
+
method: "post",
|
|
2493
3253
|
className: formClasses,
|
|
2494
3254
|
style: formInlineStyle,
|
|
2495
|
-
"data-form-version": definition.version
|
|
3255
|
+
"data-form-version": definition.version
|
|
3256
|
+
}, darkScopeAttr), {
|
|
2496
3257
|
children: [
|
|
3258
|
+
darkStyleSheet,
|
|
3259
|
+
onValuesChange && /* @__PURE__ */ jsx(ValuesObserver, { onChange: onValuesChange }),
|
|
2497
3260
|
honeypotEnabled && /* @__PURE__ */ jsxs(
|
|
2498
3261
|
"div",
|
|
2499
3262
|
{
|
|
@@ -2523,7 +3286,7 @@ var DynamicForm = ({
|
|
|
2523
3286
|
]
|
|
2524
3287
|
}
|
|
2525
3288
|
),
|
|
2526
|
-
effectiveSubmitStatus === "success" && /* @__PURE__ */ jsx("div", { className: bannerWrapperClass, children: /* @__PURE__ */ jsx(SuccessBanner, { message: successMessage }) }),
|
|
3289
|
+
effectiveSubmitStatus === "success" && /* @__PURE__ */ jsx("div", { ref: bannerRef, className: bannerWrapperClass, children: /* @__PURE__ */ jsx(SuccessBanner, { message: successMessage }) }),
|
|
2527
3290
|
effectiveSubmitStatus === "error" && /* @__PURE__ */ jsx("div", { className: bannerWrapperClass, children: /* @__PURE__ */ jsx(
|
|
2528
3291
|
ErrorBanner,
|
|
2529
3292
|
{
|
|
@@ -2537,7 +3300,7 @@ var DynamicForm = ({
|
|
|
2537
3300
|
disabled: isDisabled,
|
|
2538
3301
|
"aria-disabled": isDisabled,
|
|
2539
3302
|
className: twMerge(
|
|
2540
|
-
"min-w-0 border-0 p-0",
|
|
3303
|
+
"min-w-0 border-0 bg-inherit p-0",
|
|
2541
3304
|
isStacked ? "space-y-8" : "",
|
|
2542
3305
|
isDisabled ? "pointer-events-none opacity-60" : ""
|
|
2543
3306
|
),
|
|
@@ -2556,7 +3319,7 @@ var DynamicForm = ({
|
|
|
2556
3319
|
"aria-busy": showSubmitting,
|
|
2557
3320
|
children: [
|
|
2558
3321
|
showSubmitting && /* @__PURE__ */ jsx(Spinner, {}),
|
|
2559
|
-
showSubmitting ? submittingText : definition.submitConfig.buttonText
|
|
3322
|
+
showSubmitting ? submittingText : unchangedSinceSuccess ? submittedText : definition.submitConfig.buttonText
|
|
2560
3323
|
]
|
|
2561
3324
|
}
|
|
2562
3325
|
);
|
|
@@ -2569,6 +3332,7 @@ var DynamicForm = ({
|
|
|
2569
3332
|
section,
|
|
2570
3333
|
isLast,
|
|
2571
3334
|
formDefaultTextColor: definition.defaultTextColor,
|
|
3335
|
+
formDefaultTextColorDark: definition.defaultTextColorDark,
|
|
2572
3336
|
inlineSubmit: inlineButton && isLast ? submitButton : void 0
|
|
2573
3337
|
},
|
|
2574
3338
|
section.id
|
|
@@ -2580,12 +3344,31 @@ var DynamicForm = ({
|
|
|
2580
3344
|
}
|
|
2581
3345
|
)
|
|
2582
3346
|
]
|
|
2583
|
-
}
|
|
3347
|
+
})
|
|
2584
3348
|
);
|
|
2585
3349
|
}
|
|
2586
3350
|
}
|
|
2587
|
-
) }) });
|
|
3351
|
+
) }) }) });
|
|
2588
3352
|
};
|
|
3353
|
+
function AdReferralTracker({
|
|
3354
|
+
fallback,
|
|
3355
|
+
cookieName = AD_REFERRAL_COOKIE,
|
|
3356
|
+
ttlDays = AD_REFERRAL_TTL_DAYS
|
|
3357
|
+
} = {}) {
|
|
3358
|
+
useEffect(() => {
|
|
3359
|
+
const referral = captureAdReferral(
|
|
3360
|
+
window.location.search,
|
|
3361
|
+
fallback,
|
|
3362
|
+
/* @__PURE__ */ new Date(),
|
|
3363
|
+
window.location.pathname
|
|
3364
|
+
);
|
|
3365
|
+
if (!referral) return;
|
|
3366
|
+
const existing = readAdReferral(cookieName);
|
|
3367
|
+
if (existing && isSameAdReferralTouch(existing, referral)) return;
|
|
3368
|
+
writeAdReferral(referral, cookieName, ttlDays);
|
|
3369
|
+
}, []);
|
|
3370
|
+
return null;
|
|
3371
|
+
}
|
|
2589
3372
|
function buildQueryString(opts) {
|
|
2590
3373
|
const params = new URLSearchParams({
|
|
2591
3374
|
projectId: opts.projectId,
|
|
@@ -2847,6 +3630,6 @@ function useDragReorder({
|
|
|
2847
3630
|
});
|
|
2848
3631
|
}
|
|
2849
3632
|
|
|
2850
|
-
export { APPLICATION_STATUS_KEYS, 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, DynamicForm, DynamicFormField, DynamicFormSection, FORM_CSS_VAR, FORM_DEFAULT_COLOR, FORM_VAR, HONEYPOT_FIELD_NAME, NEWSLETTER_ALLOWED_FIELD_TYPES, SAME_AS_TOGGLE_PREFIX, SAMPLE_EMAIL_TEMPLATE_VARIABLES, applyTextTransform, applyTransform, base64ToBuffer, bufferToBase64, buildEmailTemplateVariables, buildFormCssVars, buildInitialValues, buildYupSchema, deriveLast4, encryptSensitiveValue, formatSsn, formatUsPhone, getFormDefinition, getSafeRedirectUrl, isVisibilityConditionMet, parseFormDefinition, renderEmailTemplate, renderNotificationEmail, sameAsToggleKey, useDragReorder, useFormDefinition, useUndoRedo, useUndoRedoShortcuts };
|
|
3633
|
+
export { AD_REFERRAL_COOKIE, AD_REFERRAL_TTL_DAYS, APPLICATION_STATUS_KEYS, AdReferralTracker, 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, DynamicForm, DynamicFormField, DynamicFormSection, ENHANCED_CONVERSIONS_GLOBAL, FORM_CONVERSION_SEND_TO_GLOBAL, FORM_CSS_VAR, FORM_DARK_SCOPE_ATTR, FORM_DARK_TEXT_ATTR, FORM_DARK_TEXT_VAR, FORM_DEFAULT_COLOR, FORM_DEFAULT_DARK_SELECTOR, FORM_DEFAULT_RADIUS, FORM_GAP_VAR, FORM_RADIUS_VAR, FORM_ROOT_BG_VAR, FORM_STRUCT_VAR, FORM_STYLE_COLOR_KEYS, FORM_SUBMIT_SUCCESS_EVENT, FORM_VAR, FileField, FormFileUploadProvider, HONEYPOT_FIELD_NAME, NEWSLETTER_ALLOWED_FIELD_TYPES, SAME_AS_TOGGLE_PREFIX, SAMPLE_EMAIL_TEMPLATE_VARIABLES, applyTextTransform, applyTransform, base64ToBuffer, bufferToBase64, buildColorVars, buildDarkSchemeCss, buildEmailTemplateVariables, buildFormCssVars, buildFormDarkCssVars, buildInitialValues, buildUserData, buildYupSchema, captureAdReferral, darkVarName, definitionHasDarkColors, deriveLast4, encryptSensitiveValue, fireAdsConversion, fireGenerateLead, formatSsn, formatUsPhone, getFormDefinition, getSafeRedirectUrl, hasDarkColors, isSameAdReferralTouch, isVisibilityConditionMet, newTransactionId, parseFormDefinition, pushFormSubmitSuccess, readAdReferral, renderEmailTemplate, renderNotificationEmail, resizeImageFile, resolveConversionSendTo, resolveCustomGap, resolveCustomRadius, resolveSchemeColors, resolveSchemeStyle, resolveSectionTextColor, sameAsToggleKey, toE164, trackFormConversion, useDragReorder, useFormDefinition, useFormFileUpload, useUndoRedo, useUndoRedoShortcuts, writeAdReferral };
|
|
2851
3634
|
//# sourceMappingURL=index.mjs.map
|
|
2852
3635
|
//# sourceMappingURL=index.mjs.map
|