swagger-editor
Version:
- [Anonymized analytics](#anonymized-analytics) - [Getting started](#getting-started) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Usage](#usage) - [Development](#development) - [Prerequisites](#prerequisites) - [Setting
152 lines (151 loc) • 5.25 kB
JavaScript
import { n as e } from "../../fn-CSHJFKWj.js";
import { t } from "../../import-url-DG6FhiUC.js";
import { useEffect as n } from "react";
import r from "prop-types";
import { jsx as i, jsxs as a } from "react/jsx-runtime";
import { List as o } from "immutable";
import s from "react-immutable-proptypes";
import { compile as c } from "@swagger-api/apidom-json-pointer/modern";
//#region src/plugins/editor-preview-swagger-ui/components/EditorPreviewSwaggerUI/EditorPreviewSwaggerUI.jsx
var l = ({ getComponent: e, editorPreviewSwaggerUIActions: t }) => {
let r = e("BaseLayout", !0);
return n(() => () => {
t.previewUnmounted();
}, [t]), /* @__PURE__ */ i("div", {
className: "swagger-editor__editor-preview-swagger-ui",
children: /* @__PURE__ */ i(r, {})
});
};
l.propTypes = {
getComponent: r.func.isRequired,
editorPreviewSwaggerUIActions: r.shape({ previewUnmounted: r.func.isRequired }).isRequired
};
//#endregion
//#region src/plugins/editor-preview-swagger-ui/assets/jump-icon.svg
var u = "data:image/svg+xml,%3csvg%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20x='0px'%20y='0px'%20viewBox='0%200%2024%2024'%20enable-background='new%200%200%2024%2024'%20xml:space='preserve'%3e%3cpath%20d='M19%207v4H5.83l3.58-3.59L8%206l-6%206%206%206%201.41-1.41L5.83%2013H21V7z'/%3e%3c/svg%3e", d = ({ path: e = o(), content: t = null, showButton: n = !1, editorPreviewSwaggerUIActions: r }) => {
let s = (t) => {
t.stopPropagation(), r.jumpToPath(e.toJS());
}, c = /* @__PURE__ */ i("span", {
role: "button",
tabIndex: 0,
onClick: s,
onKeyDown: s,
children: /* @__PURE__ */ i("img", {
src: u,
className: "view-line-link",
title: "Jump to definition",
alt: "Jump to path"
})
});
return t ? /* @__PURE__ */ a("span", {
role: "button",
tabIndex: 0,
onClick: s,
onKeyDown: s,
children: [n && c, t]
}) : c;
};
d.propTypes = {
path: s.listOf(r.string),
content: r.element,
showButton: r.bool,
editorPreviewSwaggerUIActions: r.shape({ jumpToPath: r.func.isRequired }).isRequired
};
//#endregion
//#region src/plugins/editor-preview-swagger-ui/extensions/editor-preview/wrap-components/EditorPreviewWrapper.jsx
var f = (e, t) => {
let n = ({ getComponent: n, editorSelectors: r }) => {
let a = n("EditorPreviewSwaggerUI", !0);
return r.selectIsContentTypeOpenAPI() ? /* @__PURE__ */ i(a, {}) : /* @__PURE__ */ i(e, { ...t });
};
return n.propTypes = {
getComponent: r.func.isRequired,
editorSelectors: r.shape({
selectIsContentTypeOpenAPI: r.func.isRequired,
selectIsContentTypeOpenAPI31x: r.func.isRequired,
selectIsContentTypeOpenAPI32x: r.func.isRequired
}).isRequired
}, n;
}, p = "editor_preview_swagger_ui_preview_unmounted", m = () => ({ type: p }), h = "editor_preview_swagger_ui_jump_to_path_started", g = "editor_preview_swagger_ui_jump_to_path_success", _ = "editor_preview_swagger_ui_jump_to_path_failure", v = ({ path: e, requestId: t }) => ({
type: h,
payload: e,
meta: { requestId: t }
}), y = ({ position: e, path: t, jsonPointer: n, requestId: r }) => ({
type: g,
payload: e,
meta: {
jsonPointer: n,
path: t,
requestId: r
}
}), b = ({ error: e, path: t, jsonPointer: n, requestId: r }) => ({
type: _,
error: !0,
payload: e,
meta: {
jsonPointer: n,
path: t,
requestId: r
}
}), x = (e) => async (t) => {
let { editorActions: n, editorPreviewSwaggerUIActions: r, fn: i } = t, a = i.generateRequestId(), o = "";
r.jumpToPathStarted({
path: e,
requestId: a
});
try {
o = c(e);
let t = await n.getJsonPointerPosition(o);
if (t.error) throw t;
let { payload: i } = t, s = await n.setPosition(i);
if (s.error) throw s;
return r.jumpToPathSuccess({
path: e,
jsonPointer: o,
position: i,
requestId: a
});
} catch (t) {
return r.jumpToPathFailure({
error: t,
path: e,
jsonPointer: o,
requestId: a
});
}
}, S = e((e, t) => () => {
t.specActions.updateUrl(""), t.specActions.updateSpec("", t.EditorContentOrigin.Editor);
}), C = e((e, t) => ({ path: e }) => {
let { authActions: n } = t;
(e[0] === "securityDefinitions" || e[0] === "components" && e[1] === "securitySchemes") && n.showDefinitions(!1);
}), w = e((e, t) => ({ content: e }) => {
let { specActions: n, editorSelectors: r, editorPreviewSwaggerUISelectors: i, EditorContentOrigin: a } = t, o = r.selectContentOrigin();
o === a.Editor && !e.trim() && n.updateUrl(""), r.selectIsContentTypeOpenAPI() && (o === a.ImportUrl ? n.updateUrl(i.selectURL()) : o !== a.Editor && n.updateUrl(""), n.updateSpec(e, a.Editor));
}), T = { [t]: (e, t) => e.set("url", t.meta.url) }, E = (e) => e.get("url") || "", D = () => ({
components: {
EditorPreviewSwaggerUI: l,
JumpToPath: d
},
wrapComponents: { EditorPreview: f },
statePlugins: {
editor: { wrapActions: { detectContentTypeSuccess: w } },
editorPreviewSwaggerUI: {
actions: {
previewUnmounted: m,
jumpToPath: x,
jumpToPathStarted: v,
jumpToPathSuccess: y,
jumpToPathFailure: b
},
wrapActions: {
previewUnmounted: S,
jumpToPathSuccess: C
},
selectors: { selectURL: E },
reducers: T
}
}
});
//#endregion
export { D as default };
//# sourceMappingURL=index.js.map