@usefillo/react 0.5.0 → 0.5.2

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7,7 +7,8 @@ import {
7
7
  createClient,
8
8
  isField as isField2,
9
9
  normalizeFormSchema,
10
- normalizeFormTheme
10
+ normalizeFormTheme,
11
+ visibleFields as visibleFields2
11
12
  } from "@usefillo/core";
12
13
 
13
14
  // src/context.ts
@@ -130,7 +131,7 @@ function useCodeFormSync(form, client, onError) {
130
131
  }
131
132
 
132
133
  // src/fields.tsx
133
- import { isField, pipeBlock, validateResponse } from "@usefillo/core";
134
+ import { isField, pipeBlock, validateResponse, visibleFields } from "@usefillo/core";
134
135
  import { memo, useEffect as useEffect6, useState as useState5 } from "react";
135
136
 
136
137
  // src/phone.tsx
@@ -1357,7 +1358,10 @@ function shouldAutoSubmit(field, value, api) {
1357
1358
  })();
1358
1359
  if (!hasDiscreteAnswer) return false;
1359
1360
  if (value === api.data[field.id]) return false;
1360
- return validateResponse(api.form, { ...api.data, [field.id]: value }).ok;
1361
+ const nextData = { ...api.data, [field.id]: value };
1362
+ const interactive = visibleFields(api.form, nextData).filter((f) => f.kind !== "hidden");
1363
+ if (interactive.length !== 1 || interactive[0]?.id !== field.id) return false;
1364
+ return validateResponse(api.form, nextData).ok;
1361
1365
  }
1362
1366
  function blockHasPiping(block) {
1363
1367
  const has = (s) => typeof s === "string" && s.includes("{{");
@@ -1486,8 +1490,11 @@ function focusFirstInvalid(formEl) {
1486
1490
  function isAutoSubmitBlock(block) {
1487
1491
  return isField2(block) && (block.kind === "select" || block.kind === "dropdown" || block.kind === "checkbox" || block.kind === "rating" || block.kind === "linear_scale");
1488
1492
  }
1489
- function needsExplicitSubmit(blocks) {
1490
- return blocks.some((block) => isField2(block) && block.kind !== "hidden" && !isAutoSubmitBlock(block));
1493
+ function needsExplicitSubmit(visible) {
1494
+ const interactive = visible.filter((b) => !(isField2(b) && b.kind === "hidden"));
1495
+ if (interactive.length === 0) return false;
1496
+ if (interactive.length > 1) return true;
1497
+ return !isAutoSubmitBlock(interactive[0]);
1491
1498
  }
1492
1499
  function FilloForm(props) {
1493
1500
  const { form, formId } = props;
@@ -1623,7 +1630,7 @@ function ResolvedForm(props) {
1623
1630
  }
1624
1631
  const multiPage = api.pageCount > 1;
1625
1632
  const autoSubmit = settings.submitMode === "auto";
1626
- const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(api.blocks);
1633
+ const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(visibleFields2(api.form, api.data));
1627
1634
  const showFooter = showPrimaryButton || multiPage && !api.isFirstPage;
1628
1635
  return /* @__PURE__ */ jsx5(FilloContext.Provider, { value: api, children: /* @__PURE__ */ jsx5(FilloInstanceIdContext.Provider, { value: instanceId, children: /* @__PURE__ */ jsxs5(
1629
1636
  "form",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefillo/react",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Headless React components for embedding Fillo forms natively in your product.",
5
5
  "license": "MIT",
6
6
  "keywords": [