formanitor 0.1.4 → 0.1.5

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/index.cjs CHANGED
@@ -1745,8 +1745,6 @@ var FormStore = class {
1745
1745
  updateConfig(next) {
1746
1746
  let needsReeval = false;
1747
1747
  if (next.onUpload !== void 0) this.config.onUpload = next.onUpload;
1748
- if (next.onFileUpload !== void 0)
1749
- this.config.onFileUpload = next.onFileUpload;
1750
1748
  if (next.onEvent !== void 0) this.config.onEvent = next.onEvent;
1751
1749
  if (next.onDraftChange !== void 0) this.config.onDraftChange = next.onDraftChange;
1752
1750
  if (next.voice !== void 0) this.config.voice = next.voice;
@@ -1767,10 +1765,6 @@ var FormStore = class {
1767
1765
  getUploadHandler() {
1768
1766
  return this.config.onUpload;
1769
1767
  }
1770
- /** Resolved handler for `file_upload` widgets: `onFileUpload` ?? `onUpload`. */
1771
- getFileUploadHandler() {
1772
- return this.config.onFileUpload ?? this.config.onUpload;
1773
- }
1774
1768
  preSubmitHandlers = /* @__PURE__ */ new Map();
1775
1769
  registerPreSubmitHandler(fieldId, fn) {
1776
1770
  this.preSubmitHandlers.set(fieldId, fn);
@@ -4079,7 +4073,7 @@ var FormFileUploadWidget = ({
4079
4073
  const accept = def.accept ?? "*/*";
4080
4074
  const maxSize = def.maxSize ?? 10 * 1024 * 1024;
4081
4075
  const allowMultiple = def.multiple === true;
4082
- const uploadHandler = store.getFileUploadHandler();
4076
+ const uploadHandler = store.getUploadHandler();
4083
4077
  const showLabel = isLabelVisible(fieldDef);
4084
4078
  if (!uploadHandler) {
4085
4079
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: fieldWrapperClass(fieldDef, "space-y-2"), children: [
@@ -4088,7 +4082,7 @@ var FormFileUploadWidget = ({
4088
4082
  " ",
4089
4083
  /* @__PURE__ */ jsxRuntime.jsx(FieldRequiredIndicator, { fieldDef })
4090
4084
  ] }) : null,
4091
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-2 border-red-300 rounded-lg p-4 bg-red-50", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-red-600", children: "Upload handler not configured. Provide `config.onFileUpload` or `config.onUpload` on FormProvider." }) })
4085
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-2 border-red-300 rounded-lg p-4 bg-red-50", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-red-600", children: "Upload handler not configured. Please provide an onUpload function in FormProvider config." }) })
4092
4086
  ] });
4093
4087
  }
4094
4088
  const hasStoredValue = value !== null && value !== void 0 && value !== "" && !(Array.isArray(value) && value.length === 0);
@@ -16328,52 +16322,33 @@ var FormControls = ({
16328
16322
  };
16329
16323
 
16330
16324
  // src/utils/createUploadHandler.ts
16331
- function normalizeBaseUrl(apiBaseUrl) {
16332
- return apiBaseUrl.replace(/\/+$/, "");
16333
- }
16334
- async function uploadViaPresignedEndpoint(options, presignPath, file, filename) {
16335
- const { apiBaseUrl, headers = {} } = options;
16336
- const base = normalizeBaseUrl(apiBaseUrl);
16337
- const path = presignPath.startsWith("/") ? presignPath : `/${presignPath}`;
16338
- const response = await fetch(`${base}${path}`, {
16339
- method: "POST",
16340
- headers: {
16341
- "Content-Type": "application/json",
16342
- ...headers
16343
- },
16344
- body: JSON.stringify({ filename })
16345
- });
16346
- if (!response.ok) {
16347
- throw new Error(`Failed to get presigned URL: ${response.statusText}`);
16348
- }
16349
- const presignedData = await response.json();
16350
- const uploadResponse = await fetch(presignedData.presigned_url, {
16351
- method: presignedData.upload_method,
16352
- headers: {
16353
- "Content-Type": presignedData.content_type
16354
- },
16355
- body: file
16356
- });
16357
- if (!uploadResponse.ok) {
16358
- throw new Error(`Failed to upload file: ${uploadResponse.statusText}`);
16359
- }
16360
- return presignedData.s3_key;
16361
- }
16362
16325
  function createUploadHandler(options) {
16363
- return async (file, filename) => uploadViaPresignedEndpoint(
16364
- options,
16365
- "/api/forms/media-upload/",
16366
- file,
16367
- filename
16368
- );
16369
- }
16370
- function createFileUploadHandler(options) {
16371
- return async (file, filename) => uploadViaPresignedEndpoint(
16372
- options,
16373
- "/api/forms/media-presigned-get/",
16374
- file,
16375
- filename
16376
- );
16326
+ const { apiBaseUrl, headers = {} } = options;
16327
+ return async (file, filename) => {
16328
+ const response = await fetch(`${apiBaseUrl}/api/forms/media-upload/`, {
16329
+ method: "POST",
16330
+ headers: {
16331
+ "Content-Type": "application/json",
16332
+ ...headers
16333
+ },
16334
+ body: JSON.stringify({ filename })
16335
+ });
16336
+ if (!response.ok) {
16337
+ throw new Error(`Failed to get presigned URL: ${response.statusText}`);
16338
+ }
16339
+ const presignedData = await response.json();
16340
+ const uploadResponse = await fetch(presignedData.presigned_url, {
16341
+ method: presignedData.upload_method,
16342
+ headers: {
16343
+ "Content-Type": presignedData.content_type
16344
+ },
16345
+ body: file
16346
+ });
16347
+ if (!uploadResponse.ok) {
16348
+ throw new Error(`Failed to upload file: ${uploadResponse.statusText}`);
16349
+ }
16350
+ return presignedData.s3_key;
16351
+ };
16377
16352
  }
16378
16353
 
16379
16354
  exports.AddInvestigationField = AddInvestigationField;
@@ -16402,7 +16377,6 @@ exports.SignatureUploadWidget = SignatureUploadWidget;
16402
16377
  exports.SmartForm = SmartForm;
16403
16378
  exports.SmartTextareaWidget = SmartTextareaWidget;
16404
16379
  exports.Upload = Upload3;
16405
- exports.createFileUploadHandler = createFileUploadHandler;
16406
16380
  exports.createUploadHandler = createUploadHandler;
16407
16381
  exports.evaluateRules = evaluateRules;
16408
16382
  exports.fieldControlClass = fieldControlClass;