@stsdti/funky-ui-kit 1.8.6 → 1.8.7

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.
@@ -67202,6 +67202,29 @@ var BaseRepository = class BaseRepository {
67202
67202
  insert = (data) => {
67203
67203
  return this.submit("post", this.fullURL, data);
67204
67204
  };
67205
+ buildFormDataMultipart = (data, method = null) => {
67206
+ const formData = new FormData();
67207
+ if (!data) return formData;
67208
+ Object.entries(data).forEach(([key, value]) => {
67209
+ if (value instanceof File || value instanceof FileList) return;
67210
+ if (typeof value === "object") {
67211
+ formData.append(key, value ? JSON.stringify(value) : "");
67212
+ return;
67213
+ }
67214
+ formData.append(key, value ?? "");
67215
+ });
67216
+ if (method) formData.append("_method", method);
67217
+ this.appendFormDataMultipart(formData, data);
67218
+ return formData;
67219
+ };
67220
+ updateToFormDataMultipart = (id, data) => {
67221
+ const formData = this.buildFormDataMultipart(data, "PATCH");
67222
+ return this.submitMultipart("post", `${this.fullURL}/${id}`, formData);
67223
+ };
67224
+ insertToFormDataMultipart = (data) => {
67225
+ const formData = this.buildFormDataMultipart(data, "POST");
67226
+ return this.submitMultipart("post", this.fullURL, formData);
67227
+ };
67205
67228
  updateBulk = (data) => {
67206
67229
  return this.submit("patch", this.fullURL, data);
67207
67230
  };
@@ -67245,6 +67268,31 @@ var BaseRepository = class BaseRepository {
67245
67268
  });
67246
67269
  return requestPromise;
67247
67270
  }
67271
+ submitMultipart(method, url, data = null, params = null, throttleMs = 400, axiosConfig = null) {
67272
+ if (!(data instanceof FormData)) throw new Error("submitMultipart requires data to be an instance of FormData");
67273
+ return this.axios({
67274
+ method,
67275
+ url,
67276
+ data,
67277
+ params,
67278
+ crossDomain: true,
67279
+ ...axiosConfig ?? {},
67280
+ headers: {
67281
+ "Content-Type": "multipart/form-data",
67282
+ "X-Process-Multipart": "true",
67283
+ ...axiosConfig?.headers ?? {}
67284
+ }
67285
+ });
67286
+ }
67287
+ appendFormDataMultipart(formData, data, rootName = "") {
67288
+ if (data instanceof FileList) throw new Error("FileList is not supported in multipart payload. Please provide a File instead.");
67289
+ else if (data instanceof File) formData.append(rootName, data);
67290
+ else if (Array.isArray(data)) for (let i = 0; i < data.length; i++) this.appendFormDataMultipart(formData, data[i], `${rootName}/${i}`);
67291
+ else if (typeof data === "object" && data !== null && !(data instanceof Date)) {
67292
+ for (const key in data) if (Object.hasOwn(data, key)) if (rootName === "") this.appendFormDataMultipart(formData, data[key], key);
67293
+ else this.appendFormDataMultipart(formData, data[key], `${rootName}/${key}`);
67294
+ }
67295
+ }
67248
67296
  objectToQueryString(queryParameters) {
67249
67297
  return Object.keys(queryParameters).map((key) => key + "=" + queryParameters[key]).join("&");
67250
67298
  }
@@ -125795,7 +125843,7 @@ var useFormEvent = {
125795
125843
  fetched: "fetched"
125796
125844
  };
125797
125845
  function useForm(config, emits) {
125798
- const { onEvent, model = null, shouldFetchOnMount: defaultShouldFetchOnMount = true, shouldEmitOnMount = true, useInModal = false } = config;
125846
+ const { onEvent, model = null, shouldFetchOnMount: defaultShouldFetchOnMount = true, shouldEmitOnMount = true, useInModal = false, useMultipart = false } = config;
125799
125847
  const { fetchItem: fetchItem_, saveItem: saveItem_, deleteItem: deleteItem_ } = config;
125800
125848
  const { validationPath: globalValidationPath } = config;
125801
125849
  const repository = model?.getRepository();
@@ -125867,8 +125915,8 @@ function useForm(config, emits) {
125867
125915
  let newItem = (0, import_lodash.cloneDeep)(item.value);
125868
125916
  newItem = await transformer?.transformToApi?.(newItem);
125869
125917
  let response = null;
125870
- if (item.value?.id) response = await repository.update(item.value?.id, newItem);
125871
- else response = await repository.insert(newItem);
125918
+ if (item.value?.id) response = useMultipart ? await repository.updateToFormDataMultipart(item.value?.id, newItem) : await repository.update(item.value?.id, newItem);
125919
+ else response = useMultipart ? await repository.insertToFormDataMultipart(newItem) : await repository.insert(newItem);
125872
125920
  isLoading.value = false;
125873
125921
  if (!ResponseUtils.isSuccess(response)) return response;
125874
125922
  useDraft && formDraft.clearItemFromStorage();