@forms.expert/sdk 0.2.7 → 0.2.9
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/dist/react/index.cjs +23 -14
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +23 -14
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/index.cjs +4 -3
- package/dist/vanilla/index.cjs.map +1 -1
- package/dist/vanilla/index.global.js +4 -3
- package/dist/vanilla/index.global.js.map +1 -1
- package/dist/vanilla/index.js +4 -3
- package/dist/vanilla/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -400,24 +400,25 @@ function useForm(options) {
|
|
|
400
400
|
const [values, setValues] = (0, import_react.useState)({});
|
|
401
401
|
const [error, setError] = (0, import_react.useState)(null);
|
|
402
402
|
const [uploadProgress, setUploadProgress] = (0, import_react.useState)(null);
|
|
403
|
+
const { slug, trackViews, lang, autoInit, onSuccess, onError, onValidationError } = options;
|
|
403
404
|
const initialize = (0, import_react.useCallback)(async () => {
|
|
404
405
|
setIsInitializing(true);
|
|
405
406
|
try {
|
|
406
|
-
const formConfig = await sdk.isActive(
|
|
407
|
+
const formConfig = await sdk.isActive(slug, lang);
|
|
407
408
|
setConfig(formConfig);
|
|
408
|
-
if (
|
|
409
|
-
sdk.trackView(
|
|
409
|
+
if (trackViews) {
|
|
410
|
+
void sdk.trackView(slug);
|
|
410
411
|
}
|
|
411
412
|
return formConfig;
|
|
412
413
|
} finally {
|
|
413
414
|
setIsInitializing(false);
|
|
414
415
|
}
|
|
415
|
-
}, [sdk,
|
|
416
|
+
}, [sdk, slug, trackViews, lang]);
|
|
416
417
|
(0, import_react.useEffect)(() => {
|
|
417
|
-
if (
|
|
418
|
+
if (autoInit !== false) {
|
|
418
419
|
initialize();
|
|
419
420
|
}
|
|
420
|
-
}, [initialize,
|
|
421
|
+
}, [initialize, autoInit]);
|
|
421
422
|
const setValue = (0, import_react.useCallback)((name, value) => {
|
|
422
423
|
setValues((prev) => ({ ...prev, [name]: value }));
|
|
423
424
|
setErrors((prev) => {
|
|
@@ -432,7 +433,7 @@ function useForm(options) {
|
|
|
432
433
|
setValues((prev) => ({ ...prev, ...newValues }));
|
|
433
434
|
}, []);
|
|
434
435
|
const validate = (0, import_react.useCallback)(async () => {
|
|
435
|
-
const result = await sdk.validate(
|
|
436
|
+
const result = await sdk.validate(slug, values);
|
|
436
437
|
if (!result.valid) {
|
|
437
438
|
const errorMap = result.errors.reduce(
|
|
438
439
|
(acc, err) => ({ ...acc, [err.field]: err.message }),
|
|
@@ -441,7 +442,7 @@ function useForm(options) {
|
|
|
441
442
|
setErrors(errorMap);
|
|
442
443
|
}
|
|
443
444
|
return result.valid;
|
|
444
|
-
}, [sdk,
|
|
445
|
+
}, [sdk, slug, values]);
|
|
445
446
|
const submit = (0, import_react.useCallback)(
|
|
446
447
|
async (captchaToken) => {
|
|
447
448
|
setIsLoading(true);
|
|
@@ -451,12 +452,12 @@ function useForm(options) {
|
|
|
451
452
|
setUploadProgress(null);
|
|
452
453
|
try {
|
|
453
454
|
const submitData = config?.settings?.honeypot ? { ...values, _hp: "" } : values;
|
|
454
|
-
const response = await sdk.submit(
|
|
455
|
+
const response = await sdk.submit(slug, submitData, {
|
|
455
456
|
captchaToken,
|
|
456
457
|
onProgress: setUploadProgress
|
|
457
458
|
});
|
|
458
459
|
setIsSubmitted(true);
|
|
459
|
-
|
|
460
|
+
onSuccess?.(response);
|
|
460
461
|
return response;
|
|
461
462
|
} catch (err) {
|
|
462
463
|
if (err instanceof FormValidationError) {
|
|
@@ -465,10 +466,10 @@ function useForm(options) {
|
|
|
465
466
|
{}
|
|
466
467
|
);
|
|
467
468
|
setErrors(errorMap);
|
|
468
|
-
|
|
469
|
+
onValidationError?.(err.errors);
|
|
469
470
|
} else {
|
|
470
471
|
setError(err);
|
|
471
|
-
|
|
472
|
+
onError?.(err);
|
|
472
473
|
}
|
|
473
474
|
return null;
|
|
474
475
|
} finally {
|
|
@@ -476,7 +477,7 @@ function useForm(options) {
|
|
|
476
477
|
setUploadProgress(null);
|
|
477
478
|
}
|
|
478
479
|
},
|
|
479
|
-
[sdk,
|
|
480
|
+
[sdk, slug, values, config?.settings?.honeypot, onSuccess, onError, onValidationError]
|
|
480
481
|
);
|
|
481
482
|
const reset = (0, import_react.useCallback)(() => {
|
|
482
483
|
setValues({});
|
|
@@ -697,7 +698,7 @@ function getParagraphSize(size) {
|
|
|
697
698
|
function FormsExpertForm({
|
|
698
699
|
config,
|
|
699
700
|
slug,
|
|
700
|
-
trackViews,
|
|
701
|
+
trackViews = true,
|
|
701
702
|
submitText = "Submit",
|
|
702
703
|
onSuccess,
|
|
703
704
|
onError,
|
|
@@ -990,6 +991,14 @@ function FormsExpertForm({
|
|
|
990
991
|
form[data-fe-scope="${formScopeId}"] button[type="submit"]:active:not(:disabled) { filter: brightness(0.85); transform: scale(0.98); }
|
|
991
992
|
form[data-fe-scope="${formScopeId}"] a[href]:hover { filter: brightness(0.9); }
|
|
992
993
|
form[data-fe-scope="${formScopeId}"] a[href]:active { filter: brightness(0.85); }
|
|
994
|
+
form[data-fe-scope="${formScopeId}"] input:focus,
|
|
995
|
+
form[data-fe-scope="${formScopeId}"] textarea:focus,
|
|
996
|
+
form[data-fe-scope="${formScopeId}"] select:focus {
|
|
997
|
+
outline: none !important;
|
|
998
|
+
border-color: ${styling.primaryColor || "#3b82f6"} !important;
|
|
999
|
+
box-shadow: 0 0 0 2px ${styling.primaryColor || "#3b82f6"}33 !important;
|
|
1000
|
+
-webkit-appearance: none;
|
|
1001
|
+
}
|
|
993
1002
|
` } }),
|
|
994
1003
|
styling.logoUrl && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: {
|
|
995
1004
|
textAlign: styling.logoPosition === "top-left" ? "left" : styling.logoPosition === "top-right" ? "right" : "center",
|