@usefillo/react 0.2.0 → 0.2.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 +2 -2
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/FilloForm.tsx
4
4
  import { useEffect as useEffect6, useMemo, useRef as useRef4, useState as useState5 } from "react";
5
- import { FilloError as FilloError2 } from "@usefillo/core";
5
+ import { FilloError as FilloError2, createClient } from "@usefillo/core";
6
6
 
7
7
  // src/context.ts
8
8
  import { allFields } from "@usefillo/core";
@@ -211,6 +211,7 @@ function FileUploadField({ field, value, error, setValue, api }) {
211
211
  const [dragOver, setDragOver] = useState3(false);
212
212
  const mountedRef = useRef3(true);
213
213
  const controllers = useRef3(/* @__PURE__ */ new Map());
214
+ const inFlightCount = useRef3(0);
214
215
  useEffect4(
215
216
  () => () => {
216
217
  mountedRef.current = false;
@@ -233,6 +234,7 @@ function FileUploadField({ field, value, error, setValue, api }) {
233
234
  return;
234
235
  }
235
236
  setInFlight((prev) => [...prev, { key, name: file.name, size: file.size, fraction: 0 }]);
237
+ inFlightCount.current += 1;
236
238
  api.setUploading(field.id, true);
237
239
  const controller = new AbortController();
238
240
  controllers.current.set(key, controller);
@@ -258,7 +260,8 @@ function FileUploadField({ field, value, error, setValue, api }) {
258
260
  }
259
261
  } finally {
260
262
  controllers.current.delete(key);
261
- if (mountedRef.current) api.setUploading(field.id, false);
263
+ inFlightCount.current -= 1;
264
+ if (mountedRef.current && inFlightCount.current === 0) api.setUploading(field.id, false);
262
265
  }
263
266
  }
264
267
  function cancelUpload(key) {
@@ -892,7 +895,11 @@ function themeStyle(theme) {
892
895
  return style;
893
896
  }
894
897
  function FilloForm(props) {
895
- const { form, client, formId } = props;
898
+ const { form, formId } = props;
899
+ const client = useMemo(
900
+ () => props.client ?? (formId ? createClient() : void 0),
901
+ [props.client, formId]
902
+ );
896
903
  const [fetched, setFetched] = useState5(null);
897
904
  const [fetchedTheme, setFetchedTheme] = useState5(null);
898
905
  const [loadError, setLoadError] = useState5(null);
@@ -949,7 +956,7 @@ function FilloForm(props) {
949
956
  }
950
957
  );
951
958
  }
952
- return /* @__PURE__ */ jsx4(ResolvedForm, { ...props, schema, theme, formId: syncedFormId ?? formId });
959
+ return /* @__PURE__ */ jsx4(ResolvedForm, { ...props, client, schema, theme, formId: syncedFormId ?? formId });
953
960
  }
954
961
  function ResolvedForm(props) {
955
962
  const { schema, theme } = props;
@@ -1074,7 +1081,7 @@ function FilloProvider({ children, form, formId, client, ...options }) {
1074
1081
 
1075
1082
  // src/index.ts
1076
1083
  import {
1077
- createClient,
1084
+ createClient as createClient2,
1078
1085
  FilloClient,
1079
1086
  FilloError as FilloError3
1080
1087
  } from "@usefillo/core";
@@ -1086,7 +1093,7 @@ export {
1086
1093
  FilloForm,
1087
1094
  FilloProvider,
1088
1095
  FormField,
1089
- createClient,
1096
+ createClient2 as createClient,
1090
1097
  defineForm,
1091
1098
  useField,
1092
1099
  useFillo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefillo/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Headless React components for embedding Fillo forms natively in your product.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@usefillo/core": "^0.2.0"
39
+ "@usefillo/core": "^0.2.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": "^18.0.0 || ^19.0.0",