swagger-editor
Version:
- [Anonymized analytics](#anonymized-analytics) - [Getting started](#getting-started) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Usage](#usage) - [Development](#development) - [Prerequisites](#prerequisites) - [Setting
675 lines (674 loc) • 22.7 kB
JavaScript
import { n as e } from "../../fn-BbK27qJY.js";
import { useEffect as t } from "react";
import n from "prop-types";
import { jsx as r, jsxs as i } from "react/jsx-runtime";
import { parse as a } from "@swagger-api/apidom-parser-adapter-api-design-systems-json";
import { parse as o } from "@swagger-api/apidom-parser-adapter-api-design-systems-yaml";
import { createSelector as s } from "reselect";
import { createNamespace as c, from as l, isArrayElement as u, isStringElement as d, toString as ee, toValue as f } from "@swagger-api/apidom-core";
import te, { RequirementElement as p, ScenarioElement as m, isInfoElement as h, isMainElement as ne, isPrincipleElement as g, isRequirementLevelElement as re, isScenarioElement as _, isStandardElement as ie, isStandardIdentifierElement as ae } from "@swagger-api/apidom-ns-api-design-systems";
//#region src/plugins/editor-preview-api-design-systems/actions.js
var v = "editor_preview_api_design_systems_preview_unmounted", y = "editor_preview_api_design_systems_parse_started", b = "editor_preview_api_design_systems_parse_success", x = "editor_preview_api_design_systems_parse_failure", S = () => ({ type: v }), oe = ({ content: e, contentType: t, requestId: n }) => ({
type: y,
payload: e,
meta: {
contentType: t,
requestId: n
}
}), se = ({ parseResult: e, content: t, contentType: n, requestId: r }) => ({
type: b,
payload: e,
meta: {
content: t,
contentType: n,
requestId: r
}
}), ce = ({ error: e, content: t, contentType: n, requestId: r }) => ({
type: x,
payload: e,
error: !0,
meta: {
content: t,
contentType: n,
requestId: r
}
}), le = ({ content: e, contentType: t, parserOptions: n = {} }) => async (r) => {
let { editorPreviewADSActions: i, fn: s } = r, c = s.generateRequestId();
i.parseStarted({
content: e,
contentType: t,
requestId: c
});
let l = t.includes("+json") ? a : o;
try {
let r = await l(e, n);
i.parseSuccess({
parseResult: r,
content: e,
contentType: t,
requestId: c
});
} catch (n) {
i.parseFailure({
error: n,
content: e,
contentType: t,
requestId: c
});
}
}, ue = e((e, t) => ({ content: e }) => {
let { editorSelectors: n, editorPreviewADSActions: r } = t;
if (n.selectIsContentTypeAPIDesignSystems()) {
let t = n.selectContentType();
r.parse({
content: e,
contentType: t,
parserOptions: {}
});
}
}), C = c(te), de = "idle", fe = "parsing", w = "success", T = "failure", E = {
parseStatus: de,
parseRequestId: null,
parseResult: null,
parseError: null
}, D = (e) => {
let { parseStatus: t, parseRequestId: n, parseResult: r, parseErrors: i } = E;
return e.merge({
parseStatus: t,
parseRequestId: n,
parseResult: r,
parseErrors: i
});
}, O = (e, t) => e.merge({
parseStatus: fe,
parseRequestId: t.meta.requestId
}), k = (e, t) => {
let n = e.get("parseStatus") || "idle", r = e.get("parseRequestId");
return n === "parsing" && r === t.meta.requestId ? e.merge({
parseStatus: w,
parseRequestId: null,
parseResult: ee(t.payload, C),
parseErrors: null
}) : e;
}, A = (e, t) => {
let n = e.get("parseStatus") || "idle", r = e.get("parseRequestId");
return n === "parsing" && r === t.meta.requestId ? e.merge({
parseStatus: T,
parseRequestId: null,
parseResult: null,
parseErrors: t.payload
}) : e;
}, j = {
[v]: D,
[y]: O,
[b]: k,
[x]: A
}, M = (e) => e, N = s(M, (e) => {
let t = e.get("parseResult", E.parseResult);
return typeof t == "string" ? l(t, C) : null;
}), P = s(M, (e) => e.get("parseError", E.parseResult)), F = (e) => e.get("parseStatus") || E.parseStatus, I = s(F, N, P, (e, t, n) => e === "parsing" && t === null && n === null), L = s(F, (e) => e === w), R = s(F, (e) => e === T), z = s(N, (e) => {
if (e === null) return null;
let { result: t } = e;
return ne(t) ? t : null;
}), B = s(z, (e) => {
if (e === null) return null;
let { version: t } = e;
return d(t) ? f(t) : "2021-05-07";
}), V = s(z, (e) => {
if (e === null) return null;
let { info: t } = e;
return h(t) ? f(t) : null;
}), pe = s(z, (e) => {
if (e === null) return null;
let { principles: t } = e;
return u(t) ? t.length : 0;
}), me = s(z, (e) => {
if (e === null) return null;
let { standards: t } = e;
return u(t) ? t.length : 0;
}), he = s(z, (e) => {
if (e === null) return null;
let { scenarios: t } = e;
return u(t) ? t.length : 0;
}), H = s(z, (e) => {
if (e === null) return [];
let { principles: t } = e;
return u(t) ? t.filter(g).toValue() : [];
}), ge = s(z, (e) => {
if (e === null) return [];
let { standards: t } = e;
return u(t) ? t.filter(ie).toValue() : [];
}), _e = s(z, (e) => {
if (e === null) return [];
let { scenarios: t } = e;
return u(t) ? t.filter(_).elements : [];
}), ve = (e, { standardIdentifier: t }) => ae(t) ? `[${String(f(t)).replaceAll(",", " > ")}]` : "[]", ye = (e, { scenarioElement: t }) => !_(t) || !d(t.description) ? "" : f(t.description), be = (e, { scenarioElement: t }) => !_(t) || !u(t.then) ? [] : t.then.content, xe = (e, { requirementElement: t }) => re(t.level) ? f(t.level) : "unknown", Se = (e, { requirementElement: t }) => u(t.values) ? String(f(t.values)).replaceAll(",", ", ") : "unknown", U = ({ getComponent: e }) => {
let t = e("ADSInfo", !0), n = e("ADSPrinciples", !0), a = e("ADSStandards", !0), o = e("ADSScenarios", !0);
return /* @__PURE__ */ r("section", {
className: "swagger-ui swagger-container",
children: /* @__PURE__ */ r("div", {
className: "swagger-ui",
children: /* @__PURE__ */ r("div", {
className: "information-container wrapper",
children: /* @__PURE__ */ i("section", {
className: "block col-12",
children: [
/* @__PURE__ */ r(t, {}),
/* @__PURE__ */ r(n, {}),
/* @__PURE__ */ r(a, {}),
/* @__PURE__ */ r(o, {}),
/* @__PURE__ */ r("br", {})
]
})
})
})
});
};
U.propTypes = { getComponent: n.func.isRequired };
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Info.jsx
var W = ({ editorPreviewADSSelectors: e }) => {
let t = e.selectVersion(), n = e.selectInfo(), a = e.selectPrinciplesCount(), o = e.selectStandardsCount(), s = e.selectScenariosCount();
return n === null ? null : /* @__PURE__ */ i("div", {
className: "info",
children: [
/* @__PURE__ */ r("hgroup", {
className: "main",
children: /* @__PURE__ */ i("h2", {
className: "title",
children: [n.title, /* @__PURE__ */ i("span", { children: [/* @__PURE__ */ r("small", { children: /* @__PURE__ */ r("pre", {
className: "version",
children: t
}) }), /* @__PURE__ */ r("small", {
className: "version-stamp",
children: /* @__PURE__ */ r("pre", {
className: "version",
children: "ADS"
})
})] })]
})
}),
/* @__PURE__ */ r("hgroup", {
className: "main title",
children: /* @__PURE__ */ i("span", { children: [
/* @__PURE__ */ r("small", {
className: "summary-pill",
children: /* @__PURE__ */ i("pre", {
className: "version",
children: [
" ",
a,
" Principles"
]
})
}),
/* @__PURE__ */ r("small", {
className: "summary-pill",
children: /* @__PURE__ */ i("pre", {
className: "version",
children: [
" ",
o,
" Standards"
]
})
}),
/* @__PURE__ */ r("small", {
className: "summary-pill",
children: /* @__PURE__ */ i("pre", {
className: "version",
children: [
" ",
s,
" Scenarios"
]
})
})
] })
}),
/* @__PURE__ */ r("div", {
className: "description",
children: /* @__PURE__ */ r("div", {
className: "renderedMarkdown",
children: /* @__PURE__ */ r("p", { children: n.description })
})
})
]
});
};
W.propTypes = { editorPreviewADSSelectors: n.shape({
selectVersion: n.func.isRequired,
selectInfo: n.func.isRequired,
selectPrinciplesCount: n.func.isRequired,
selectStandardsCount: n.func.isRequired,
selectScenariosCount: n.func.isRequired
}).isRequired };
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Principles.jsx
var G = ({ editorPreviewADSSelectors: e, getComponent: t }) => {
let n = e.selectPrinciplesCount(), a = e.selectPrinciples(), o = t("ADSPrinciple");
return /* @__PURE__ */ r("div", {
className: "no-margin",
children: /* @__PURE__ */ i("div", {
className: "opblock opblock-post is-open",
children: [/* @__PURE__ */ r("div", {
className: "opblock-summary opblock-summary-post",
children: /* @__PURE__ */ i("span", {
className: "opblock-summary-method",
style: {
paddingLeft: "6px",
paddingRight: "6px"
},
children: [n, " Principles"]
})
}), /* @__PURE__ */ r("div", {
className: "no-margin",
children: /* @__PURE__ */ i("div", {
className: "opblock-body",
children: [/* @__PURE__ */ r("div", {
className: "opblock-description-wrapper",
children: /* @__PURE__ */ r("div", {
className: "opblock-description",
children: /* @__PURE__ */ r("div", {
className: "markdown",
children: /* @__PURE__ */ r("p", { children: "Principles guide how decisions in API design and delivery should be made." })
})
})
}), /* @__PURE__ */ r("div", {
className: "opblock-section",
children: /* @__PURE__ */ r("div", {
className: "parameters-container",
children: /* @__PURE__ */ r("div", {
className: "table-container",
children: /* @__PURE__ */ i("table", {
className: "model ads-principles",
children: [/* @__PURE__ */ r("thead", { children: /* @__PURE__ */ i("tr", { children: [
/* @__PURE__ */ r("th", {
className: "col_header",
style: { width: "50%" },
children: "Internationalized Resource Identifiers"
}),
/* @__PURE__ */ r("th", {
className: "col_header",
style: { width: "20%" },
children: "level"
}),
/* @__PURE__ */ r("th", {
className: "col_header",
children: "Name"
})
] }) }), /* @__PURE__ */ r("tbody", { children: a.map((e) => /* @__PURE__ */ r(o, {
name: e.name,
iri: e.iri,
level: e.level
}, e.iri)) })]
})
})
})
})]
})
})]
})
});
};
G.propTypes = {
getComponent: n.func.isRequired,
editorPreviewADSSelectors: n.shape({
selectPrinciplesCount: n.func.isRequired,
selectPrinciples: n.func.isRequired
}).isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Principle.jsx
var K = ({ name: e = "", iri: t, level: n }) => /* @__PURE__ */ i("tr", { children: [
/* @__PURE__ */ r("td", { children: /* @__PURE__ */ r("span", {
className: "property-primitivetype",
children: t
}) }),
/* @__PURE__ */ r("td", { children: /* @__PURE__ */ r("span", {
className: "prop-type",
children: n
}) }),
/* @__PURE__ */ r("td", { children: e })
] });
K.propTypes = {
name: n.string,
iri: n.string.isRequired,
level: n.string.isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Standards.jsx
var q = ({ editorPreviewADSSelectors: e, getComponent: t }) => {
let n = e.selectStandardsCount(), a = e.selectStandards(), o = t("ADSStandard");
return /* @__PURE__ */ r("div", {
className: "no-margin",
children: /* @__PURE__ */ i("div", {
className: "opblock opblock-get is-open",
children: [/* @__PURE__ */ r("div", {
className: "opblock-summary opblock-summary-get",
children: /* @__PURE__ */ i("span", {
className: "opblock-summary-method",
style: {
paddingLeft: "6px",
paddingRight: "6px"
},
children: [n, " Standards"]
})
}), /* @__PURE__ */ r("div", {
className: "no-margin",
children: /* @__PURE__ */ i("div", {
className: "opblock-body",
children: [/* @__PURE__ */ r("div", {
className: "opblock-description-wrapper",
children: /* @__PURE__ */ r("div", {
className: "opblock-description",
children: /* @__PURE__ */ r("div", {
className: "markdown",
children: /* @__PURE__ */ r("p", { children: "Standards are industry best practices (e.g. RFCs) that shall influence the rules for API design." })
})
})
}), /* @__PURE__ */ r("div", {
className: "opblock-section",
children: /* @__PURE__ */ r("div", {
className: "parameters-container",
children: /* @__PURE__ */ r("div", {
className: "table-container",
children: /* @__PURE__ */ i("table", {
className: "model ads-principles",
children: [/* @__PURE__ */ r("thead", { children: /* @__PURE__ */ i("tr", { children: [
/* @__PURE__ */ r("th", {
className: "col_header",
style: { width: "50%" },
children: "Internationalized Resource Identifiers"
}),
/* @__PURE__ */ r("th", {
className: "col_header",
style: { width: "20%" },
children: "level"
}),
/* @__PURE__ */ r("th", {
className: "col_header",
children: "Name"
})
] }) }), /* @__PURE__ */ r("tbody", { children: a.map((e) => /* @__PURE__ */ r(o, {
name: e.name,
iri: e.iri,
level: e.level
}, e.iri)) })]
})
})
})
})]
})
})]
})
});
};
q.propTypes = {
getComponent: n.func.isRequired,
editorPreviewADSSelectors: n.shape({
selectStandardsCount: n.func.isRequired,
selectStandards: n.func.isRequired
}).isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Standard.jsx
var J = ({ name: e = "", iri: t, level: n }) => /* @__PURE__ */ i("tr", { children: [
/* @__PURE__ */ r("td", { children: /* @__PURE__ */ r("span", {
className: "property-primitivetype",
children: t
}) }),
/* @__PURE__ */ r("td", { children: /* @__PURE__ */ r("span", {
className: "prop-type",
children: n
}) }),
/* @__PURE__ */ r("td", { children: e })
] });
J.propTypes = {
name: n.string,
iri: n.string.isRequired,
level: n.string.isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Scenarios.jsx
var Y = ({ getComponent: e, editorPreviewADSSelectors: t }) => {
let n = t.selectScenariosCount(), a = t.selectScenarios(), o = e("ADSScenario", !0);
return /* @__PURE__ */ r("section", {
className: "block col-12 block-desktop col-12-desktop",
children: /* @__PURE__ */ i("section", {
className: "models is-open",
children: [/* @__PURE__ */ r("h4", { children: /* @__PURE__ */ i("button", {
type: "button",
"aria-expanded": "true",
className: "models-control",
children: [/* @__PURE__ */ i("span", { children: [n, " Governance Scenarios"] }), /* @__PURE__ */ r("svg", {
width: "20",
height: "20",
"aria-hidden": "true",
focusable: "false"
})]
}) }), /* @__PURE__ */ r("div", {
className: "no-margin",
children: a.map((e) => {
let n = t.selectStandardIdentifier({ standardIdentifier: e.when });
return /* @__PURE__ */ r(o, { element: e }, n);
})
})]
})
});
};
Y.propTypes = {
editorPreviewADSSelectors: n.shape({
selectScenariosCount: n.func.isRequired,
selectScenarios: n.func.isRequired,
selectStandardIdentifier: n.func.isRequired
}).isRequired,
getComponent: n.func.isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Scenario.jsx
var X = ({ getComponent: e, editorPreviewADSSelectors: t, element: n }) => {
let a = t.selectStandardIdentifier({ standardIdentifier: n.when }), o = t.selectScenarioDescription({ scenarioElement: n }), s = t.selectScenarioRequirements({ scenarioElement: n }), c = e("ADSRequirement", !0);
return /* @__PURE__ */ r("div", {
className: "modal-container",
children: /* @__PURE__ */ r("span", {
className: "model-box",
style: { display: "block" },
children: /* @__PURE__ */ i("button", {
type: "button",
"aria-expanded": "false",
className: "model-box-control",
style: { width: "100%" },
children: [
/* @__PURE__ */ r("span", {
className: "pointer",
children: /* @__PURE__ */ r("span", {
className: "model-box",
children: /* @__PURE__ */ i("span", {
className: "model model-title",
children: [
/* @__PURE__ */ r("strong", { children: "Scenario: " }),
" ",
a
]
})
})
}),
/* @__PURE__ */ r("div", {
className: "description",
children: /* @__PURE__ */ r("div", {
className: "markdown",
children: /* @__PURE__ */ r("p", { children: o })
})
}),
/* @__PURE__ */ r("div", {
className: "table-container",
children: /* @__PURE__ */ i("table", {
className: "model",
children: [/* @__PURE__ */ r("thead", { children: /* @__PURE__ */ i("tr", { children: [
/* @__PURE__ */ r("th", {
className: "col_header",
style: { width: "50%" },
children: "Subject"
}),
/* @__PURE__ */ r("th", {
className: "col_header",
children: "Level"
}),
/* @__PURE__ */ r("th", {
className: "col_header",
style: { width: "40%" },
children: "Values"
})
] }) }), /* @__PURE__ */ r("tbody", { children: s.map((e, t) => /* @__PURE__ */ r(c, { element: e }, t)) })]
})
})
]
})
})
});
};
X.propTypes = {
element: n.instanceOf(m).isRequired,
getComponent: n.func.isRequired,
editorPreviewADSSelectors: n.shape({
selectStandardIdentifier: n.func.isRequired,
selectScenarioDescription: n.func.isRequired,
selectScenarioRequirements: n.func.isRequired
}).isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/Requirement.jsx
var Z = ({ editorPreviewADSSelectors: e, element: t }) => {
let n = e.selectStandardIdentifier({ standardIdentifier: t.subject }), a = e.selectRequirementLevel({ requirementElement: t }), o = e.selectRequirementValues({ requirementElement: t });
return /* @__PURE__ */ i("tr", {
className: "property-row",
children: [
/* @__PURE__ */ r("td", { children: n }),
/* @__PURE__ */ r("td", { children: /* @__PURE__ */ r("span", {
className: "prop-type",
children: a
}) }),
/* @__PURE__ */ r("td", { children: /* @__PURE__ */ r("span", {
className: "property-primitive",
children: o
}) })
]
});
};
Z.propTypes = {
element: n.instanceOf(p).isRequired,
editorPreviewADSSelectors: n.shape({
selectStandardIdentifier: n.func.isRequired,
selectRequirementLevel: n.func.isRequired,
selectRequirementValues: n.func.isRequired
}).isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/EditorPreviewAPIDesignSystems.jsx
var Ce = () => /* @__PURE__ */ r("div", { children: "Parsing..." }), Q = ({ getComponent: e, editorPreviewADSActions: n, editorPreviewADSSelectors: a }) => {
let o = e("ADSMain", !0), s = e("EditorPreviewAPIDesignSystemsParseErrors", !0), c = a.selectIsParseInProgress(), l = a.selectIsParseSuccess(), u = a.selectIsParseFailure(), d = a.selectParseError();
return t(() => () => {
n.previewUnmounted();
}, [n]), /* @__PURE__ */ i("section", {
className: "swagger-editor__editor-preview-api-design-systems",
children: [
c && /* @__PURE__ */ r(Ce, {}),
l && /* @__PURE__ */ r(o, {}),
u && /* @__PURE__ */ r(s, { error: d })
]
});
};
Q.propTypes = {
getComponent: n.func.isRequired,
editorPreviewADSActions: n.shape({ previewUnmounted: n.func.isRequired }).isRequired,
editorPreviewADSSelectors: n.shape({
selectIsParseInProgress: n.func.isRequired,
selectIsParseSuccess: n.func.isRequired,
selectIsParseFailure: n.func.isRequired,
selectParseResult: n.func.isRequired,
selectParseError: n.func.isRequired,
selectMainElement: n.func.isRequired
}).isRequired
};
//#endregion
//#region src/plugins/editor-preview-api-design-systems/components/ParseErrors.jsx
var $ = ({ error: e }) => /* @__PURE__ */ r("div", {
className: "swagger-editor__editor-preview-api-design-systems-parse-errors",
children: /* @__PURE__ */ r("div", {
className: "swagger-ui",
children: /* @__PURE__ */ r("div", {
className: "version-pragma",
children: /* @__PURE__ */ r("div", {
className: "version-pragma__message version-pragma__message--missing",
children: /* @__PURE__ */ i("div", { children: [/* @__PURE__ */ r("h3", { children: "Invalid API Design Systems definition." }), /* @__PURE__ */ i("p", { children: ["Please fix the error: ", e.message] })] })
})
})
})
});
$.propTypes = { error: n.shape({ message: n.string }).isRequired };
//#endregion
//#region src/plugins/editor-preview-api-design-systems/extensions/editor-preview/wrap-components/EditorPreviewWrapper.jsx
var we = (e, t) => {
let i = ({ editorSelectors: n, getComponent: i }) => {
let a = i("EditorPreviewAPIDesignSystems", !0);
return n.selectIsContentTypeAPIDesignSystems() ? /* @__PURE__ */ r(a, {}) : /* @__PURE__ */ r(e, { ...t });
};
return i.propTypes = {
editorSelectors: n.oneOfType([n.shape({ selectIsContentTypeAPIDesignSystems: n.func.isRequired })]).isRequired,
getComponent: n.func.isRequired
}, i;
}, Te = () => ({
components: {
ADSMain: U,
ADSInfo: W,
ADSPrinciples: G,
ADSPrinciple: K,
ADSStandards: q,
ADSStandard: J,
ADSScenarios: Y,
ADSScenario: X,
ADSRequirement: Z,
EditorPreviewAPIDesignSystems: Q,
EditorPreviewAPIDesignSystemsParseErrors: $
},
wrapComponents: { EditorPreviewPane: we },
statePlugins: {
editor: { wrapActions: { detectContentTypeSuccess: ue } },
editorPreviewADS: {
actions: {
previewUnmounted: S,
parse: le,
parseStarted: oe,
parseSuccess: se,
parseFailure: ce
},
selectors: {
selectParseStatus: F,
selectIsParseInProgress: I,
selectIsParseSuccess: L,
selectIsParseFailure: R,
selectParseResult: N,
selectParseError: P,
selectMainElement: z,
selectVersion: B,
selectInfo: V,
selectPrinciplesCount: pe,
selectStandardsCount: me,
selectScenariosCount: he,
selectPrinciples: H,
selectStandards: ge,
selectScenarios: _e,
selectStandardIdentifier: ve,
selectScenarioDescription: ye,
selectScenarioRequirements: be,
selectRequirementLevel: xe,
selectRequirementValues: Se
},
reducers: j
}
}
});
//#endregion
export { Te as default };
//# sourceMappingURL=index.js.map