@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.
@@ -378,24 +378,25 @@ function useForm(options) {
378
378
  const [values, setValues] = useState({});
379
379
  const [error, setError] = useState(null);
380
380
  const [uploadProgress, setUploadProgress] = useState(null);
381
+ const { slug, trackViews, lang, autoInit, onSuccess, onError, onValidationError } = options;
381
382
  const initialize = useCallback(async () => {
382
383
  setIsInitializing(true);
383
384
  try {
384
- const formConfig = await sdk.isActive(options.slug, options.lang);
385
+ const formConfig = await sdk.isActive(slug, lang);
385
386
  setConfig(formConfig);
386
- if (options.trackViews) {
387
- sdk.trackView(options.slug);
387
+ if (trackViews) {
388
+ void sdk.trackView(slug);
388
389
  }
389
390
  return formConfig;
390
391
  } finally {
391
392
  setIsInitializing(false);
392
393
  }
393
- }, [sdk, options.slug, options.trackViews, options.lang]);
394
+ }, [sdk, slug, trackViews, lang]);
394
395
  useEffect(() => {
395
- if (options.autoInit !== false) {
396
+ if (autoInit !== false) {
396
397
  initialize();
397
398
  }
398
- }, [initialize, options.autoInit]);
399
+ }, [initialize, autoInit]);
399
400
  const setValue = useCallback((name, value) => {
400
401
  setValues((prev) => ({ ...prev, [name]: value }));
401
402
  setErrors((prev) => {
@@ -410,7 +411,7 @@ function useForm(options) {
410
411
  setValues((prev) => ({ ...prev, ...newValues }));
411
412
  }, []);
412
413
  const validate = useCallback(async () => {
413
- const result = await sdk.validate(options.slug, values);
414
+ const result = await sdk.validate(slug, values);
414
415
  if (!result.valid) {
415
416
  const errorMap = result.errors.reduce(
416
417
  (acc, err) => ({ ...acc, [err.field]: err.message }),
@@ -419,7 +420,7 @@ function useForm(options) {
419
420
  setErrors(errorMap);
420
421
  }
421
422
  return result.valid;
422
- }, [sdk, options.slug, values]);
423
+ }, [sdk, slug, values]);
423
424
  const submit = useCallback(
424
425
  async (captchaToken) => {
425
426
  setIsLoading(true);
@@ -429,12 +430,12 @@ function useForm(options) {
429
430
  setUploadProgress(null);
430
431
  try {
431
432
  const submitData = config?.settings?.honeypot ? { ...values, _hp: "" } : values;
432
- const response = await sdk.submit(options.slug, submitData, {
433
+ const response = await sdk.submit(slug, submitData, {
433
434
  captchaToken,
434
435
  onProgress: setUploadProgress
435
436
  });
436
437
  setIsSubmitted(true);
437
- options.onSuccess?.(response);
438
+ onSuccess?.(response);
438
439
  return response;
439
440
  } catch (err) {
440
441
  if (err instanceof FormValidationError) {
@@ -443,10 +444,10 @@ function useForm(options) {
443
444
  {}
444
445
  );
445
446
  setErrors(errorMap);
446
- options.onValidationError?.(err.errors);
447
+ onValidationError?.(err.errors);
447
448
  } else {
448
449
  setError(err);
449
- options.onError?.(err);
450
+ onError?.(err);
450
451
  }
451
452
  return null;
452
453
  } finally {
@@ -454,7 +455,7 @@ function useForm(options) {
454
455
  setUploadProgress(null);
455
456
  }
456
457
  },
457
- [sdk, options, values]
458
+ [sdk, slug, values, config?.settings?.honeypot, onSuccess, onError, onValidationError]
458
459
  );
459
460
  const reset = useCallback(() => {
460
461
  setValues({});
@@ -675,7 +676,7 @@ function getParagraphSize(size) {
675
676
  function FormsExpertForm({
676
677
  config,
677
678
  slug,
678
- trackViews,
679
+ trackViews = true,
679
680
  submitText = "Submit",
680
681
  onSuccess,
681
682
  onError,
@@ -968,6 +969,14 @@ function FormsExpertForm({
968
969
  form[data-fe-scope="${formScopeId}"] button[type="submit"]:active:not(:disabled) { filter: brightness(0.85); transform: scale(0.98); }
969
970
  form[data-fe-scope="${formScopeId}"] a[href]:hover { filter: brightness(0.9); }
970
971
  form[data-fe-scope="${formScopeId}"] a[href]:active { filter: brightness(0.85); }
972
+ form[data-fe-scope="${formScopeId}"] input:focus,
973
+ form[data-fe-scope="${formScopeId}"] textarea:focus,
974
+ form[data-fe-scope="${formScopeId}"] select:focus {
975
+ outline: none !important;
976
+ border-color: ${styling.primaryColor || "#3b82f6"} !important;
977
+ box-shadow: 0 0 0 2px ${styling.primaryColor || "#3b82f6"}33 !important;
978
+ -webkit-appearance: none;
979
+ }
971
980
  ` } }),
972
981
  styling.logoUrl && /* @__PURE__ */ jsx2("div", { style: {
973
982
  textAlign: styling.logoPosition === "top-left" ? "left" : styling.logoPosition === "top-right" ? "right" : "center",