UNPKG

swagger-editor

Version:

- [Anonymized analytics](#anonymized-analytics) - [Getting started](#getting-started) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Usage](#usage) - [Development](#development) - [Prerequisites](#prerequisites) - [Setting

119 lines (118 loc) 3.01 kB
import { n as e } from "../../fn-BbK27qJY.js"; import { useCallback as t, useState as n } from "react"; import r from "prop-types"; import { jsx as i, jsxs as a } from "react/jsx-runtime"; import { useDropzone as o } from "react-dropzone"; //#region src/plugins/dropzone/components/Dropzone.jsx var s = ({ getComponent: e, useDropzone: t, children: n }) => { let r = e("AlertDialog", !0), [o, s, c, l, u, d] = t(), f = () => { c(!1); }; return /* @__PURE__ */ a("div", { className: "dropzone", ...u(), children: [ /* @__PURE__ */ i(r, { isOpen: s, title: "Uh oh, an error has occurred", onClose: f, children: l }), /* @__PURE__ */ i("input", { "data-cy": "dropzone", ...d() }), o && /* @__PURE__ */ i("div", { className: "dropzone__overlay", children: "Please drop an OpenAPI 2.0/3.0/3.1 or AsyncApi 2.x definition in .yaml or .json format." }), n ] }); }; s.propTypes = { getComponent: r.func.isRequired, useDropzone: r.func.isRequired, children: r.node.isRequired }; //#endregion //#region src/plugins/dropzone/hooks.js var c = (e) => () => { let { editorDropzoneActions: r } = e(), [i, a] = n(!1), [s, c] = n(""), { getRootProps: l, getInputProps: u, isDragActive: d } = o({ onDrop: t(async (e, t) => { let n = t && t.length > 0, i = e && e.length === 1; n || !i ? (c("Sorry, there was an error processing your file.\nPlease drag and drop exactly one file."), a(!0)) : (await r.dropFile({ file: e[0] })).error && (c("Sorry, there was an error processing your file. Unable to process as valid YAML or JSON "), a(!0)); }, [ c, a, r ]), multiple: !1, noClick: !0 }); return [ d, i, a, s, l, u ]; }, l = "editor_dropzone_drop_file_started", u = "editor_dropzone_drop_file_success", d = "editor_dropzone_drop_file_failure", f = ({ file: e, requestId: t }) => ({ type: l, payload: e, meta: { requestId: t } }), p = ({ content: e, file: t, requestId: n }) => ({ type: u, payload: e, meta: { file: t, requestId: n } }), m = ({ error: e, file: t, requestId: n }) => ({ type: d, payload: e, error: !0, meta: { file: t, requestId: n } }), h = ({ file: e }) => async (t) => { let { editorDropzoneActions: n, fn: r } = t, i = r.generateRequestId(); n.dropFileStarted({ file: e, requestId: i }); try { let t = await e.text(); return n.dropFileSuccess({ content: t, file: e, requestId: i }); } catch (t) { return n.dropFileFailure({ error: t, file: e, requestId: i }); } }, g = e((e, t) => ({ content: e }) => { let { editorActions: n, EditorContentOrigin: r } = t; n.setContent(e, r.FileDrop); }), _ = ({ getSystem: e }) => ({ rootInjects: { useDropzone: c(e) }, components: { Dropzone: s }, statePlugins: { editorDropzone: { actions: { dropFile: h, dropFileStarted: f, dropFileSuccess: p, dropFileFailure: m }, wrapActions: { dropFileSuccess: g } } } }); //#endregion export { _ as default }; //# sourceMappingURL=index.js.map