@scalar/api-client
Version:
the open source API testing client
75 lines (74 loc) • 2.02 kB
JavaScript
import { defineComponent as f, ref as R, watch as w, createBlock as i, openBlock as s } from "vue";
import v from "./RequestTable.vue.js";
import { getFormBodyRows as y } from "../helpers/get-form-body-rows.js";
import { useFileDialog as F } from "../../../../hooks/useFileDialog.js";
const D = /* @__PURE__ */ f({
__name: "RequestBodyForm",
props: {
example: {},
selectedContentType: {},
environment: {}
},
emits: ["update:formValue"],
setup(a, { emit: d }) {
const u = d, e = R([]);
w(
() => a.example,
(t) => {
e.value = y(t, a.selectedContentType);
},
{ immediate: !0 }
);
const m = (t, o) => {
if (t >= e.value.length) {
e.value = [
...e.value,
{ name: "", value: "", ...o, isDisabled: !1 }
], u("update:formValue", e.value);
return;
}
e.value = e.value.map(
(n, l) => l === t ? { ...n, ...o } : n
), u("update:formValue", e.value);
}, r = (t) => {
e.value = e.value.filter(
(o, n) => n !== t
), u("update:formValue", e.value);
}, p = (t) => {
const { open: o } = F({
onChange: (n) => {
const l = n?.[0];
if (l) {
const c = e.value[t];
m(t, {
name: c?.name || l.name,
value: l
});
}
},
multiple: !1,
accept: "*/*"
});
o();
};
return (t, o) => a.selectedContentType === "multipart/form-data" ? (s(), i(v, {
key: 0,
data: e.value,
environment: a.environment,
showUploadButton: "",
onDeleteRow: r,
onRemoveFile: o[0] || (o[0] = (n) => m(n, { value: void 0 })),
onUploadFile: p,
onUpsertRow: m
}, null, 8, ["data", "environment"])) : (s(), i(v, {
key: 1,
data: e.value,
environment: a.environment,
onDeleteRow: r,
onUpsertRow: m
}, null, 8, ["data", "environment"]));
}
});
export {
D as default
};